Skip to content

Commit

Permalink
Fix tests breaking when checkout path contains shell metacharacters
Browse files Browse the repository at this point in the history
This fixes the remainder of the issues where the test script itself is at
fault for failing when the git checkout path contains whitespace or other
shell metacharacters.

The majority of git svn tests used the idiom

  test_expect_success "title" "test script using $svnrepo"

These were changed to have the test script in single-quotes:

  test_expect_success "title" 'test script using "$svnrepo"'

which unfortunately makes the patch appear larger than it really is.

One consequence of this change is that in the verbose test output the
value of $svnrepo (and in some cases other variables, too) is no
longer expanded, i.e. previously we saw

  * expecting success:
	test script using /path/to/git/t/trash/svnrepo

but now it is:

  * expecting success:
	test script using "$svnrepo"

Signed-off-by: Bryan Donlan <bdonlan@fushizen.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Bryan Donlan authored and Junio C Hamano committed May 5, 2008
1 parent 0e46e70 commit f69e836
Show file tree
Hide file tree
Showing 39 changed files with 475 additions and 469 deletions.
4 changes: 2 additions & 2 deletions t/t0000-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ test_expect_success 'absolute path works as expected' '
file="$dir"/index &&
test "$file" = "$(test-absolute-path $dir2/index)" &&
basename=blub &&
test "$dir/$basename" = $(cd .git && test-absolute-path $basename) &&
test "$dir/$basename" = "$(cd .git && test-absolute-path "$basename")" &&
ln -s ../first/file .git/syml &&
sym="$(cd first; pwd -P)"/file &&
test "$sym" = "$(test-absolute-path $dir2/syml)"
test "$sym" = "$(test-absolute-path "$dir2/syml")"
'

test_expect_success 'very long name in the index handled sanely' '
Expand Down
22 changes: 11 additions & 11 deletions t/t1020-subdirectory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LF='
'

test_expect_success 'update-index and ls-files' '
cd $HERE &&
cd "$HERE" &&
git update-index --add one &&
case "`git ls-files`" in
one) echo ok one ;;
Expand All @@ -41,7 +41,7 @@ test_expect_success 'update-index and ls-files' '
'

test_expect_success 'cat-file' '
cd $HERE &&
cd "$HERE" &&
two=`git ls-files -s dir/two` &&
two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
echo "$two" &&
Expand All @@ -54,7 +54,7 @@ test_expect_success 'cat-file' '
rm -f actual dir/actual

test_expect_success 'diff-files' '
cd $HERE &&
cd "$HERE" &&
echo a >>one &&
echo d >>dir/two &&
case "`git diff-files --name-only`" in
Expand All @@ -74,7 +74,7 @@ test_expect_success 'diff-files' '
'

test_expect_success 'write-tree' '
cd $HERE &&
cd "$HERE" &&
top=`git write-tree` &&
echo $top &&
cd dir &&
Expand All @@ -84,7 +84,7 @@ test_expect_success 'write-tree' '
'

test_expect_success 'checkout-index' '
cd $HERE &&
cd "$HERE" &&
git checkout-index -f -u one &&
cmp one original.one &&
cd dir &&
Expand All @@ -93,7 +93,7 @@ test_expect_success 'checkout-index' '
'

test_expect_success 'read-tree' '
cd $HERE &&
cd "$HERE" &&
rm -f one dir/two &&
tree=`git write-tree` &&
git read-tree --reset -u "$tree" &&
Expand All @@ -107,27 +107,27 @@ test_expect_success 'read-tree' '
'

test_expect_success 'no file/rev ambiguity check inside .git' '
cd $HERE &&
cd "$HERE" &&
git commit -a -m 1 &&
cd $HERE/.git &&
cd "$HERE"/.git &&
git show -s HEAD
'

test_expect_success 'no file/rev ambiguity check inside a bare repo' '
cd $HERE &&
cd "$HERE" &&
git clone -s --bare .git foo.git &&
cd foo.git && GIT_DIR=. git show -s HEAD
'

