X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=blobdiff_plain;f=tg-update.sh;h=5162c52b9d335f383a0bdb54ceb0c5929463b20f;hp=5caf6910a17f7c39906fe6456bd550faf4b537c2;hb=608626e5896f71da51467fedb6f461342df3f850;hpb=9092d7656e160bc7384d82c6c42062817ae0a20f diff --git a/tg-update.sh b/tg-update.sh index 5caf691..5162c52 100644 --- a/tg-update.sh +++ b/tg-update.sh @@ -8,20 +8,26 @@ 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" ## First, take care of our base -depcheck="$(mktemp -t tg-depcheck.XXXXXX)" +depcheck="$(get_temp tg-depcheck)" missing_deps= needs_update "$name" >"$depcheck" || : [ -z "$missing_deps" ] || die "some dependencies are missing: $missing_deps" @@ -43,9 +49,10 @@ if [ -s "$depcheck" ]; then dep="$(echo "$depline" | cut -c 2-)" # We do not distinguish between dependencies out-of-date - # and base out-of-date cases for $dep here, - # but thanks to needs_update returning : for the latter, - # we do correctly recurse here in both cases. + # and base/remote out-of-date cases for $dep here, + # but thanks to needs_update returning : or % + # for the latter, we do correctly recurse here + # in both cases. if [ x"$action" = x+ ]; then info "Recursing to $dep..." @@ -53,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 " + info "It is also safe to abort this operation using: git reset --hard $name" + exit 3 + fi + # Go back but remember we want to merge with this, not base + merge_with="$(git rev-parse HEAD)" + git checkout -q "$name" + fi +fi -## Second, update our head with the base -if branch_contains "$name" "refs/top-bases/$name"; then +## Third, update our head with the base + +if branch_contains "$name" "$merge_with"; then info "The $name head is up-to-date wrt. the base." exit 0 fi info "Updating $name against new base..." -if ! git merge "refs/top-bases/$name"; then +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