-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
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
missing_deps=
needs_update "$name" >"$depcheck" || :
[ -z "$missing_deps" ] || die "some dependencies are missing: $missing_deps"
missing_deps=
needs_update "$name" >"$depcheck" || :
[ -z "$missing_deps" ] || die "some dependencies are missing: $missing_deps"
# 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
# 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 "Updating base with $dep changes..."
if ! git merge "$dep"; then
if [ -z "$TG_RECURSIVE" ]; then
info "Updating base with $dep changes..."
if ! git merge "$dep"; then
if [ -z "$TG_RECURSIVE" ]; then
merge_with="refs/top-bases/$name"
## Second, update our head with the remote branch
merge_with="refs/top-bases/$name"
## Second, update our head with the remote branch
if branch_contains "$name" "$rname"; then
info "The $name head is up-to-date wrt. its remote branch."
else
if branch_contains "$name" "$rname"; then
info "The $name head is up-to-date wrt. its remote branch."
else
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"
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"
else # subshell
info "Please commit merge resolution and call exit."
info "You can abort this operation using \`git reset --hard\`."
fi
exit 3
fi
else # subshell
info "Please commit merge resolution and call exit."
info "You can abort this operation using \`git reset --hard\`."
fi
exit 3
fi