chiark / gitweb /
git-branchmove: seems to work
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 7 Oct 2015 20:48:05 +0000 (21:48 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 7 Oct 2015 20:48:05 +0000 (21:48 +0100)
scripts/git-branchmove

index e68c474..6952727 100755 (executable)
@@ -35,6 +35,7 @@ case "$remote" in
                git config remote."$remote".url ||
                fail "no pushurl or url defined for remote $remote"
                )"
+       remotename="$remote"
 esac
 
 remote_spec="$(perl -e '
@@ -46,7 +47,7 @@ remote_spec="$(perl -e '
     } elsif (m#^([-+_.0-9a-zA-Z\@]+):(?!//|:)#) {
         print "$'\''|ssh $1\n";
     } elsif (m#^[/.]#) {
-        print "$&|sh -c $1\n";
+        print "$_|sh -c $1\n";
     } else {
         die "git-branchmove: unsupported remote url \`$_'\''\n";
     }
@@ -171,8 +172,30 @@ esac
                src_ref="${src_rm%=*}"
                src_obj="${src_rm##*=}"
                git update-ref -m "$updatemsg" -d "$src_ref" "$src_obj"
-               echo "move complete: $src_ref"
+               echo "moved: $src_ref"
        done
 '
 
-echo "moved ${#src_branches[@]} branches."
+#----- update the remote tracking branches -----
+
+if [ "x$remotename" != x ]; then
+       for src_rm in "${src_branches[@]}"; do
+               src_ref="${src_rm%=*}"
+               src_obj="${src_rm##*=}"
+
+               case "$src_ref" in
+               refs/heads/*) ;;
+               *) continue ;;
+               esac
+
+               branch="${src_ref#refs/heads/}"
+               track_ref="refs/remotes/$remotename/$branch"
+               case $op in
+               get)    git update-ref -d "$track_ref"  ;;
+               put)    git update-ref "$track_ref" "$src_obj" ;;
+               *)      fail "unknown $op ???"
+               esac
+       done
+fi
+
+echo "git-repomove: moved ${#src_branches[@]} branches."