chiark / gitweb /
tg-push: prevent handing branches more than once to git-push
authorBert Wesarg <bert.wesarg@googlemail.com>
Wed, 27 May 2009 08:16:35 +0000 (10:16 +0200)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 28 May 2009 08:30:06 +0000 (10:30 +0200)
Doing otherwise can result in a lot of warnings and errors:

warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master

error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/bw/log is at a16df35cc7009b36f6f71717ae3d9a3dc29987da but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/bw/log
error: Ref refs/top-bases/bw/log is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/top-bases/bw/log

 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] bw/log -> bw/log (failed to lock)
 ! [remote rejected] refs/top-bases/bw/log -> refs/top-bases/bw/log (failed to lock)

Note, the result is OK only the output is irritating.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
tg-push.sh

index 40849ae..8e1b43f 100644 (file)
@@ -45,27 +45,32 @@ for name in $branches; do
        ref_exists "$name" || die "detached HEAD? Can't push $name"
 done
 
+_listfile="$(mktemp -t tg-push-listfile.XXXXXX)"
+trap "rm -f \"$_listfile\"" 0
+
 push_branch()
 {
        # if so desired omit non tgish deps
        $tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
 
-       echo "$_dep"
+       echo "$_dep" >> "$_listfile"
        [ -z "$_dep_is_tgish" ] ||
-               echo "top-bases/$_dep"
+               echo "top-bases/$_dep" >> "$_listfile"
 }
 
 for name in $branches; do
-       list="$(
-               # deps
-               if $recurse_deps; then
-                       no_remotes=1 recurse_deps push_branch "$name"
-               fi
-               # current branch
-               _dep="$name"
-               _dep_is_tgish=1
-               push_branch "$name"
-       )"
-       echo "pushing:"; echo $list
-       git push $dry_run "$remote" $list
+       # current branch
+       # re-use push_branch, which expects some pre-defined variables
+       _dep="$name"
+       _dep_is_tgish=1
+       ref_exists "top-bases/$_dep" ||
+               _dep_is_tgish=
+       push_branch "$name"
+
+       # deps
+       $recurse_deps &&
+               no_remotes=1 recurse_deps push_branch "$name"
+
+       # remove multiple occurrences of the same branch
+       sort -u "$_listfile" | xargs git push $dry_run "$remote"
 done