@matheusbsbs / matheus-bagliano / commits / 22c9071728
Fork 0

git-help -w: do not require to be in git repository

The users used to be able to say "git help cat-file" from anywhere, but the browse-help script insisted to be in a git repository, which caused "git help -w cat-file" to barf outside. Correct it. While at it, remove leftover debugging "echo". Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 12, 2007 at 17:34 UTC 22c9071728cdc4c5b39e4fc6a33036d967d3a3a5
2 files changed +34 -24
git-browse-help.sh
+8 -5
@@ -17,8 +17,10 @@
17 #
18
19 USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'
20 -SUBDIRECTORY_OK=Yes
21 -OPTIONS_SPEC=
20 +
21 +# This must be capable of running outside of git directory, so
22 +# the vanilla git-sh-setup should not be used.
23 +NONGIT_OK=Yes
24 . git-sh-setup
25
26 # Install data.
@@ -37,7 +39,7 @@ valid_tool() {
39 }
40
41 init_browser_path() {
40 - browser_path=`git config browser.$1.path`
42 + test -z "$GIT_DIR" || browser_path=`git config browser.$1.path`
43 test -z "$browser_path" && browser_path=$1
44 }
45
@@ -69,7 +71,8 @@ do
71 shift
72 done
73
72 -if test -z "$browser"; then
74 +if test -z "$browser" && test -n "$GIT_DIR"
75 +then
76 for opt in "help.browser" "web.browser"
77 do
78 browser="`git config $opt`"
@@ -91,7 +94,7 @@ if test -z "$browser" ; then
94 else
95 browser_candidates="w3m links lynx"
96 fi
94 - echo "browser candidates: $browser_candidates"
97 +
98 for i in $browser_candidates; do
99 init_browser_path $i
100 if type "$browser_path" > /dev/null 2>&1; then
git-sh-setup.sh
+26 -19
@@ -122,26 +122,33 @@ get_author_ident_from_commit () {
122 LANG=C LC_ALL=C sed -ne "$pick_author_script"
123 }
124
125 -# Make sure we are in a valid repository of a vintage we understand.
126 -if [ -z "$SUBDIRECTORY_OK" ]
125 +# Make sure we are in a valid repository of a vintage we understand,
126 +# if we require to be in a git repository.
127 +if test -n "$NONGIT_OK"
128 then
128 - : ${GIT_DIR=.git}
129 - test -z "$(git rev-parse --show-cdup)" || {
130 - exit=$?
131 - echo >&2 "You need to run this command from the toplevel of the working tree."
132 - exit $exit
133 - }
129 + if git rev-parse --git-dir >/dev/null 2>&1
130 + then
131 + : ${GIT_DIR=.git}
132 + fi
133 else
135 - GIT_DIR=$(git rev-parse --git-dir) || {
136 - exit=$?
137 - echo >&2 "Failed to find a valid git directory."
138 - exit $exit
134 + if [ -z "$SUBDIRECTORY_OK" ]
135 + then
136 + : ${GIT_DIR=.git}
137 + test -z "$(git rev-parse --show-cdup)" || {
138 + exit=$?
139 + echo >&2 "You need to run this command from the toplevel of the working tree."
140 + exit $exit
141 + }
142 + else
143 + GIT_DIR=$(git rev-parse --git-dir) || {
144 + exit=$?
145 + echo >&2 "Failed to find a valid git directory."
146 + exit $exit
147 + }
148 + fi
149 + test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || {
150 + echo >&2 "Unable to determine absolute path of git directory"
151 + exit 1
152 }
153 + : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
154 fi
141 -
142 -test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || {
143 - echo >&2 "Unable to determine absolute path of git directory"
144 - exit 1
145 -}
146 -
147 -: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}