git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[TopGit PATCH] Make tg help work in any directory

From
Robin Green <greenrd@greenrd.org>
Date
Oct 24, 2010, 14:34 UTC
Message-ID
<1287930899-20186-1-git-send-email-greenrd@greenrd.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)
Message 1 of 1 in “Make tg help work in any directory”
  1. Make tg help work in any directoryRobin Green, Oct 24, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.