From: Ian Jackson Date: Wed, 28 Dec 2011 01:52:52 +0000 (+0000) Subject: Merge commit 'refs/top-bases/fixes/independent-help' into fixes/independent-help X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=cc57ff8b9f834918d8cee3e76deb10cc519ee8cb;hp=d279e292a787fa733746c3d15209c70e5596ab10;p=topgit.git Merge commit 'refs/top-bases/fixes/independent-help' into fixes/independent-help --- diff --git a/.topdeps b/.topdeps new file mode 100644 index 0000000..0459513 --- /dev/null +++ b/.topdeps @@ -0,0 +1 @@ +upstream diff --git a/.topmsg b/.topmsg new file mode 100644 index 0000000..b229ffa --- /dev/null +++ b/.topmsg @@ -0,0 +1,10 @@ +From: martin f. krafft +Subject: [TopGit PATCH] Allow help/--help/-h to be run outside of a TopGit repo + +The user ought to be able to call `tg help` from anywhere in the filesystem, +not just Git repositories, so the help parsing has to happen before the calls +to git git binary. + +Debian bug: #501982 + +Signed-off-by: martin f. krafft diff --git a/tg.sh b/tg.sh index 9082d88..734ddcc 100644 --- a/tg.sh +++ b/tg.sh @@ -374,6 +374,29 @@ do_help() fi } +# Check whether we are supposed to output the help message +should_do_help() +{ + # we are being sourced for utility functions, never run help + [ -z "$tg__include" ] || return 1 + + local prev + while [ -n "$1" ]; do + case "$1" in + help|--help|-h) + shift + echo "${1:-$prev}" + return 0 + esac + prev="$1" + shift + done + + # run help when there was no previous topic, meaning that there where + # no arguments at all + test -z "$prev" +} + ## Pager stuff # isatty FD @@ -427,6 +450,9 @@ get_temp() [ -d "@cmddir@" ] || die "No command directory: '@cmddir@'" +# check if we should run help and get the topic while we're at it +help_topic="$(should_do_help "$@")" && { do_help "$help_topic"; exit 0; } + ## Initial setup set -e @@ -466,9 +492,6 @@ cmd="$1" shift case "$cmd" in -help|--help|-h) - do_help "$1" - exit 0;; --hooks-path) # Internal command echo "@hooksdir@";;