chiark / gitweb /
Check for help invocation before setup
[topgit.git] / tg.sh
diff --git a/tg.sh b/tg.sh
index 959f621ed9ac4cec251c31412a9696b051a1a8c5..da3366d533f49702c1c25ab0a7bd9022e3fdf137 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -236,6 +236,24 @@ do_help()
 }
 
 
+## Startup
+
+[ -d "@cmddir@" ] ||
+       die "No command directory: '@cmddir@'"
+
+args_saved="$@"
+while [ -n "$1" ]; do
+       case "$1" in
+       help|--help|-h)
+               shift
+               do_help "$1"
+               exit 0;;
+       esac
+       shift
+done
+set -- $args_saved
+unset args_saved
+
 ## Initial setup
 
 set -e
@@ -249,9 +267,6 @@ tg="tg"
 setup_ours
 setup_hook "pre-commit"
 
-[ -d "@cmddir@" ] ||
-       die "No command directory: '@cmddir@'"
-
 ## Dispatch
 
 # We were sourced from another script for our utility functions;
@@ -264,13 +279,10 @@ if [ "$1" = "-r" ]; then
 fi
 
 cmd="$1"
-[ -n "$cmd" ] || die "He took a duck in the face at two hundred and fifty knots"
+[ -n "$cmd" ] || { do_help; exit 1; }
 shift
 
 case "$cmd" in
-help|--help|-h)
-       do_help "$1"
-       exit 0;;
 --hooks-path)
        # Internal command
        echo "@hooksdir@";;