chiark / gitweb /
Let tg-update take a branch parameter
[topgit.git] / tg-update.sh
index 34fa6dcb10f59799e0df977e98544483cff3fc30..b256c7c270b41c4e8f5d384a7ece4011d07beb74 100644 (file)
@@ -8,13 +8,19 @@ name=
 
 ## Parse options
 
-if [ -n "$1" ]; then
-       echo "Usage: tg update" >&2
-       exit 1
-fi
-
-
-name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
+while [ -n "$1" ]; do
+       arg="$1"; shift
+       case "$arg" in
+       -*)
+               echo "Usage: tg [...] update [NAME]" >&2
+               exit 1;;
+       *)
+               [ -z "$name" ] || die "name already specified ($name)"
+               name="$arg";;
+       esac
+done
+
+[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
        die "not a TopGit-controlled branch"
 
@@ -54,12 +60,12 @@ if [ -s "$depcheck" ]; then
                                (
                                export TG_RECURSIVE="[$dep] $TG_RECURSIVE"
                                export PS1="[$dep] $PS1"
-                               while ! tg update; do
+                               while ! $tg update; do
                                        # The merge got stuck! Let the user fix it up.
                                        info "You are in a subshell. If you abort the merge,"
                                        info "use \`exit 1\` to abort the recursive update altogether."
                                        if ! sh -i </dev/tty; then
-                                               info "Ok, you aborated the merge. Now, you just need to"
+                                               info "Ok, you aborted the merge. Now, you just need to"
                                                info "switch back to some sane branch using \`git checkout\`."
                                                exit 3
                                        fi
@@ -75,7 +81,7 @@ if [ -s "$depcheck" ]; then
                        info "Updating base with $dep changes..."
                        if ! git merge "$dep"; then
                                if [ -z "$TG_RECURSIVE" ]; then
-                                       resume='`tg update` again'
+                                       resume="\`git checkout $name && $tg update\` again"
                                else # subshell
                                        resume='exit'
                                fi
@@ -87,14 +93,16 @@ if [ -s "$depcheck" ]; then
                                exit 2
                        fi
                done
-
-       # Home, sweet home...
-       git checkout -q "$name"
 else
        info "The base is up-to-date."
 fi
 rm "$depcheck"
 
+# Home, sweet home...
+# (We want to always switch back, in case we were on the base from failed
+# previous merge.)
+git checkout -q "$name"
+
 merge_with="refs/top-bases/$name"
 
 
@@ -133,10 +141,12 @@ if ! git merge "$merge_with"; then
        if [ -z "$TG_RECURSIVE" ]; then
                info "Please commit merge resolution. No need to do anything else"
                info "You can abort this operation using \`git reset --hard\` now"
-               info "and retry this merge later using \`tg update\`."
+               info "and retry this merge later using \`$tg update\`."
        else # subshell
                info "Please commit merge resolution and call exit."
                info "You can abort this operation using \`git reset --hard\`."
        fi
        exit 3
 fi
+
+# vim:noet