Git development
 help / color / mirror / Atom feed
* [PATCH] Allow help/--help/-h to be run outside of a TopGit repo
@ 2008-11-20 11:46 martin f. krafft
  2008-11-20 14:27 ` Petr Baudis
  0 siblings, 1 reply; 5+ messages in thread
From: martin f. krafft @ 2008-11-20 11:46 UTC (permalink / raw)
  To: git, pasky; +Cc: martin f. krafft

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>

---
 tg.sh |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/tg.sh b/tg.sh
index 4dcc15e..258f8ce 100644
--- a/tg.sh
+++ b/tg.sh
@@ -235,12 +235,37 @@ 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"
+}
 
 ## Startup
 
 [ -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
@@ -270,9 +295,6 @@ cmd="$1"
 shift
 
 case "$cmd" in
-help|--help|-h)
-	do_help "$1"
-	exit 0;;
 --hooks-path)
 	# Internal command
 	echo "@hooksdir@";;
-- 
tg: (f17218e..) fixes/independent-help (depends on: upstream)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-20 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-20 11:46 [PATCH] Allow help/--help/-h to be run outside of a TopGit repo martin f. krafft
2008-11-20 14:27 ` Petr Baudis
2008-11-20 14:55   ` martin f krafft
2008-11-20 15:08     ` Petr Baudis
2008-11-20 15:11       ` martin f krafft

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox