python312Packages.tencentcloud-sdk-python: 3.0.1266 -> 3.0.1267
[NixPkgs.git] / maintainers / scripts / update-channel-branches.sh
blobeaa731adccce8c477ef03409c87c35ebfb3f35d4
1 #!/usr/bin/env bash
2 set -e
4 : ${NIXOS_CHANNELS:=https://nixos.org/channels/}
5 : ${CHANNELS_NAMESPACE:=refs/heads/channels/}
7 # List all channels which are currently in the repository which we would
8 # have to remove if they are not found again.
9 deadChannels=$(git for-each-ref --format="%(refname)" "$CHANNELS_NAMESPACE")
11 updateRef() {
12 local channelName=$1
13 local newRev=$2
15 # if the inputs are not valid, then we do not update any branch.
16 test -z "$newRev" -o -z "$channelName" && return;
18 # Update the local refs/heads/channels/* branches to be in-sync with the
19 # channel references.
20 local branch=$CHANNELS_NAMESPACE$channelName
21 oldRev=$(git rev-parse --short "$branch" 2>/dev/null || true)
22 if test "$oldRev" != "$newRev"; then
23 if git update-ref "$branch" "$newRev" 2>/dev/null; then
24 if test -z "$oldRev"; then
25 echo " * [new branch] $newRev -> ${branch#refs/heads/}"
26 else
27 echo " $oldRev..$newRev -> ${branch#refs/heads/}"
29 else
30 if test -z "$oldRev"; then
31 echo " * [missing rev] $newRev -> ${branch#refs/heads/}"
32 else
33 echo " [missing rev] $oldRev..$newRev -> ${branch#refs/heads/}"
38 # Filter out the current channel from the list of dead channels.
39 deadChannels=$(grep -v "$CHANNELS_NAMESPACE$channelName" <<EOF
40 $deadChannels
41 EOF
42 ) ||true
45 # Find the name of all channels which are listed in the directory.
46 echo "Fetching channels from $NIXOS_CHANNELS:"
47 for channelName in : $(curl -s "$NIXOS_CHANNELS" | sed -n '/folder/ { s,.*href=",,; s,/".*,,; p }'); do
48 test "$channelName" = : && continue;
50 # Do not follow redirections, such that we can extract the
51 # short-changeset from the name of the directory where we are
52 # redirected to.
53 sha1=$(curl -sI "$NIXOS_CHANNELS$channelName" | sed -n '/Location/ { s,.*\.\([a-f0-9]*\)[ \r]*$,\1,; p; }')
55 updateRef "remotes/$channelName" "$sha1"
56 done
58 echo "Fetching channels from nixos-version:"
59 if currentSystem=$(nixos-version 2>/dev/null); then
60 # If the system is entirely build from a custom nixpkgs version,
61 # then the version is not annotated in git version. This sed
62 # expression is basically matching that the expressions end with
63 # ".<sha1> (Name)" to extract the sha1.
64 sha1=$(echo "$currentSystem" | sed -n 's,^.*\.\([a-f0-9]*\) *(.*)$,\1,; T skip; p; :skip;')
66 updateRef current-system "$sha1"
69 echo "Fetching channels from $HOME/.nix-defexpr:"
70 for revFile in : $(find -L "$HOME/.nix-defexpr/" -maxdepth 4 -name svn-revision); do
71 test "$revFile" = : && continue;
73 # Deconstruct a path such as, into:
75 # /home/luke/.nix-defexpr/channels_root/nixos/nixpkgs/svn-revision
76 # channelName = root/nixos
78 # /home/luke/.nix-defexpr/channels/nixpkgs/svn-revision
79 # channelName = nixpkgs
81 user=${revFile#*.nix-defexpr/channels}
82 repo=${user#*/}
83 repo=${repo%%/*}
84 user=${user%%/*}
85 user=${user#_}
86 test -z "$user" && user=$USER
87 channelName="$user${user:+/}$repo"
89 sha1=$(sed -n 's,^.*\.\([a-f0-9]*\)$,\1,; T skip; p; :skip;' "$revFile")
91 updateRef "$channelName" "$sha1"
92 done
94 # Suggest to remove channel branches which are no longer found by this
95 # script. This is to handle the cases where a local/remote channel
96 # disappear. We should not attempt to remove manually any branches, as they
97 # might be user branches.
98 if test -n "$deadChannels"; then
100 echo "
101 Some old channel branches are still in your repository, if you
102 want to remove them, run the following command(s):
105 while read branch; do
106 echo " git update-ref -d $branch"
107 done <<EOF
108 $deadChannels
111 echo