# This still does not work as it should...
: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
cd $HERE &&
cd "$HERE" &&
git clone -s --bare .git foo.git &&
cd foo.git && git show -s HEAD
'

test_expect_success 'detection should not be fooled by a symlink' '
cd $HERE &&
cd "$HERE" &&
rm -fr foo.git &&
git clone -s .git another &&
ln -s another yetanother &&
Expand Down
2 changes: 1 addition & 1 deletion t/t3050-subprojects-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_expect_success setup '
'

test_expect_success clone '
git clone file://`pwd`/.git cloned &&
git clone "file://$(pwd)/.git" cloned &&
(git rev-parse HEAD; git ls-files -s) >expected &&
(
cd cloned &&
Expand Down
3 changes: 1 addition & 2 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ for line in $FAKE_LINES; do
done
EOF

test_set_editor "$(pwd)/fake-editor.sh"
chmod a+x fake-editor.sh
VISUAL="$(pwd)/fake-editor.sh"
export VISUAL

test_expect_success 'no changes are a nop' '
git rebase -i F &&
Expand Down
2 changes: 1 addition & 1 deletion t/t5500-fetch-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pull_to_client 2nd "B" $((64*3))

pull_to_client 3rd "A" $((1*3)) # old fails

test_expect_success "clone shallow" "git-clone --depth 2 file://`pwd`/. shallow"
test_expect_success "clone shallow" 'git-clone --depth 2 "file://$(pwd)/." shallow'

(cd shallow; git count-objects -v) > count.shallow

Expand Down
2 changes: 1 addition & 1 deletion t/t5512-ls-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_expect_success setup '
git show-ref -d | sed -e "s/ / /"
) >expected.all &&
git remote add self $(pwd)/.git
git remote add self "$(pwd)/.git"
'

