DORMANTno replies

[TopGit PATCH] Make tg help work in any directory

From: Robin Green <hidden>
Date: 2016-06-15 22:49:52
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>

---
 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)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help