Use cd_to_toplevel in scripts that implement it by hand.
This converts scripts that do "cd $(rev-parse --show-cdup)" by hand to use cd_to_toplevel. I think git-fetch does not have to go to the toplevel, but that should be dealt with in a separate patch. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 12, 2007 at 12:49 UTC
514c09fdcfef6385f1a61ee52344794356c99986
4 files changed
+11
-29
git-checkout.sh
+1
-5
@@ -135,11 +135,7 @@ fi
135
136
# We are switching branches and checking out trees, so
137
# we *NEED* to be at the toplevel.
138
-cdup=$(git-rev-parse --show-cdup)
139
-if test ! -z "$cdup"
140
-then
141
- cd "$cdup"
142
-fi
138
+cd_to_toplevel
139
140
[ -z "$new" ] && new=$old && new_name="$old_name"
141
git-commit.sh
+8
-14
@@ -316,22 +316,16 @@ esac
316
################################################################
317
# Prepare index to have a tree to be committed
318
319
-TOP=`git-rev-parse --show-cdup`
320
-if test -z "$TOP"
321
-then
322
- TOP=./
323
-fi
324
-
319
case "$all,$also" in
320
t,)
321
save_index &&
322
(
329
- cd "$TOP"
330
- GIT_INDEX_FILE="$NEXT_INDEX"
331
- export GIT_INDEX_FILE
323
+ cd_to_toplevel &&
324
+ GIT_INDEX_FILE="$NEXT_INDEX" &&
325
+ export GIT_INDEX_FILE &&
326
git-diff-files --name-only -z |
327
git-update-index --remove -z --stdin
334
- )
328
+ ) || exit
329
;;
330
,t)
331
save_index &&
@@ -339,11 +333,11 @@ t,)
333
334
git-diff-files --name-only -z -- "$@" |
335
(
342
- cd "$TOP"
343
- GIT_INDEX_FILE="$NEXT_INDEX"
344
- export GIT_INDEX_FILE
336
+ cd_to_toplevel &&
337
+ GIT_INDEX_FILE="$NEXT_INDEX" &&
338
+ export GIT_INDEX_FILE &&
339
git-update-index --remove -z --stdin
346
- )
340
+ ) || exit
341
;;
342
,)
343
case "$#" in
git-fetch.sh
+1
-5
@@ -5,12 +5,8 @@ USAGE='<fetch-options> <repository> <refspec>...'
5
SUBDIRECTORY_OK=Yes
6
. git-sh-setup
7
set_reflog_action "fetch $*"
8
+cd_to_toplevel ;# probably unnecessary...
9
9
-TOP=$(git-rev-parse --show-cdup)
10
-if test ! -z "$TOP"
11
-then
12
- cd "$TOP"
13
-fi
10
. git-parse-remote
11
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
12
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
git-reset.sh
+1
-5
@@ -53,11 +53,7 @@ then
53
exit
54
fi
55
56
-TOP=$(git-rev-parse --show-cdup)
57
-if test ! -z "$TOP"
58
-then
59
- cd "$TOP"
60
-fi
56
+cd_to_toplevel
57
58
if test "$reset_type" = "--hard"
59
then