Expand Down
6 changes: 3 additions & 3 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test_expect_success 'fetch with insteadOf' '
(
TRASH=$(pwd)/ &&
cd testrepo &&
git config url.$TRASH.insteadOf trash/
git config "url.$TRASH.insteadOf" trash/ &&
git config remote.up.url trash/. &&
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up &&
Expand Down Expand Up @@ -145,8 +145,8 @@ test_expect_success 'push with wildcard' '

test_expect_success 'push with insteadOf' '
mk_empty &&
TRASH=$(pwd)/ &&
git config url.$TRASH.insteadOf trash/ &&
TRASH="$(pwd)/" &&
git config "url./$TRASH/.insteadOf" trash/ &&
git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
(
cd testrepo &&
Expand Down
2 changes: 1 addition & 1 deletion t/t5700-clone-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ diff expected current'
cd "$base_dir"

test_expect_success 'cloning with reference (no -l -s)' \
'git clone --reference B file://`pwd`/A D'
'git clone --reference B "file://$(pwd)/A" D'

cd "$base_dir"

Expand Down
4 changes: 2 additions & 2 deletions t/t5710-info-alternate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ test_valid_repo'
cd "$base_dir"

test_expect_success 'breaking of loops' \
"echo '$base_dir/B/.git/objects' >> '$base_dir'/A/.git/objects/info/alternates&&
'echo "$base_dir"/B/.git/objects >> "$base_dir"/A/.git/objects/info/alternates&&
cd C &&
test_valid_repo"
test_valid_repo'

cd "$base_dir"

Expand Down
2 changes: 1 addition & 1 deletion t/t7003-filter-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ test_expect_success 'use index-filter to move into a subdirectory' '
"git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE" directorymoved &&
mv \"\$GIT_INDEX_FILE.new\" \"\$GIT_INDEX_FILE\"" directorymoved &&
test -z "$(git diff HEAD directorymoved:newsubdir)"'

test_expect_success 'stops when msg filter fails' '
Expand Down
2 changes: 1 addition & 1 deletion t/t7010-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ test_expect_success 'commit using absolute path names' '

test_expect_success 'log using absolute path names' '
echo bb >>a/b/c/d &&
git commit -m "bb" $(pwd)/a/b/c/d &&
git commit -m "bb" "$(pwd)/a/b/c/d" &&
git log a/b/c/d >f1.txt &&
git log "$(pwd)/a/b/c/d" >f2.txt &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7300-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test_expect_success 'git-clean with absolute path' '
touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
would_clean=$(
cd docs &&
git clean -n $(pwd)/../src |
git clean -n "$(pwd)/../src" |
sed -n -e "s|^Would remove ||p"
) &&
test "$would_clean" = ../src/part3.c || {
Expand Down
8 changes: 4 additions & 4 deletions t/t7501-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ test_expect_success \

cat >editor <<\EOF
#!/bin/sh
sed -e "s/a file/an amend commit/g" < $1 > $1-
mv $1- $1
sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
mv "$1-" "$1"
EOF
chmod 755 editor

Expand All @@ -99,8 +99,8 @@ test_expect_success \

cat >editor <<\EOF
#!/bin/sh
sed -e "s/amend/older/g" < $1 > $1-
mv $1- $1
sed -e "s/amend/older/g" < "$1" > "$1-"
mv "$1-" "$1"
EOF
chmod 755 editor

Expand Down
23 changes: 13 additions & 10 deletions t/t7504-commit-msg-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ cp FAKE_MSG "$1"
exit 0
EOF
chmod +x fake-editor

## Not using test_set_editor here so we can easily ensure the editor variable
## is only set for the editor tests
FAKE_EDITOR="$(pwd)/fake-editor"
export FAKE_EDITOR

Expand All @@ -27,7 +30,7 @@ test_expect_success 'with no hook (editor)' '
echo "more foo" >> file &&
git add file &&
echo "more foo" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit
'

Expand All @@ -44,7 +47,7 @@ test_expect_success '--no-verify with no hook (editor)' '
echo "more bar" > file &&
git add file &&
echo "more bar" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
'

Expand All @@ -71,7 +74,7 @@ test_expect_success 'with succeeding hook (editor)' '
echo "more more" >> file &&
git add file &&
echo "more more" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit
'

Expand All @@ -88,7 +91,7 @@ test_expect_success '--no-verify with succeeding hook (editor)' '
echo "even more more" >> file &&
git add file &&
echo "even more more" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
'

Expand All @@ -111,7 +114,7 @@ test_expect_success 'with failing hook (editor)' '
echo "more another" >> file &&
git add file &&
echo "more another" > FAKE_MSG &&
! (GIT_EDITOR="$FAKE_EDITOR" git commit)
! (GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit)
'

Expand All @@ -128,7 +131,7 @@ test_expect_success '--no-verify with failing hook (editor)' '
echo "more stuff" >> file &&
git add file &&
echo "more stuff" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
'

Expand All @@ -146,7 +149,7 @@ test_expect_success 'with non-executable hook (editor)' '
echo "content again" >> file &&
git add file &&
echo "content again" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit -m "content again"
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit -m "content again"
'

Expand All @@ -163,7 +166,7 @@ test_expect_success '--no-verify with non-executable hook (editor)' '
echo "even more content" >> file &&
git add file &&
echo "even more content" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
'

Expand Down Expand Up @@ -193,7 +196,7 @@ test_expect_success 'hook edits commit message (editor)' '
echo "additional content" >> file &&
git add file &&
echo "additional content" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit &&
commit_msg_is "new message"
'
Expand All @@ -212,7 +215,7 @@ test_expect_success "hook doesn't edit commit message (editor)" '
echo "more plus" >> file &&
git add file &&
echo "more plus" > FAKE_MSG &&
GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
commit_msg_is "more plus"
'
Expand Down
Loading

0 comments on commit f69e836

Please sign in to comment.