chiark / gitweb /
Merge commit 'refs/top-bases/fixes/independent-help' into fixes/independent-help
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 3 Mar 2009 10:23:44 +0000 (11:23 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 3 Mar 2009 10:23:44 +0000 (11:23 +0100)
.topdeps [new file with mode: 0644]
.topmsg [new file with mode: 0644]
tg.sh

diff --git a/.topdeps b/.topdeps
new file mode 100644 (file)
index 0000000..0459513
--- /dev/null
+++ b/.topdeps
@@ -0,0 +1 @@
+upstream
diff --git a/.topmsg b/.topmsg
new file mode 100644 (file)
index 0000000..b229ffa
--- /dev/null
+++ b/.topmsg
@@ -0,0 +1,10 @@
+From: martin f. krafft <madduck@debian.org>
+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 <madduck@debian.org>
diff --git a/tg.sh b/tg.sh
index f0496f1b6ade99b1f9290f3cc5fe7096fc4373ba..119c152c3e823eaf0e7715804b7248ca28774935 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -280,6 +280,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
@@ -324,6 +347,9 @@ setup_pager()
 [ -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
@@ -359,9 +385,6 @@ cmd="$1"
 shift
 
 case "$cmd" in
-help|--help|-h)
-       do_help "$1"
-       exit 0;;
 --hooks-path)
        # Internal command
        echo "@hooksdir@";;