X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=scripts%2Fgit-branchmove;h=6952727b7421614ecb8b9f1ffee9c167110b7e6e;hp=029992dd776d9cb9067b8bc9b526bb792907a69a;hb=fdf6c19932ae3de217a11b64365815561101e29f;hpb=f4c74ad52db38f9f467207d3c1ea952e9b9441c8 diff --git a/scripts/git-branchmove b/scripts/git-branchmove index 029992d..6952727 100755 --- a/scripts/git-branchmove +++ b/scripts/git-branchmove @@ -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"; } @@ -61,7 +62,7 @@ get) src_path="$remote_path" dst_rune="sh -c" dst_path=. - msg="git-branchmove: moved to $remote ($remoteurl)" ;; + updatemsg="git-branchmove: moved to $remote ($remoteurl)" push_fetch=fetch ;; put) @@ -69,7 +70,7 @@ put) dst_path="$remote_path" src_rune="sh -c" src_path=. - msg="git-branchmove; moved to `hostname -f` by `whoami`" ;; + updatemsg="git-branchmove; moved to `hostname -f` by `whoami`" push_fetch=push ;; esac @@ -116,6 +117,12 @@ H) ;; # already detached ;; esac + +if [ "${#src_branches[@]}" = 0 ]; then + echo >&2 "git-branchmove: nothing to do" + exit 1 +fi + dst_branches=( $(on_dst "$get_branches_rune") ) : "${dst_branches[@]}" @@ -157,16 +164,38 @@ esac #----- delete the refs on the source ----- ( - printf "%s\n" "$message" + printf "%s\n" "$updatemsg" for src_rm in "${src_branches[@]}"; do printf "%s\n" "$src_rm"; done ) | on_src ' - read message + read updatemsg while read src_rm; do src_ref="${src_rm%=*}" src_obj="${src_rm##*=}" - git update-ref -m "$message" -d "$src_ref" "$src_obj" - echo "move complete: $src_ref" + git update-ref -m "$updatemsg" -d "$src_ref" "$src_obj" + 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."