# [TopGit PATCH] Make tg help work in any directory

1 messages from 2010-10-24 to 2010-10-24. Participants: Robin Green.
Thread: https://gitlist.dev/t/25540

## Robin Green, 2010-10-24 14:34

Subject: [TopGit PATCH] Make tg help work in any directory
Message-ID: <1287930899-20186-1-git-send-email-greenrd@greenrd.org>
URL: https://gitlist.dev/e/1287930899-20186-1-git-send-email-greenrd%40greenrd.org

```
tg was checking if the current directory is a git repository,
which isn't necessary if the command is "help" or there is no
command.

Signed-off-by: Robin Green <greenrd@greenrd.org>

---
 tg.sh |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/tg.sh b/tg.sh
index 8264a3b..03ef227 100644
--- a/tg.sh
+++ b/tg.sh
@@ -356,16 +356,25 @@ setup_pager()
 
 ## Initial setup
 
-set -e
-git_dir="$(git rev-parse --git-dir)"
-root_dir="$(git rev-parse --show-cdup)"; root_dir="${root_dir:-.}"
+cmd="$1"
+[ -z "$tg__include" ] || cmd="include" # ensure setup happens
+case "$cmd" in
+help|--help|-h)
+        :;;
+*)
+        if [ -n "$cmd" ]; then
+            set -e
+            git_dir="$(git rev-parse --git-dir)"
+            root_dir="$(git rev-parse --show-cdup)"; root_dir="${root_dir:-.}"
 # Make sure root_dir doesn't end with a trailing slash.
-root_dir="${root_dir%/}"
-base_remote="$(git config topgit.remote 2>/dev/null)" || :
-tg="tg"
+            root_dir="${root_dir%/}"
+            base_remote="$(git config topgit.remote 2>/dev/null)" || :
+            tg="tg"
 # make sure merging the .top* files will always behave sanely
-setup_ours
-setup_hook "pre-commit"
+            setup_ours
+            setup_hook "pre-commit"
+        fi
+esac
 
 ## Dispatch
 
@@ -385,7 +394,6 @@ if [ "$1" = "-r" ]; then
 	tg="$tg -r $base_remote"
 fi
 
-cmd="$1"
 [ -n "$cmd" ] || { do_help; exit 1; }
 shift
 
-- 
tg: (8b0f1f9..) t/help-anywhere (depends on: master)

```
