* [PATCH] Several tests: cd inside subshell instead of around
@ 2010-09-06 18:39 Jens Lehmann
2010-09-06 19:06 ` Jonathan Nieder
2010-09-06 23:16 ` [PATCH] Several tests: cd inside subshell instead of around Junio C Hamano
0 siblings, 2 replies; 27+ messages in thread
From: Jens Lehmann @ 2010-09-06 18:39 UTC (permalink / raw
To: Junio C Hamano; +Cc: Git Mailing List
Fixed all places where it was a straightforward change from cd'ing into a
directory and back via "cd .." to a cd inside a subshell.
Found these places with "git grep -w "cd \.\.".
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
This patch applies to maint.
t/t1020-subdirectory.sh | 6 +-
t/t1302-repo-version.sh | 6 +-
t/t2101-update-index-reupdate.sh | 6 +-
t/t3060-ls-files-with-tree.sh | 4 +-
t/t3409-rebase-preserve-merges.sh | 12 +-
t/t3903-stash.sh | 6 +-
t/t4041-diff-submodule-option.sh | 6 +-
t/t5510-fetch.sh | 18 ++--
t/t6050-replace.sh | 22 ++--
t/t7400-submodule-basic.sh | 6 +-
t/t7401-submodule-summary.sh | 6 +-
t/t9100-git-svn-basic.sh | 6 +-
t/t9101-git-svn-props.sh | 16 ++--
t/t9102-git-svn-deep-rmdir.sh | 6 +-
t/t9104-git-svn-follow-parent.sh | 30 +++---
t/t9105-git-svn-commit-diff.sh | 6 +-
t/t9106-git-svn-commit-diff-clobber.sh | 24 +++---
t/t9107-git-svn-migrate.sh | 4 +-
t/t9114-git-svn-dcommit-merge.sh | 6 +-
t/t9115-git-svn-dcommit-funky-renames.sh | 6 +-
t/t9116-git-svn-log.sh | 4 +-
t/t9119-git-svn-info.sh | 126 ++++++++++++------------
t/t9120-git-svn-clone-with-percent-escapes.sh | 6 +-
t/t9123-git-svn-rebuild-with-rewriteroot.sh | 4 +-
t/t9125-git-svn-multi-glob-branch-names.sh | 12 +-
t/t9127-git-svn-partial-rebuild.sh | 30 +++---
t/t9128-git-svn-cmd-branch.sh | 18 ++--
t/t9137-git-svn-dcommit-clobber-series.sh | 12 +-
t/t9300-fast-import.sh | 5 +-
t/t9401-git-cvsserver-crlf.sh | 53 +++++-----
t/t9600-cvsimport.sh | 38 ++++----
t/t9603-cvsimport-patchsets.sh | 6 +-
32 files changed, 256 insertions(+), 260 deletions(-)
diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index 5687499..c36157a 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -27,13 +27,13 @@ test_expect_success 'update-index and ls-files' '
one) echo pass one ;;
*) echo bad one; exit 1 ;;
esac &&
- cd dir &&
+ (cd dir &&
git update-index --add two &&
case "`git ls-files`" in
two) echo pass two ;;
*) echo bad two; exit 1 ;;
- esac &&
- cd .. &&
+ esac
+ ) &&
case "`git ls-files`" in
dir/two"$LF"one) echo pass both ;;
*) echo bad; exit 1 ;;
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index 8d305b4..c948719 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -32,9 +32,9 @@ test_expect_success 'gitdir selection on unsupported repo' '
test "$(git config core.repositoryformatversion)" = 99)'
test_expect_success 'gitdir not required mode' '
- (git apply --stat test.patch &&
- cd test && git apply --stat ../test.patch &&
- cd ../test2 && git apply --stat ../test.patch)'
+ git apply --stat test.patch &&
+ (cd test && git apply --stat ../test.patch) &&
+ (cd test2 && git apply --stat ../test.patch)'
test_expect_success 'gitdir required mode on normal repos' '
(git apply --check --index test.patch &&
diff --git a/t/t2101-update-index-reupdate.sh b/t/t2101-update-index-reupdate.sh
index 648184f..76ad7c3 100755
--- a/t/t2101-update-index-reupdate.sh
+++ b/t/t2101-update-index-reupdate.sh
@@ -63,10 +63,10 @@ cat > expected <<\EOF
EOF
test_expect_success 'update-index --update from subdir' \
'echo not so happy >file2 &&
- cd dir1 &&
+ (cd dir1 &&
cat ../file2 >file3 &&
- git update-index --again &&
- cd .. &&
+ git update-index --again
+ ) &&
git ls-files -s >current &&
cmp current expected'
diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh
index 3ce501b..25afb4f 100755
--- a/t/t3060-ls-files-with-tree.sh
+++ b/t/t3060-ls-files-with-tree.sh
@@ -55,15 +55,13 @@ test_expect_success setup '
# We have to run from a sub-directory to trigger prune_path
# Then we finally get to run our --with-tree test
-cd sub
test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
- git ls-files --with-tree=HEAD~1 >../output
+ (cd sub && git ls-files --with-tree=HEAD~1 >../output)
'
-cd ..
test_expect_success \
'git -ls-files --with-tree should add entries from named tree.' \
'test_cmp expected output'
diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh
index 8f785e7..1a362d2 100755
--- a/t/t3409-rebase-preserve-merges.sh
+++ b/t/t3409-rebase-preserve-merges.sh
@@ -42,23 +42,23 @@ test_expect_success 'setup for merge-preserving rebase' \
git commit -a -m "Modify A2" &&
git clone ./. clone1 &&
- cd clone1 &&
+ (cd clone1 &&
git checkout -b topic origin/topic &&
- git merge origin/master &&
- cd .. &&
+ git merge origin/master
+ ) &&
echo Fifth > B &&
git add B &&
git commit -m "Add different B" &&
git clone ./. clone2 &&
- cd clone2 &&
+ (cd clone2 &&
git checkout -b topic origin/topic &&
test_must_fail git merge origin/master &&
echo Resolved > B &&
git add B &&
- git commit -m "Merge origin/master into topic" &&
- cd .. &&
+ git commit -m "Merge origin/master into topic"
+ ) &&
git checkout topic &&
echo Fourth >> B &&
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 62e208a..3f43012 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -69,9 +69,9 @@ test_expect_success 'apply stashed changes (including index)' '
test_expect_success 'unstashing in a subdirectory' '
git reset --hard HEAD &&
mkdir subdir &&
- cd subdir &&
- git stash apply &&
- cd ..
+ (cd subdir &&
+ git stash apply
+ )
'
test_expect_success 'drop top stash' '
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index 8e391cf..737c3d9 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -85,10 +85,10 @@ EOF
"
commit_file sm1 &&
-cd sm1 &&
+head3=$(cd sm1 &&
git reset --hard HEAD~2 >/dev/null &&
-head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
-cd ..
+git rev-parse --verify HEAD | cut -c1-7
+)
test_expect_success 'modified submodule(backward)' "
git diff-index -p --submodule=log HEAD >actual &&
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 4eb10f6..34d59d5 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -21,18 +21,18 @@ test_expect_success setup '
test_expect_success "clone and setup child repos" '
git clone . one &&
- cd one &&
+ (cd one &&
echo >file updated by one &&
- git commit -a -m "updated by one" &&
- cd .. &&
+ git commit -a -m "updated by one"
+ ) &&
git clone . two &&
- cd two &&
+ (cd two &&
git config branch.master.remote one &&
git config remote.one.url ../one/.git/ &&
- git config remote.one.fetch refs/heads/master:refs/heads/one &&
- cd .. &&
+ git config remote.one.fetch refs/heads/master:refs/heads/one
+ ) &&
git clone . three &&
- cd three &&
+ (cd three &&
git config branch.master.remote two &&
git config branch.master.merge refs/heads/one &&
mkdir -p .git/remotes &&
@@ -40,8 +40,8 @@ test_expect_success "clone and setup child repos" '
echo "URL: ../two/.git/"
echo "Pull: refs/heads/master:refs/heads/two"
echo "Pull: refs/heads/one:refs/heads/one"
- } >.git/remotes/two &&
- cd .. &&
+ } >.git/remotes/two
+ ) &&
git clone . bundle &&
git clone . seven
'
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 4185b7c..01dfa51 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -104,7 +104,7 @@ test_expect_success '"git fsck" works' '
test_expect_success 'repack, clone and fetch work' '
git repack -a -d &&
git clone --no-hardlinks . clone_dir &&
- cd clone_dir &&
+ (cd clone_dir &&
git show HEAD~5 | grep "A U Thor" &&
git show $HASH2 | grep "A U Thor" &&
git cat-file commit $R &&
@@ -113,8 +113,8 @@ test_expect_success 'repack, clone and fetch work' '
git fetch ../ "refs/replace/*:refs/replace/*" &&
git show HEAD~5 | grep "O Thor" &&
git show $HASH2 | grep "O Thor" &&
- git cat-file commit $R &&
- cd ..
+ git cat-file commit $R
+ )
'
test_expect_success '"git replace" listing and deleting' '
@@ -177,10 +177,10 @@ test_expect_success 'create parallel branch without the bug' '
test_expect_success 'push to cloned repo' '
git push cloned $HASH6^:refs/heads/parallel &&
- cd clone_dir &&
+ (cd clone_dir &&
git checkout parallel &&
- git log --pretty=oneline | grep $PARA2 &&
- cd ..
+ git log --pretty=oneline | grep $PARA2
+ )
'
test_expect_success 'push branch with replacement' '
@@ -191,20 +191,20 @@ test_expect_success 'push branch with replacement' '
git show $HASH6~2 | grep "O Thor" &&
git show $PARA3 | grep "O Thor" &&
git push cloned $HASH6^:refs/heads/parallel2 &&
- cd clone_dir &&
+ (cd clone_dir &&
git checkout parallel2 &&
git log --pretty=oneline | grep $PARA3 &&
- git show $PARA3 | grep "A U Thor" &&
- cd ..
+ git show $PARA3 | grep "A U Thor"
+ )
'
test_expect_success 'fetch branch with replacement' '
git branch tofetch $HASH6 &&
- cd clone_dir &&
+ (cd clone_dir &&
git fetch origin refs/heads/tofetch:refs/heads/parallel3
git log --pretty=oneline parallel3 | grep $PARA3
git show $PARA3 | grep "A U Thor"
- cd ..
+ )
'
test_expect_success 'bisect and replacements' '
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 9bda970..21b0839 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -413,12 +413,12 @@ test_expect_success 'submodule <invalid-path> warns' '
test_expect_success 'add submodules without specifying an explicit path' '
mkdir repo &&
- cd repo &&
+ (cd repo &&
git init &&
echo r >r &&
git add r &&
- git commit -m "repo commit 1" &&
- cd .. &&
+ git commit -m "repo commit 1"
+ ) &&
git clone --bare repo/ bare.git &&
cd addtest &&
git submodule add "$submodurl/repo" &&
diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh
index cee319d..b5ad45f 100755
--- a/t/t7401-submodule-summary.sh
+++ b/t/t7401-submodule-summary.sh
@@ -66,10 +66,10 @@ EOF
"
commit_file sm1 &&
-cd sm1 &&
+head3=$(cd sm1 &&
git reset --hard HEAD~2 >/dev/null &&
-head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
-cd ..
+git rev-parse --verify HEAD | cut -c1-7
+)
test_expect_success 'modified submodule(backward)' "
git submodule summary >actual &&
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index 13766ab..75388f3 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -22,7 +22,7 @@ esac
test_expect_success \
'initialize git svn' '
mkdir import &&
- cd import &&
+ (cd import &&
echo foo > foo &&
ln -s foo foo.link
mkdir -p dir/a/b/c/d/e &&
@@ -31,8 +31,8 @@ test_expect_success \
echo "zzz" > bar/zzz &&
echo "#!/bin/sh" > exec.sh &&
chmod +x exec.sh &&
- svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null &&
- cd .. &&
+ svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
+ ) &&
rm -rf import &&
git svn init "$svnrepo"'
diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh
index 929499e..f53a1a9 100755
--- a/t/t9101-git-svn-props.sh
+++ b/t/t9101-git-svn-props.sh
@@ -54,7 +54,7 @@ cd ..
rm -rf import
test_expect_success 'checkout working copy from svn' 'svn co "$svnrepo" test_wc'
test_expect_success 'setup some commits to svn' \
- 'cd test_wc &&
+ '(cd test_wc &&
echo Greetings >> kw.c &&
poke kw.c &&
svn_cmd commit -m "Not yet an Id" &&
@@ -63,8 +63,8 @@ test_expect_success 'setup some commits to svn' \
svn_cmd commit -m "Modified file, but still not yet an Id" &&
svn_cmd propset svn:keywords Id kw.c &&
poke kw.c &&
- svn_cmd commit -m "Propset Id" &&
- cd ..'
+ svn_cmd commit -m "Propset Id"
+ )'
test_expect_success 'initialize git svn' 'git svn init "$svnrepo"'
test_expect_success 'fetch revisions from svn' 'git svn fetch'
@@ -82,12 +82,12 @@ got="`sed -ne 2p kw.c`"
test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"
test_expect_success "propset CR on crlf files" \
- 'cd test_wc &&
+ '(cd test_wc &&
svn_cmd propset svn:eol-style CR empty &&
svn_cmd propset svn:eol-style CR crlf &&
svn_cmd propset svn:eol-style CR ne_crlf &&
- svn_cmd commit -m "propset CR on crlf files" &&
- cd ..'
+ svn_cmd commit -m "propset CR on crlf files"
+ )'
test_expect_success 'fetch and pull latest from svn and checkout a new wc' \
'git svn fetch &&
@@ -137,7 +137,7 @@ cat > show-ignore.expect <<\EOF
EOF
test_expect_success 'test show-ignore' "
- cd test_wc &&
+ (cd test_wc &&
mkdir -p deeply/nested/directory &&
touch deeply/nested/directory/.keep &&
svn_cmd add deeply &&
@@ -146,7 +146,7 @@ test_expect_success 'test show-ignore' "
no-such-file*
' .
svn_cmd commit -m 'propset svn:ignore'
- cd .. &&
+ ) &&
git svn show-ignore > show-ignore.got &&
cmp show-ignore.expect show-ignore.got
"
diff --git a/t/t9102-git-svn-deep-rmdir.sh b/t/t9102-git-svn-deep-rmdir.sh
index 028fb19..d60a8ef 100755
--- a/t/t9102-git-svn-deep-rmdir.sh
+++ b/t/t9102-git-svn-deep-rmdir.sh
@@ -4,13 +4,13 @@ test_description='git svn rmdir'
test_expect_success 'initialize repo' '
mkdir import &&
- cd import &&
+ (cd import &&
mkdir -p deeply/nested/directory/number/1 &&
mkdir -p deeply/nested/directory/number/2 &&
echo foo > deeply/nested/directory/number/1/file &&
echo foo > deeply/nested/directory/number/2/another &&
- svn_cmd import -m "import for git svn" . "$svnrepo" &&
- cd ..
+ svn_cmd import -m "import for git svn" . "$svnrepo"
+ )
'
test_expect_success 'mirror via git svn' '
diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh
index bbfd7f4..d2f0e92 100755
--- a/t/t9104-git-svn-follow-parent.sh
+++ b/t/t9104-git-svn-follow-parent.sh
@@ -8,13 +8,13 @@ test_description='git svn fetching'
test_expect_success 'initialize repo' '
mkdir import &&
- cd import &&
+ (cd import &&
mkdir -p trunk &&
echo hello > trunk/readme &&
- svn_cmd import -m "initial" . "$svnrepo" &&
- cd .. &&
+ svn_cmd import -m "initial" . "$svnrepo"
+ ) &&
svn_cmd co "$svnrepo" wc &&
- cd wc &&
+ (cd wc &&
echo world >> trunk/readme &&
poke trunk/readme &&
svn_cmd commit -m "another commit" &&
@@ -22,8 +22,8 @@ test_expect_success 'initialize repo' '
svn_cmd mv trunk thunk &&
echo goodbye >> thunk/readme &&
poke thunk/readme &&
- svn_cmd commit -m "bye now" &&
- cd ..
+ svn_cmd commit -m "bye now"
+ )
'
test_expect_success 'init and fetch a moved directory' '
@@ -85,11 +85,11 @@ test_expect_success 'follow larger parent' '
test_expect_success 'follow higher-level parent' '
svn mkdir -m "follow higher-level parent" "$svnrepo"/blob &&
svn co "$svnrepo"/blob blob &&
- cd blob &&
+ (cd blob &&
echo hi > hi &&
svn add hi &&
- svn commit -m "hihi" &&
- cd ..
+ svn commit -m "hihi"
+ ) &&
svn mkdir -m "new glob at top level" "$svnrepo"/glob &&
svn mv -m "move blob down a level" "$svnrepo"/blob "$svnrepo"/glob/blob &&
git svn init --minimize-url -i blob "$svnrepo"/glob/blob &&
@@ -117,18 +117,18 @@ test_expect_success 'follow-parent avoids deleting relevant info' '
import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
echo "bad delete test 2" > \
import/trunk/subversion/bindings/swig/perl/another-larger &&
- cd import &&
- svn import -m "r9270 test" . "$svnrepo"/r9270 &&
- cd .. &&
+ (cd import &&
+ svn import -m "r9270 test" . "$svnrepo"/r9270
+ ) &&
svn_cmd co "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl r9270 &&
- cd r9270 &&
+ (cd r9270 &&
svn mkdir native &&
svn mv t native/t &&
for i in a b c; do svn mv $i.pm native/$i.pm; done &&
echo z >> native/t/c.t &&
poke native/t/c.t &&
- svn commit -m "reorg test" &&
- cd .. &&
+ svn commit -m "reorg test"
+ ) &&
git svn init --minimize-url -i r9270-t \
"$svnrepo"/r9270/trunk/subversion/bindings/swig/perl/native/t &&
git svn fetch -i r9270-t &&
diff --git a/t/t9105-git-svn-commit-diff.sh b/t/t9105-git-svn-commit-diff.sh
index dd48e9c..d432d83 100755
--- a/t/t9105-git-svn-commit-diff.sh
+++ b/t/t9105-git-svn-commit-diff.sh
@@ -6,10 +6,10 @@ test_description='git svn commit-diff'
test_expect_success 'initialize repo' '
mkdir import &&
- cd import &&
+ (cd import &&
echo hello > readme &&
- svn_cmd import -m "initial" . "$svnrepo" &&
- cd .. &&
+ svn_cmd import -m "initial" . "$svnrepo"
+ ) &&
echo hello > readme &&
git update-index --add readme &&
git commit -a -m "initial" &&
diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh
index 12f21b7..af367a1 100755
--- a/t/t9106-git-svn-commit-diff-clobber.sh
+++ b/t/t9106-git-svn-commit-diff-clobber.sh
@@ -6,21 +6,21 @@ test_description='git svn commit-diff clobber'
test_expect_success 'initialize repo' '
mkdir import &&
- cd import &&
+ (cd import &&
echo initial > file &&
- svn_cmd import -m "initial" . "$svnrepo" &&
- cd .. &&
+ svn_cmd import -m "initial" . "$svnrepo"
+ ) &&
echo initial > file &&
git update-index --add file &&
git commit -a -m "initial"
'
test_expect_success 'commit change from svn side' '
svn_cmd co "$svnrepo" t.svn &&
- cd t.svn &&
+ (cd t.svn &&
echo second line from svn >> file &&
poke file &&
- svn_cmd commit -m "second line from svn" &&
- cd .. &&
+ svn_cmd commit -m "second line from svn"
+ ) &&
rm -rf t.svn
'
@@ -44,11 +44,11 @@ test_expect_success 'dcommit fails to commit because of conflict' '
git svn fetch &&
git reset --hard refs/${remotes_git_svn} &&
svn_cmd co "$svnrepo" t.svn &&
- cd t.svn &&
+ (cd t.svn &&
echo fourth line from svn >> file &&
poke file &&
- svn_cmd commit -m "fourth line from svn" &&
- cd .. &&
+ svn_cmd commit -m "fourth line from svn"
+ ) &&
rm -rf t.svn &&
echo "fourth line from git" >> file &&
git commit -a -m "fourth line from git" &&
@@ -68,11 +68,11 @@ test_expect_success 'dcommit does the svn equivalent of an index merge' "
test_expect_success 'commit another change from svn side' '
svn_cmd co "$svnrepo" t.svn &&
- cd t.svn &&
+ (cd t.svn &&
echo third line from svn >> file &&
poke file &&
- svn_cmd commit -m "third line from svn" &&
- cd .. &&
+ svn_cmd commit -m "third line from svn"
+ ) &&
rm -rf t.svn
'
diff --git a/t/t9107-git-svn-migrate.sh b/t/t9107-git-svn-migrate.sh
index 901b8e0..f60b306 100755
--- a/t/t9107-git-svn-migrate.sh
+++ b/t/t9107-git-svn-migrate.sh
@@ -6,14 +6,14 @@ test_description='git svn metadata migrations from previous versions'
test_expect_success 'setup old-looking metadata' '
cp "$GIT_DIR"/config "$GIT_DIR"/config-old-git-svn &&
mkdir import &&
- cd import &&
+ (cd import &&
for i in trunk branches/a branches/b \
tags/0.1 tags/0.2 tags/0.3; do
mkdir -p $i && \
echo hello >> $i/README || exit 1
done && \
svn_cmd import -m test . "$svnrepo"
- cd .. &&
+ ) &&
git svn init "$svnrepo" &&
git svn fetch &&
rm -rf "$GIT_DIR"/svn &&
diff --git a/t/t9114-git-svn-dcommit-merge.sh b/t/t9114-git-svn-dcommit-merge.sh
index 84f7c9b..a7d0c7d 100755
--- a/t/t9114-git-svn-dcommit-merge.sh
+++ b/t/t9114-git-svn-dcommit-merge.sh
@@ -37,11 +37,11 @@ EOF
test_expect_success 'setup svn repository' '
svn_cmd co "$svnrepo" mysvnwork &&
mkdir -p mysvnwork/trunk &&
- cd mysvnwork &&
+ (cd mysvnwork &&
big_text_block >> trunk/README &&
svn_cmd add trunk &&
- svn_cmd ci -m "first commit" trunk &&
- cd ..
+ svn_cmd ci -m "first commit" trunk
+ )
'
test_expect_success 'setup git mirror and merge' '
diff --git a/t/t9115-git-svn-dcommit-funky-renames.sh b/t/t9115-git-svn-dcommit-funky-renames.sh
index 767799e..9fdbc9b 100755
--- a/t/t9115-git-svn-dcommit-funky-renames.sh
+++ b/t/t9115-git-svn-dcommit-funky-renames.sh
@@ -61,11 +61,11 @@ test_expect_success 'add a file with plus signs' '
test_expect_success 'clone the repository to test rebase' '
git svn clone "$svnrepo" test-rebase &&
- cd test-rebase &&
+ (cd test-rebase &&
echo test-rebase > test-rebase &&
git add test-rebase &&
- git commit -m test-rebase &&
- cd ..
+ git commit -m test-rebase
+ )
'
test_expect_success 'make a commit to test rebase' '
diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh
index 0374a74..244b5cd 100755
--- a/t/t9116-git-svn-log.sh
+++ b/t/t9116-git-svn-log.sh
@@ -8,14 +8,14 @@ test_description='git svn log tests'
test_expect_success 'setup repository and import' '
mkdir import &&
- cd import &&
+ (cd import &&
for i in trunk branches/a branches/b \
tags/0.1 tags/0.2 tags/0.3; do
mkdir -p $i && \
echo hello >> $i/README || exit 1
done && \
svn_cmd import -m test . "$svnrepo"
- cd .. &&
+ ) &&
git svn init "$svnrepo" -T trunk -b branches -t tags &&
git svn fetch &&
git reset --hard trunk &&
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index 5fb94fb..e3f08c4 100755
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -39,27 +39,27 @@ quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
test_expect_success 'setup repository and import' '
mkdir info &&
- cd info &&
+ (cd info &&
echo FIRST > A &&
echo one > file &&
ln -s file symlink-file &&
mkdir directory &&
touch directory/.placeholder &&
ln -s directory symlink-directory &&
- svn_cmd import -m "initial" . "$svnrepo" &&
- cd .. &&
+ svn_cmd import -m "initial" . "$svnrepo"
+ ) &&
svn_cmd co "$svnrepo" svnwc &&
- cd svnwc &&
+ (cd svnwc &&
echo foo > foo &&
svn_cmd add foo &&
svn_cmd commit -m "change outside directory" &&
- svn_cmd update &&
- cd .. &&
+ svn_cmd update
+ ) &&
mkdir gitwc &&
- cd gitwc &&
+ (cd gitwc &&
git svn init "$svnrepo" &&
- git svn fetch &&
- cd .. &&
+ git svn fetch
+ ) &&
ptouch gitwc/file svnwc/file &&
ptouch gitwc/directory svnwc/directory &&
ptouch gitwc/symlink-file svnwc/symlink-file &&
@@ -138,14 +138,14 @@ test_expect_success 'info --url symlink-directory' '
test_expect_success 'info added-file' "
echo two > gitwc/added-file &&
- cd gitwc &&
- git add added-file &&
- cd .. &&
+ (cd gitwc &&
+ git add added-file
+ ) &&
cp gitwc/added-file svnwc/added-file &&
ptouch gitwc/added-file svnwc/added-file &&
- cd svnwc &&
- svn_cmd add added-file > /dev/null &&
- cd .. &&
+ (cd svnwc &&
+ svn_cmd add added-file > /dev/null
+ ) &&
(cd svnwc; svn info added-file) > expected.info-added-file &&
(cd gitwc; git svn info added-file) > actual.info-added-file &&
test_cmp expected.info-added-file actual.info-added-file
@@ -160,12 +160,12 @@ test_expect_success 'info added-directory' "
mkdir gitwc/added-directory svnwc/added-directory &&
ptouch gitwc/added-directory svnwc/added-directory &&
touch gitwc/added-directory/.placeholder &&
- cd svnwc &&
- svn_cmd add added-directory > /dev/null &&
- cd .. &&
- cd gitwc &&
- git add added-directory &&
- cd .. &&
+ (cd svnwc &&
+ svn_cmd add added-directory > /dev/null
+ ) &&
+ (cd gitwc &&
+ git add added-directory
+ ) &&
(cd svnwc; svn info added-directory) \
> expected.info-added-directory &&
(cd gitwc; git svn info added-directory) \
@@ -179,14 +179,14 @@ test_expect_success 'info --url added-directory' '
'
test_expect_success 'info added-symlink-file' "
- cd gitwc &&
+ (cd gitwc &&
ln -s added-file added-symlink-file &&
- git add added-symlink-file &&
- cd .. &&
- cd svnwc &&
+ git add added-symlink-file
+ ) &&
+ (cd svnwc &&
ln -s added-file added-symlink-file &&
- svn_cmd add added-symlink-file > /dev/null &&
- cd .. &&
+ svn_cmd add added-symlink-file > /dev/null
+ ) &&
ptouch gitwc/added-symlink-file svnwc/added-symlink-file &&
(cd svnwc; svn info added-symlink-file) \
> expected.info-added-symlink-file &&
@@ -202,14 +202,14 @@ test_expect_success 'info --url added-symlink-file' '
'
test_expect_success 'info added-symlink-directory' "
- cd gitwc &&
+ (cd gitwc &&
ln -s added-directory added-symlink-directory &&
- git add added-symlink-directory &&
- cd .. &&
- cd svnwc &&
+ git add added-symlink-directory
+ ) &&
+ (cd svnwc &&
ln -s added-directory added-symlink-directory &&
- svn_cmd add added-symlink-directory > /dev/null &&
- cd .. &&
+ svn_cmd add added-symlink-directory > /dev/null
+ ) &&
ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory &&
(cd svnwc; svn info added-symlink-directory) \
> expected.info-added-symlink-directory &&
@@ -230,12 +230,12 @@ test_expect_success 'info --url added-symlink-directory' '
# simply reuses the Last Changed Date.
test_expect_success 'info deleted-file' "
- cd gitwc &&
- git rm -f file > /dev/null &&
- cd .. &&
- cd svnwc &&
- svn_cmd rm --force file > /dev/null &&
- cd .. &&
+ (cd gitwc &&
+ git rm -f file > /dev/null
+ ) &&
+ (cd svnwc &&
+ svn_cmd rm --force file > /dev/null
+ ) &&
(cd svnwc; svn info file) |
sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
> expected.info-deleted-file &&
@@ -251,12 +251,12 @@ test_expect_success 'info --url file (deleted)' '
'
test_expect_success 'info deleted-directory' "
- cd gitwc &&
- git rm -r -f directory > /dev/null &&
- cd .. &&
- cd svnwc &&
- svn_cmd rm --force directory > /dev/null &&
- cd .. &&
+ (cd gitwc &&
+ git rm -r -f directory > /dev/null
+ ) &&
+ (cd svnwc &&
+ svn_cmd rm --force directory > /dev/null
+ ) &&
(cd svnwc; svn info directory) |
sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
> expected.info-deleted-directory &&
@@ -272,12 +272,12 @@ test_expect_success 'info --url directory (deleted)' '
'
test_expect_success 'info deleted-symlink-file' "
- cd gitwc &&
- git rm -f symlink-file > /dev/null &&
- cd .. &&
- cd svnwc &&
- svn_cmd rm --force symlink-file > /dev/null &&
- cd .. &&
+ (cd gitwc &&
+ git rm -f symlink-file > /dev/null
+ ) &&
+ (cd svnwc &&
+ svn_cmd rm --force symlink-file > /dev/null
+ ) &&
(cd svnwc; svn info symlink-file) |
sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
> expected.info-deleted-symlink-file &&
@@ -294,12 +294,12 @@ test_expect_success 'info --url symlink-file (deleted)' '
'
test_expect_success 'info deleted-symlink-directory' "
- cd gitwc &&
- git rm -f symlink-directory > /dev/null &&
- cd .. &&
- cd svnwc &&
- svn_cmd rm --force symlink-directory > /dev/null &&
- cd .. &&
+ (cd gitwc &&
+ git rm -f symlink-directory > /dev/null
+ ) &&
+ (cd svnwc &&
+ svn_cmd rm --force symlink-directory > /dev/null
+ ) &&
(cd svnwc; svn info symlink-directory) |
sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
> expected.info-deleted-symlink-directory &&
@@ -346,9 +346,9 @@ test_expect_success 'info --url unknown-directory' '
'
test_expect_success 'info unknown-symlink-file' "
- cd gitwc &&
- ln -s unknown-file unknown-symlink-file &&
- cd .. &&
+ (cd gitwc &&
+ ln -s unknown-file unknown-symlink-file
+ ) &&
(cd gitwc; test_must_fail git svn info unknown-symlink-file) \
2> actual.info-unknown-symlink-file &&
grep unknown-symlink-file actual.info-unknown-symlink-file
@@ -361,9 +361,9 @@ test_expect_success 'info --url unknown-symlink-file' '
'
test_expect_success 'info unknown-symlink-directory' "
- cd gitwc &&
- ln -s unknown-directory unknown-symlink-directory &&
- cd .. &&
+ (cd gitwc &&
+ ln -s unknown-directory unknown-symlink-directory
+ ) &&
(cd gitwc; test_must_fail git svn info unknown-symlink-directory) \
2> actual.info-unknown-symlink-directory &&
grep unknown-symlink-directory actual.info-unknown-symlink-directory
diff --git a/t/t9120-git-svn-clone-with-percent-escapes.sh b/t/t9120-git-svn-clone-with-percent-escapes.sh
index 9d9ebd5..cddb9d4 100755
--- a/t/t9120-git-svn-clone-with-percent-escapes.sh
+++ b/t/t9120-git-svn-clone-with-percent-escapes.sh
@@ -20,9 +20,9 @@ test_expect_success 'setup svnrepo' '
test_expect_success 'test clone with percent escapes' '
git svn clone "$svnrepo/pr%20ject" clone &&
- cd clone &&
- git rev-parse refs/${remotes_git_svn} &&
- cd ..
+ (cd clone &&
+ git rev-parse refs/${remotes_git_svn}
+ )
'
# SVN works either way, so should we...
diff --git a/t/t9123-git-svn-rebuild-with-rewriteroot.sh b/t/t9123-git-svn-rebuild-with-rewriteroot.sh
index 0455216..0ed90d9 100755
--- a/t/t9123-git-svn-rebuild-with-rewriteroot.sh
+++ b/t/t9123-git-svn-rebuild-with-rewriteroot.sh
@@ -8,10 +8,10 @@ test_description='git svn respects rewriteRoot during rebuild'
. ./lib-git-svn.sh
mkdir import
-cd import
+(cd import
touch foo
svn_cmd import -m 'import for git svn' . "$svnrepo" >/dev/null
-cd ..
+)
rm -rf import
test_expect_success 'init, fetch and checkout repository' '
diff --git a/t/t9125-git-svn-multi-glob-branch-names.sh b/t/t9125-git-svn-multi-glob-branch-names.sh
index c194186..096abd1 100755
--- a/t/t9125-git-svn-multi-glob-branch-names.sh
+++ b/t/t9125-git-svn-multi-glob-branch-names.sh
@@ -19,19 +19,19 @@ test_expect_success 'setup svnrepo' '
test_expect_success 'test clone with multi-glob in branch names' '
git svn clone -T trunk -b branches/*/* -t tags \
"$svnrepo/project" project &&
- cd project &&
+ (cd project &&
git rev-parse "refs/remotes/v14.1/beta" &&
- git rev-parse "refs/remotes/v14.1/gold" &&
- cd ..
+ git rev-parse "refs/remotes/v14.1/gold"
+ )
'
test_expect_success 'test dcommit to multi-globbed branch' "
- cd project &&
+ (cd project &&
git reset --hard 'refs/remotes/v14.1/gold' &&
echo hello >> foo &&
git commit -m 'hello' -- foo &&
- git svn dcommit &&
- cd ..
+ git svn dcommit
+ )
"
test_done
diff --git a/t/t9127-git-svn-partial-rebuild.sh b/t/t9127-git-svn-partial-rebuild.sh
index 4aab8ec..2e4789d 100755
--- a/t/t9127-git-svn-partial-rebuild.sh
+++ b/t/t9127-git-svn-partial-rebuild.sh
@@ -9,27 +9,27 @@ test_description='git svn partial-rebuild tests'
test_expect_success 'initialize svnrepo' '
mkdir import &&
(
- cd import &&
+ (cd import &&
mkdir trunk branches tags &&
- cd trunk &&
- echo foo > foo &&
- cd .. &&
+ (cd trunk &&
+ echo foo > foo
+ ) &&
svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null &&
svn_cmd copy "$svnrepo"/trunk "$svnrepo"/branches/a \
- -m "created branch a" &&
- cd .. &&
+ -m "created branch a"
+ ) &&
rm -rf import &&
svn_cmd co "$svnrepo"/trunk trunk &&
- cd trunk &&
+ (cd trunk &&
echo bar >> foo &&
- svn_cmd ci -m "updated trunk" &&
- cd .. &&
+ svn_cmd ci -m "updated trunk"
+ ) &&
svn_cmd co "$svnrepo"/branches/a a &&
- cd a &&
+ (cd a &&
echo baz >> a &&
svn_cmd add a &&
- svn_cmd ci -m "updated a" &&
- cd .. &&
+ svn_cmd ci -m "updated a"
+ ) &&
git svn init --stdlayout "$svnrepo"
)
'
@@ -41,11 +41,11 @@ test_expect_success 'import an early SVN revision into git' '
test_expect_success 'make full git mirror of SVN' '
mkdir mirror &&
(
- cd mirror &&
+ (cd mirror &&
git init &&
git svn init --stdlayout "$svnrepo" &&
- git svn fetch &&
- cd ..
+ git svn fetch
+ )
)
'
diff --git a/t/t9128-git-svn-cmd-branch.sh b/t/t9128-git-svn-cmd-branch.sh
index 807e494..4b034a6 100755
--- a/t/t9128-git-svn-cmd-branch.sh
+++ b/t/t9128-git-svn-cmd-branch.sh
@@ -9,19 +9,19 @@ test_description='git svn partial-rebuild tests'
test_expect_success 'initialize svnrepo' '
mkdir import &&
(
- cd import &&
+ (cd import &&
mkdir trunk branches tags &&
- cd trunk &&
- echo foo > foo &&
- cd .. &&
- svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null &&
- cd .. &&
+ (cd trunk &&
+ echo foo > foo
+ ) &&
+ svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null
+ ) &&
rm -rf import &&
svn_cmd co "$svnrepo"/trunk trunk &&
- cd trunk &&
+ (cd trunk &&
echo bar >> foo &&
- svn_cmd ci -m "updated trunk" &&
- cd .. &&
+ svn_cmd ci -m "updated trunk"
+ ) &&
rm -rf trunk
)
'
diff --git a/t/t9137-git-svn-dcommit-clobber-series.sh b/t/t9137-git-svn-dcommit-clobber-series.sh
index 636ca0a..d60da63 100755
--- a/t/t9137-git-svn-dcommit-clobber-series.sh
+++ b/t/t9137-git-svn-dcommit-clobber-series.sh
@@ -6,10 +6,10 @@ test_description='git svn dcommit clobber series'
test_expect_success 'initialize repo' '
mkdir import &&
- cd import &&
+ (cd import &&
awk "BEGIN { for (i = 1; i < 64; i++) { print i } }" > file
- svn_cmd import -m "initial" . "$svnrepo" &&
- cd .. &&
+ svn_cmd import -m "initial" . "$svnrepo"
+ ) &&
git svn init "$svnrepo" &&
git svn fetch &&
test -e file
@@ -19,14 +19,14 @@ test_expect_success '(supposedly) non-conflicting change from SVN' '
test x"`sed -n -e 58p < file`" = x58 &&
test x"`sed -n -e 61p < file`" = x61 &&
svn_cmd co "$svnrepo" tmp &&
- cd tmp &&
+ (cd tmp &&
perl -i.bak -p -e "s/^58$/5588/" file &&
perl -i.bak -p -e "s/^61$/6611/" file &&
poke file &&
test x"`sed -n -e 58p < file`" = x5588 &&
test x"`sed -n -e 61p < file`" = x6611 &&
- svn_cmd commit -m "58 => 5588, 61 => 6611" &&
- cd ..
+ svn_cmd commit -m "58 => 5588, 61 => 6611"
+ )
'
test_expect_success 'some unrelated changes to git' "
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 2aeed7b..1a205a4 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -1056,11 +1056,10 @@ test_expect_success \
'P: supermodule & submodule mix' \
'git fast-import <input &&
git checkout subuse1 &&
- rm -rf sub && mkdir sub && cd sub &&
+ rm -rf sub && mkdir sub && (cd sub &&
git init &&
git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
- git checkout master &&
- cd .. &&
+ git checkout master) &&
git submodule init &&
git submodule update'
diff --git a/t/t9401-git-cvsserver-crlf.sh b/t/t9401-git-cvsserver-crlf.sh
index 925bd0f..1bbfd82 100755
--- a/t/t9401-git-cvsserver-crlf.sh
+++ b/t/t9401-git-cvsserver-crlf.sh
@@ -129,21 +129,22 @@ test_expect_success 'cvs co (use attributes)' '
'
test_expect_success 'adding files' '
- cd cvswork/subdir &&
+ (cd cvswork &&
+ (cd subdir &&
echo "more text" > src.c &&
GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
marked_as . src.c "" &&
- echo "psuedo-binary" > temp.bin &&
- cd .. &&
+ echo "psuedo-binary" > temp.bin
+ ) &&
GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
marked_as subdir temp.bin "-kb" &&
cd subdir &&
GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
marked_as . temp.bin "-kb" &&
marked_as . src.c ""
+ )
'
-cd "$WORKDIR"
test_expect_success 'updating' '
git pull gitcvs.git &&
echo 'hi' > subdir/newfile.bin &&
@@ -153,9 +154,9 @@ test_expect_success 'updating' '
git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
git commit -q -m "Add and change some files" &&
git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- cd .. &&
+ (cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update
+ ) &&
marked_as cvswork textfile.c "" &&
marked_as cvswork binfile.bin -kb &&
marked_as cvswork .gitattributes "" &&
@@ -233,35 +234,35 @@ test_expect_success 'cvs co another copy (guess)' '
'
test_expect_success 'add text (guess)' '
- cd cvswork &&
+ (cd cvswork &&
echo "simpleText" > simpleText.c &&
- GIT_CONFIG="$git_config" cvs -Q add simpleText.c &&
- cd .. &&
+ GIT_CONFIG="$git_config" cvs -Q add simpleText.c
+ ) &&
marked_as cvswork simpleText.c ""
'
test_expect_success 'add bin (guess)' '
- cd cvswork &&
+ (cd cvswork &&
echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
- GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin &&
- cd .. &&
+ GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin
+ ) &&
marked_as cvswork simpleBin.bin -kb
'
test_expect_success 'remove files (guess)' '
- cd cvswork &&
+ (cd cvswork &&
GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
- cd subdir &&
- GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin &&
- cd ../.. &&
+ (cd subdir &&
+ GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin
+ )) &&
marked_as cvswork/subdir withCr.bin -kb &&
marked_as cvswork/subdir file.h ""
'
test_expect_success 'cvs ci (guess)' '
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 &&
- cd .. &&
+ (cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1
+ ) &&
marked_as cvswork textfile.c "" &&
marked_as cvswork binfile.bin -kb &&
marked_as cvswork .gitattributes "" &&
@@ -278,9 +279,9 @@ test_expect_success 'cvs ci (guess)' '
'
test_expect_success 'update subdir of other copy (guess)' '
- cd cvswork2/subdir &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- cd ../.. &&
+ (cd cvswork2/subdir &&
+ GIT_CONFIG="$git_config" cvs -Q update
+ ) &&
marked_as cvswork2 textfile.c "" &&
marked_as cvswork2 binfile.bin -kb &&
marked_as cvswork2 .gitattributes "" &&
@@ -304,11 +305,11 @@ test_expect_success 'update/merge full other copy (guess)' '
git add multilineTxt.c &&
git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
git push gitcvs.git >/dev/null &&
- cd cvswork2 &&
+ (cd cvswork2 &&
sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
mv ml.temp multilineTxt.c &&
- GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 &&
- cd .. &&
+ GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1
+ ) &&
marked_as cvswork2 textfile.c "" &&
marked_as cvswork2 binfile.bin -kb &&
marked_as cvswork2 .gitattributes "" &&
diff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh
index 2eff9cd..6ef1c34 100755
--- a/t/t9600-cvsimport.sh
+++ b/t/t9600-cvsimport.sh
@@ -17,7 +17,7 @@ test_expect_success 'setup a cvs module' '
mkdir "$CVSROOT/module" &&
$CVS co -d module-cvs module &&
- cd module-cvs &&
+ (cd module-cvs &&
cat <<EOF >o_fortuna &&
O Fortuna
velut luna
@@ -41,8 +41,8 @@ add "O Fortuna" lyrics
These public domain lyrics make an excellent sample text.
EOF
- $CVS commit -F message &&
- cd ..
+ $CVS commit -F message
+ )
'
test_expect_success 'import a trivial module' '
@@ -52,7 +52,7 @@ test_expect_success 'import a trivial module' '
'
-test_expect_success 'pack refs' 'cd module-git && git gc && cd ..'
+test_expect_success 'pack refs' '(cd module-git && git gc)'
test_expect_success 'initial import has correct .git/cvs-revisions' '
@@ -62,8 +62,7 @@ test_expect_success 'initial import has correct .git/cvs-revisions' '
'
test_expect_success 'update cvs module' '
-
- cd module-cvs &&
+ (cd module-cvs &&
cat <<EOF >o_fortuna &&
O Fortune,
like the moon
@@ -86,16 +85,16 @@ translate to English
My Latin is terrible.
EOF
- $CVS commit -F message &&
- cd ..
+ $CVS commit -F message
+ )
'
test_expect_success 'update git module' '
- cd module-git &&
+ (cd module-git &&
git cvsimport -a -R -z 0 module &&
- git merge origin &&
- cd .. &&
+ git merge origin
+ ) &&
test_cmp module-cvs/o_fortuna module-git/o_fortuna
'
@@ -110,21 +109,20 @@ test_expect_success 'update has correct .git/cvs-revisions' '
test_expect_success 'update cvs module' '
- cd module-cvs &&
+ (cd module-cvs &&
echo 1 >tick &&
$CVS add tick &&
$CVS commit -m 1
- cd ..
-
+ )
'
test_expect_success 'cvsimport.module config works' '
- cd module-git &&
+ (cd module-git &&
git config cvsimport.module module &&
git cvsimport -a -R -z0 &&
- git merge origin &&
- cd .. &&
+ git merge origin
+ ) &&
test_cmp module-cvs/tick module-git/tick
'
@@ -141,12 +139,12 @@ test_expect_success 'second update has correct .git/cvs-revisions' '
test_expect_success 'import from a CVS working tree' '
$CVS co -d import-from-wt module &&
- cd import-from-wt &&
+ (cd import-from-wt &&
git cvsimport -a -z0 &&
echo 1 >expect &&
git log -1 --pretty=format:%s%n >actual &&
- test_cmp actual expect &&
- cd ..
+ test_cmp actual expect
+ )
'
diff --git a/t/t9603-cvsimport-patchsets.sh b/t/t9603-cvsimport-patchsets.sh
index 958bdce..6733f0f 100755
--- a/t/t9603-cvsimport-patchsets.sh
+++ b/t/t9603-cvsimport-patchsets.sh
@@ -20,12 +20,12 @@ export CVSROOT
test_expect_failure 'import with criss cross times on revisions' '
git cvsimport -p"-x" -C module-git module &&
- cd module-git &&
+ (cd module-git &&
git log --pretty=format:%s > ../actual-master &&
git log A~2..A --pretty="format:%s %ad" -- > ../actual-A &&
echo "" >> ../actual-master &&
- echo "" >> ../actual-A &&
- cd .. &&
+ echo "" >> ../actual-A
+ ) &&
echo "Rev 4
Rev 3
Rev 2
--
1.7.3.rc0.181.g885f40
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-06 18:39 [PATCH] Several tests: cd inside subshell instead of around Jens Lehmann
@ 2010-09-06 19:06 ` Jonathan Nieder
2010-09-06 20:12 ` Jens Lehmann
2010-09-06 23:16 ` [PATCH] Several tests: cd inside subshell instead of around Junio C Hamano
1 sibling, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-06 19:06 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List
Jens Lehmann wrote:
> Fixed all places where it was a straightforward change from cd'ing into a
> directory and back via "cd .." to a cd inside a subshell.
Thanks, Jens.
> Found these places with "git grep -w "cd \.\.".
I assume that "sed"-ing out all parentheses would make the diff very
small and readable.
Do you think it would be a bad idea if I send a follow-on patch that
changes code like this:
(cd dir &&
git update-index --add two &&
case "`git ls-files`" in
two) echo pass two ;;
*) echo bad two; exit 1 ;;
esac
) &&
to this:
(
cd dir &&
git update-index --add two &&
case "`git ls-files`" in
two) echo pass two ;;
*) echo bad two; exit 1 ;;
esac
)
It would have the benefit of touching all code in the subshell, so we
could see the effect on "exit" commands and whatnot.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-06 19:06 ` Jonathan Nieder
@ 2010-09-06 20:12 ` Jens Lehmann
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
0 siblings, 1 reply; 27+ messages in thread
From: Jens Lehmann @ 2010-09-06 20:12 UTC (permalink / raw
To: Jonathan Nieder; +Cc: Junio C Hamano, Git Mailing List
Am 06.09.2010 21:06, schrieb Jonathan Nieder:
> Do you think it would be a bad idea if I send a follow-on patch that
> changes code like this:
>
> (cd dir &&
> git update-index --add two &&
> case "`git ls-files`" in
> two) echo pass two ;;
> *) echo bad two; exit 1 ;;
> esac
> ) &&
>
> to this:
>
> (
> cd dir &&
> git update-index --add two &&
> case "`git ls-files`" in
> two) echo pass two ;;
> *) echo bad two; exit 1 ;;
> esac
> )
>
> It would have the benefit of touching all code in the subshell, so we
> could see the effect on "exit" commands and whatnot.
I think that makes a lot of sense. I think you would not only end up
changing the indentation of many subshells (not only those that I
added), you will also have to deal with tests using spaces instead of
tabs for indentation. But these issues have to be addressed anyway ...
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 0/7] Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-06 20:12 ` Jens Lehmann
@ 2010-09-07 1:41 ` Jonathan Nieder
2010-09-07 1:42 ` [PATCH 1/7] tests: subshell indentation stylefix Jonathan Nieder
` (6 more replies)
0 siblings, 7 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:41 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List
Jens Lehmann wrote:
> I think that makes a lot of sense. I think you would not only end up
> changing the indentation of many subshells (not only those that I
> added), you will also have to deal with tests using spaces instead of
> tabs for indentation. But these issues have to be addressed anyway ...
Hmm, it seems there are quite a lot of strange uses of subshells in
tests. I have only started the task you describe. But here are
a couple of patches of that kind.
Patch 1 re-indents the subshells you introduced. I have not checked
that those subshells are all semantically neutral (and in fact some
seem not to be, but I think for the better); in fact, the main goal of
that patch is to help other people review yours.
Patch 2 teaches the fsck tests to use test_when_finished. This
causes some pointless subshells to be removed, and more importantly,
it fixes the cleanup to actually work, so there are no dangling
objects by the end.
Patch 3 adds a missing && in t2105 (.git file pointing to .git dir).
The style cleanup for that file has been done locally but I do not
think it's worth sending yet.
Patch 4 teaches the "unwritable file" error handling tests to use
test_when_finished. This causes some pointless subshells to be
removed, and more importantly, it simplifies the script a lot.
Patch 5 is a style cleanup for the core.repositoryversion tests
(mostly to do with formatting of subshells, but there are other
things).
Patch 6: likewise, for the git config tests.
Patch 7 is perhaps iffy. I find it easier to read
printf "%s\n" some long list of lines
than
(echo some; echo long; echo list; echo of; echo lines)
but others might disagree; anyway, this patch change the latter
to the former (and adds a missing && while at it).
I hope such mundane patches are not too painful to read.
Jonathan Nieder (7):
tests: subshell indentation stylefix
t1450 (fsck): remove dangling objects
t2105 (gitlink): add missing &&
t0004 (core): simplify error handling
t1302 (core.repositoryversion): style tweaks
t1303 (config): style tweaks
t2016 (checkout -p): use printf for multiline y/n input
t/t0004-unwritable.sh | 52 +++-------
t/t1020-subdirectory.sh | 13 ++-
t/t1302-repo-version.sh | 75 +++++++++-----
t/t1303-wacky-config.sh | 28 +++--
t/t1450-fsck.sh | 138 ++++++++++++++----------
t/t2016-checkout-patch.sh | 43 +++++---
t/t2105-update-index-gitfile.sh | 2 +-
t/t3060-ls-files-with-tree.sh | 12 +-
t/t3409-rebase-preserve-merges.sh | 13 ++-
t/t3903-stash.sh | 5 +-
t/t4041-diff-submodule-option.sh | 7 +-
t/t5510-fetch.sh | 35 ++++---
t/t6050-replace.sh | 46 +++++----
t/t7400-submodule-basic.sh | 11 +-
t/t7401-submodule-summary.sh | 7 +-
t/t9100-git-svn-basic.sh | 21 ++--
t/t9101-git-svn-props.sh | 33 ++++---
t/t9102-git-svn-deep-rmdir.sh | 13 ++-
t/t9104-git-svn-follow-parent.sh | 56 ++++++-----
t/t9105-git-svn-commit-diff.sh | 7 +-
t/t9106-git-svn-commit-diff-clobber.sh | 30 +++---
t/t9107-git-svn-migrate.sh | 16 ++--
t/t9114-git-svn-dcommit-merge.sh | 7 +-
t/t9115-git-svn-dcommit-funky-renames.sh | 7 +-
t/t9116-git-svn-log.sh | 16 ++--
t/t9119-git-svn-info.sh | 69 ++++++++-----
t/t9120-git-svn-clone-with-percent-escapes.sh | 3 +-
27 files changed, 433 insertions(+), 332 deletions(-)
--
1.7.2.3
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 1/7] tests: subshell indentation stylefix
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
@ 2010-09-07 1:42 ` Jonathan Nieder
2010-09-07 3:44 ` Jonathan Nieder
2010-09-07 1:47 ` [PATCH 2/7] t1450 (fsck): remove dangling objects Jonathan Nieder
` (5 subsequent siblings)
6 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:42 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List
Format the subshells introduced by the previous patch (Several tests:
cd inside subshell instead of around, 2010-09-06) like so:
(
cd subdir &&
...
) &&
This is generally easier to read and has the nice side-effect that
this patch will show what commands are used in the subshell, making
it easier to check for lost environment variables and similar
behavior changes.
Cc: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t1020-subdirectory.sh | 13 +++--
t/t1302-repo-version.sh | 11 +++-
t/t3060-ls-files-with-tree.sh | 12 ++--
t/t3409-rebase-preserve-merges.sh | 13 +++--
t/t3903-stash.sh | 5 +-
t/t4041-diff-submodule-option.sh | 7 ++-
t/t5510-fetch.sh | 35 +++++++------
t/t6050-replace.sh | 46 +++++++++--------
t/t7400-submodule-basic.sh | 11 ++--
t/t7401-submodule-summary.sh | 7 ++-
t/t9100-git-svn-basic.sh | 21 ++++----
t/t9101-git-svn-props.sh | 33 +++++++-----
t/t9102-git-svn-deep-rmdir.sh | 13 +++--
t/t9104-git-svn-follow-parent.sh | 56 +++++++++++---------
t/t9105-git-svn-commit-diff.sh | 7 ++-
t/t9106-git-svn-commit-diff-clobber.sh | 30 ++++++-----
t/t9107-git-svn-migrate.sh | 16 +++---
t/t9114-git-svn-dcommit-merge.sh | 7 ++-
t/t9115-git-svn-dcommit-funky-renames.sh | 7 ++-
t/t9116-git-svn-log.sh | 16 +++---
t/t9119-git-svn-info.sh | 69 ++++++++++++++++---------
t/t9120-git-svn-clone-with-percent-escapes.sh | 3 +-
22 files changed, 253 insertions(+), 185 deletions(-)
diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index c36157a..0d0da17 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -27,12 +27,13 @@ test_expect_success 'update-index and ls-files' '
one) echo pass one ;;
*) echo bad one; exit 1 ;;
esac &&
- (cd dir &&
- git update-index --add two &&
- case "`git ls-files`" in
- two) echo pass two ;;
- *) echo bad two; exit 1 ;;
- esac
+ (
+ cd dir &&
+ git update-index --add two &&
+ case "`git ls-files`" in
+ two) echo pass two ;;
+ *) echo bad two; exit 1 ;;
+ esac
) &&
case "`git ls-files`" in
dir/two"$LF"one) echo pass both ;;
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index c948719..0da2799 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -33,8 +33,15 @@ test_expect_success 'gitdir selection on unsupported repo' '
test_expect_success 'gitdir not required mode' '
git apply --stat test.patch &&
- (cd test && git apply --stat ../test.patch) &&
- (cd test2 && git apply --stat ../test.patch)'
+ (
+ cd test &&
+ git apply --stat ../test.patch
+ ) &&
+ (
+ cd test2 &&
+ git apply --stat ../test.patch
+ )
+'
test_expect_success 'gitdir required mode on normal repos' '
(git apply --check --index test.patch &&
diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh
index 25afb4f..61c1f53 100755
--- a/t/t3060-ls-files-with-tree.sh
+++ b/t/t3060-ls-files-with-tree.sh
@@ -53,13 +53,13 @@ test_expect_success setup '
git add .
'
-# We have to run from a sub-directory to trigger prune_path
-# Then we finally get to run our --with-tree test
-
test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
-
- (cd sub && git ls-files --with-tree=HEAD~1 >../output)
-
+ # We have to run from a sub-directory to trigger prune_path
+ # Then we finally get to run our --with-tree test
+ (
+ cd sub &&
+ git ls-files --with-tree=HEAD~1 >../output
+ )
'
test_expect_success \
diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh
index 1a362d2..74161a4 100755
--- a/t/t3409-rebase-preserve-merges.sh
+++ b/t/t3409-rebase-preserve-merges.sh
@@ -52,12 +52,13 @@ test_expect_success 'setup for merge-preserving rebase' \
git commit -m "Add different B" &&
git clone ./. clone2 &&
- (cd clone2 &&
- git checkout -b topic origin/topic &&
- test_must_fail git merge origin/master &&
- echo Resolved > B &&
- git add B &&
- git commit -m "Merge origin/master into topic"
+ (
+ cd clone2 &&
+ git checkout -b topic origin/topic &&
+ test_must_fail git merge origin/master &&
+ echo Resolved >B &&
+ git add B &&
+ git commit -m "Merge origin/master into topic"
) &&
git checkout topic &&
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 3f43012..bd4b288 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -69,8 +69,9 @@ test_expect_success 'apply stashed changes (including index)' '
test_expect_success 'unstashing in a subdirectory' '
git reset --hard HEAD &&
mkdir subdir &&
- (cd subdir &&
- git stash apply
+ (
+ cd subdir &&
+ git stash apply
)
'
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index 737c3d9..995bdfa 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -85,9 +85,10 @@ EOF
"
commit_file sm1 &&
-head3=$(cd sm1 &&
-git reset --hard HEAD~2 >/dev/null &&
-git rev-parse --verify HEAD | cut -c1-7
+head3=$(
+ cd sm1 &&
+ git reset --hard HEAD~2 >/dev/null &&
+ git rev-parse --verify HEAD | cut -c1-7
)
test_expect_success 'modified submodule(backward)' "
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 34d59d5..7d1c866 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -21,26 +21,29 @@ test_expect_success setup '
test_expect_success "clone and setup child repos" '
git clone . one &&
- (cd one &&
- echo >file updated by one &&
- git commit -a -m "updated by one"
+ (
+ cd one &&
+ echo >file updated by one &&
+ git commit -a -m "updated by one"
) &&
git clone . two &&
- (cd two &&
- git config branch.master.remote one &&
- git config remote.one.url ../one/.git/ &&
- git config remote.one.fetch refs/heads/master:refs/heads/one
+ (
+ cd two &&
+ git config branch.master.remote one &&
+ git config remote.one.url ../one/.git/ &&
+ git config remote.one.fetch refs/heads/master:refs/heads/one
) &&
git clone . three &&
- (cd three &&
- git config branch.master.remote two &&
- git config branch.master.merge refs/heads/one &&
- mkdir -p .git/remotes &&
- {
- echo "URL: ../two/.git/"
- echo "Pull: refs/heads/master:refs/heads/two"
- echo "Pull: refs/heads/one:refs/heads/one"
- } >.git/remotes/two
+ (
+ cd three &&
+ git config branch.master.remote two &&
+ git config branch.master.merge refs/heads/one &&
+ mkdir -p .git/remotes &&
+ {
+ echo "URL: ../two/.git/"
+ echo "Pull: refs/heads/master:refs/heads/two"
+ echo "Pull: refs/heads/one:refs/heads/one"
+ } >.git/remotes/two
) &&
git clone . bundle &&
git clone . seven
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 01dfa51..f5c3d7f 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -104,16 +104,17 @@ test_expect_success '"git fsck" works' '
test_expect_success 'repack, clone and fetch work' '
git repack -a -d &&
git clone --no-hardlinks . clone_dir &&
- (cd clone_dir &&
- git show HEAD~5 | grep "A U Thor" &&
- git show $HASH2 | grep "A U Thor" &&
- git cat-file commit $R &&
- git repack -a -d &&
- test_must_fail git cat-file commit $R &&
- git fetch ../ "refs/replace/*:refs/replace/*" &&
- git show HEAD~5 | grep "O Thor" &&
- git show $HASH2 | grep "O Thor" &&
- git cat-file commit $R
+ (
+ cd clone_dir &&
+ git show HEAD~5 | grep "A U Thor" &&
+ git show $HASH2 | grep "A U Thor" &&
+ git cat-file commit $R &&
+ git repack -a -d &&
+ test_must_fail git cat-file commit $R &&
+ git fetch ../ "refs/replace/*:refs/replace/*" &&
+ git show HEAD~5 | grep "O Thor" &&
+ git show $HASH2 | grep "O Thor" &&
+ git cat-file commit $R
)
'
@@ -177,9 +178,10 @@ test_expect_success 'create parallel branch without the bug' '
test_expect_success 'push to cloned repo' '
git push cloned $HASH6^:refs/heads/parallel &&
- (cd clone_dir &&
- git checkout parallel &&
- git log --pretty=oneline | grep $PARA2
+ (
+ cd clone_dir &&
+ git checkout parallel &&
+ git log --pretty=oneline | grep $PARA2
)
'
@@ -191,19 +193,21 @@ test_expect_success 'push branch with replacement' '
git show $HASH6~2 | grep "O Thor" &&
git show $PARA3 | grep "O Thor" &&
git push cloned $HASH6^:refs/heads/parallel2 &&
- (cd clone_dir &&
- git checkout parallel2 &&
- git log --pretty=oneline | grep $PARA3 &&
- git show $PARA3 | grep "A U Thor"
+ (
+ cd clone_dir &&
+ git checkout parallel2 &&
+ git log --pretty=oneline | grep $PARA3 &&
+ git show $PARA3 | grep "A U Thor"
)
'
test_expect_success 'fetch branch with replacement' '
git branch tofetch $HASH6 &&
- (cd clone_dir &&
- git fetch origin refs/heads/tofetch:refs/heads/parallel3
- git log --pretty=oneline parallel3 | grep $PARA3
- git show $PARA3 | grep "A U Thor"
+ (
+ cd clone_dir &&
+ git fetch origin refs/heads/tofetch:refs/heads/parallel3
+ git log --pretty=oneline parallel3 | grep $PARA3
+ git show $PARA3 | grep "A U Thor"
)
'
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 21b0839..782b0a3 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -413,11 +413,12 @@ test_expect_success 'submodule <invalid-path> warns' '
test_expect_success 'add submodules without specifying an explicit path' '
mkdir repo &&
- (cd repo &&
- git init &&
- echo r >r &&
- git add r &&
- git commit -m "repo commit 1"
+ (
+ cd repo &&
+ git init &&
+ echo r >r &&
+ git add r &&
+ git commit -m "repo commit 1"
) &&
git clone --bare repo/ bare.git &&
cd addtest &&
diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh
index b5ad45f..2945844 100755
--- a/t/t7401-submodule-summary.sh
+++ b/t/t7401-submodule-summary.sh
@@ -66,9 +66,10 @@ EOF
"
commit_file sm1 &&
-head3=$(cd sm1 &&
-git reset --hard HEAD~2 >/dev/null &&
-git rev-parse --verify HEAD | cut -c1-7
+head3=$(
+ cd sm1 &&
+ git reset --hard HEAD~2 >/dev/null &&
+ git rev-parse --verify HEAD | cut -c1-7
)
test_expect_success 'modified submodule(backward)' "
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index 75388f3..a1e1d27 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -22,16 +22,17 @@ esac
test_expect_success \
'initialize git svn' '
mkdir import &&
- (cd import &&
- echo foo > foo &&
- ln -s foo foo.link
- mkdir -p dir/a/b/c/d/e &&
- echo "deep dir" > dir/a/b/c/d/e/file &&
- mkdir bar &&
- echo "zzz" > bar/zzz &&
- echo "#!/bin/sh" > exec.sh &&
- chmod +x exec.sh &&
- svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
+ (
+ cd import &&
+ echo foo >foo &&
+ ln -s foo foo.link
+ mkdir -p dir/a/b/c/d/e &&
+ echo "deep dir" >dir/a/b/c/d/e/file &&
+ mkdir bar &&
+ echo "zzz" >bar/zzz &&
+ echo "#!/bin/sh" >exec.sh &&
+ chmod +x exec.sh &&
+ svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
) &&
rm -rf import &&
git svn init "$svnrepo"'
diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh
index f53a1a9..8869f50 100755
--- a/t/t9101-git-svn-props.sh
+++ b/t/t9101-git-svn-props.sh
@@ -53,8 +53,9 @@ cd ..
rm -rf import
test_expect_success 'checkout working copy from svn' 'svn co "$svnrepo" test_wc'
-test_expect_success 'setup some commits to svn' \
- '(cd test_wc &&
+test_expect_success 'setup some commits to svn' '
+ (
+ cd test_wc &&
echo Greetings >> kw.c &&
poke kw.c &&
svn_cmd commit -m "Not yet an Id" &&
@@ -64,7 +65,8 @@ test_expect_success 'setup some commits to svn' \
svn_cmd propset svn:keywords Id kw.c &&
poke kw.c &&
svn_cmd commit -m "Propset Id"
- )'
+ )
+'
test_expect_success 'initialize git svn' 'git svn init "$svnrepo"'
test_expect_success 'fetch revisions from svn' 'git svn fetch'
@@ -81,13 +83,15 @@ expect='/* $Id$ */'
got="`sed -ne 2p kw.c`"
test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"
-test_expect_success "propset CR on crlf files" \
- '(cd test_wc &&
+test_expect_success "propset CR on crlf files" '
+ (
+ cd test_wc &&
svn_cmd propset svn:eol-style CR empty &&
svn_cmd propset svn:eol-style CR crlf &&
svn_cmd propset svn:eol-style CR ne_crlf &&
svn_cmd commit -m "propset CR on crlf files"
- )'
+ )
+'
test_expect_success 'fetch and pull latest from svn and checkout a new wc' \
'git svn fetch &&
@@ -137,19 +141,20 @@ cat > show-ignore.expect <<\EOF
EOF
test_expect_success 'test show-ignore' "
- (cd test_wc &&
- mkdir -p deeply/nested/directory &&
- touch deeply/nested/directory/.keep &&
- svn_cmd add deeply &&
- svn_cmd up &&
- svn_cmd propset -R svn:ignore '
+ (
+ cd test_wc &&
+ mkdir -p deeply/nested/directory &&
+ touch deeply/nested/directory/.keep &&
+ svn_cmd add deeply &&
+ svn_cmd up &&
+ svn_cmd propset -R svn:ignore '
no-such-file*
' .
- svn_cmd commit -m 'propset svn:ignore'
+ svn_cmd commit -m 'propset svn:ignore'
) &&
git svn show-ignore > show-ignore.got &&
cmp show-ignore.expect show-ignore.got
- "
+"
cat >create-ignore.expect <<\EOF
/no-such-file*
diff --git a/t/t9102-git-svn-deep-rmdir.sh b/t/t9102-git-svn-deep-rmdir.sh
index d60a8ef..eb70f48 100755
--- a/t/t9102-git-svn-deep-rmdir.sh
+++ b/t/t9102-git-svn-deep-rmdir.sh
@@ -4,12 +4,13 @@ test_description='git svn rmdir'
test_expect_success 'initialize repo' '
mkdir import &&
- (cd import &&
- mkdir -p deeply/nested/directory/number/1 &&
- mkdir -p deeply/nested/directory/number/2 &&
- echo foo > deeply/nested/directory/number/1/file &&
- echo foo > deeply/nested/directory/number/2/another &&
- svn_cmd import -m "import for git svn" . "$svnrepo"
+ (
+ cd import &&
+ mkdir -p deeply/nested/directory/number/1 &&
+ mkdir -p deeply/nested/directory/number/2 &&
+ echo foo >deeply/nested/directory/number/1/file &&
+ echo foo >deeply/nested/directory/number/2/another &&
+ svn_cmd import -m "import for git svn" . "$svnrepo"
)
'
diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh
index d2f0e92..1e5217a 100755
--- a/t/t9104-git-svn-follow-parent.sh
+++ b/t/t9104-git-svn-follow-parent.sh
@@ -8,21 +8,23 @@ test_description='git svn fetching'
test_expect_success 'initialize repo' '
mkdir import &&
- (cd import &&
- mkdir -p trunk &&
- echo hello > trunk/readme &&
- svn_cmd import -m "initial" . "$svnrepo"
+ (
+ cd import &&
+ mkdir -p trunk &&
+ echo hello >trunk/readme &&
+ svn_cmd import -m "initial" . "$svnrepo"
) &&
svn_cmd co "$svnrepo" wc &&
- (cd wc &&
- echo world >> trunk/readme &&
- poke trunk/readme &&
- svn_cmd commit -m "another commit" &&
- svn_cmd up &&
- svn_cmd mv trunk thunk &&
- echo goodbye >> thunk/readme &&
- poke thunk/readme &&
- svn_cmd commit -m "bye now"
+ (
+ cd wc &&
+ echo world >>trunk/readme &&
+ poke trunk/readme &&
+ svn_cmd commit -m "another commit" &&
+ svn_cmd up &&
+ svn_cmd mv trunk thunk &&
+ echo goodbye >>thunk/readme &&
+ poke thunk/readme &&
+ svn_cmd commit -m "bye now"
)
'
@@ -85,11 +87,12 @@ test_expect_success 'follow larger parent' '
test_expect_success 'follow higher-level parent' '
svn mkdir -m "follow higher-level parent" "$svnrepo"/blob &&
svn co "$svnrepo"/blob blob &&
- (cd blob &&
+ (
+ cd blob &&
echo hi > hi &&
svn add hi &&
svn commit -m "hihi"
- ) &&
+ ) &&
svn mkdir -m "new glob at top level" "$svnrepo"/glob &&
svn mv -m "move blob down a level" "$svnrepo"/blob "$svnrepo"/glob/blob &&
git svn init --minimize-url -i blob "$svnrepo"/glob/blob &&
@@ -117,17 +120,22 @@ test_expect_success 'follow-parent avoids deleting relevant info' '
import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
echo "bad delete test 2" > \
import/trunk/subversion/bindings/swig/perl/another-larger &&
- (cd import &&
- svn import -m "r9270 test" . "$svnrepo"/r9270
+ (
+ cd import &&
+ svn import -m "r9270 test" . "$svnrepo"/r9270
) &&
svn_cmd co "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl r9270 &&
- (cd r9270 &&
- svn mkdir native &&
- svn mv t native/t &&
- for i in a b c; do svn mv $i.pm native/$i.pm; done &&
- echo z >> native/t/c.t &&
- poke native/t/c.t &&
- svn commit -m "reorg test"
+ (
+ cd r9270 &&
+ svn mkdir native &&
+ svn mv t native/t &&
+ for i in a b c
+ do
+ svn mv $i.pm native/$i.pm
+ done &&
+ echo z >>native/t/c.t &&
+ poke native/t/c.t &&
+ svn commit -m "reorg test"
) &&
git svn init --minimize-url -i r9270-t \
"$svnrepo"/r9270/trunk/subversion/bindings/swig/perl/native/t &&
diff --git a/t/t9105-git-svn-commit-diff.sh b/t/t9105-git-svn-commit-diff.sh
index d432d83..5d0afea 100755
--- a/t/t9105-git-svn-commit-diff.sh
+++ b/t/t9105-git-svn-commit-diff.sh
@@ -6,9 +6,10 @@ test_description='git svn commit-diff'
test_expect_success 'initialize repo' '
mkdir import &&
- (cd import &&
- echo hello > readme &&
- svn_cmd import -m "initial" . "$svnrepo"
+ (
+ cd import &&
+ echo hello >readme &&
+ svn_cmd import -m "initial" . "$svnrepo"
) &&
echo hello > readme &&
git update-index --add readme &&
diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh
index af367a1..f6d7ac7 100755
--- a/t/t9106-git-svn-commit-diff-clobber.sh
+++ b/t/t9106-git-svn-commit-diff-clobber.sh
@@ -6,9 +6,10 @@ test_description='git svn commit-diff clobber'
test_expect_success 'initialize repo' '
mkdir import &&
- (cd import &&
- echo initial > file &&
- svn_cmd import -m "initial" . "$svnrepo"
+ (
+ cd import &&
+ echo initial >file &&
+ svn_cmd import -m "initial" . "$svnrepo"
) &&
echo initial > file &&
git update-index --add file &&
@@ -16,10 +17,11 @@ test_expect_success 'initialize repo' '
'
test_expect_success 'commit change from svn side' '
svn_cmd co "$svnrepo" t.svn &&
- (cd t.svn &&
- echo second line from svn >> file &&
- poke file &&
- svn_cmd commit -m "second line from svn"
+ (
+ cd t.svn &&
+ echo second line from svn >>file &&
+ poke file &&
+ svn_cmd commit -m "second line from svn"
) &&
rm -rf t.svn
'
@@ -44,10 +46,11 @@ test_expect_success 'dcommit fails to commit because of conflict' '
git svn fetch &&
git reset --hard refs/${remotes_git_svn} &&
svn_cmd co "$svnrepo" t.svn &&
- (cd t.svn &&
- echo fourth line from svn >> file &&
- poke file &&
- svn_cmd commit -m "fourth line from svn"
+ (
+ cd t.svn &&
+ echo fourth line from svn >>file &&
+ poke file &&
+ svn_cmd commit -m "fourth line from svn"
) &&
rm -rf t.svn &&
echo "fourth line from git" >> file &&
@@ -68,8 +71,9 @@ test_expect_success 'dcommit does the svn equivalent of an index merge' "
test_expect_success 'commit another change from svn side' '
svn_cmd co "$svnrepo" t.svn &&
- (cd t.svn &&
- echo third line from svn >> file &&
+ (
+ cd t.svn &&
+ echo third line from svn >>file &&
poke file &&
svn_cmd commit -m "third line from svn"
) &&
diff --git a/t/t9107-git-svn-migrate.sh b/t/t9107-git-svn-migrate.sh
index f60b306..289fc31 100755
--- a/t/t9107-git-svn-migrate.sh
+++ b/t/t9107-git-svn-migrate.sh
@@ -6,14 +6,16 @@ test_description='git svn metadata migrations from previous versions'
test_expect_success 'setup old-looking metadata' '
cp "$GIT_DIR"/config "$GIT_DIR"/config-old-git-svn &&
mkdir import &&
- (cd import &&
- for i in trunk branches/a branches/b \
- tags/0.1 tags/0.2 tags/0.3; do
- mkdir -p $i && \
- echo hello >> $i/README || exit 1
- done && \
+ (
+ cd import &&
+ for i in trunk branches/a branches/b tags/0.1 tags/0.2 tags/0.3
+ do
+ mkdir -p $i &&
+ echo hello >>$i/README ||
+ exit 1
+ done &&
svn_cmd import -m test . "$svnrepo"
- ) &&
+ ) &&
git svn init "$svnrepo" &&
git svn fetch &&
rm -rf "$GIT_DIR"/svn &&
diff --git a/t/t9114-git-svn-dcommit-merge.sh b/t/t9114-git-svn-dcommit-merge.sh
index a7d0c7d..3077851 100755
--- a/t/t9114-git-svn-dcommit-merge.sh
+++ b/t/t9114-git-svn-dcommit-merge.sh
@@ -37,11 +37,12 @@ EOF
test_expect_success 'setup svn repository' '
svn_cmd co "$svnrepo" mysvnwork &&
mkdir -p mysvnwork/trunk &&
- (cd mysvnwork &&
- big_text_block >> trunk/README &&
+ (
+ cd mysvnwork &&
+ big_text_block >>trunk/README &&
svn_cmd add trunk &&
svn_cmd ci -m "first commit" trunk
- )
+ )
'
test_expect_success 'setup git mirror and merge' '
diff --git a/t/t9115-git-svn-dcommit-funky-renames.sh b/t/t9115-git-svn-dcommit-funky-renames.sh
index 9fdbc9b..6a48e40 100755
--- a/t/t9115-git-svn-dcommit-funky-renames.sh
+++ b/t/t9115-git-svn-dcommit-funky-renames.sh
@@ -61,11 +61,12 @@ test_expect_success 'add a file with plus signs' '
test_expect_success 'clone the repository to test rebase' '
git svn clone "$svnrepo" test-rebase &&
- (cd test-rebase &&
- echo test-rebase > test-rebase &&
+ (
+ cd test-rebase &&
+ echo test-rebase >test-rebase &&
git add test-rebase &&
git commit -m test-rebase
- )
+ )
'
test_expect_success 'make a commit to test rebase' '
diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh
index 244b5cd..5d477e4 100755
--- a/t/t9116-git-svn-log.sh
+++ b/t/t9116-git-svn-log.sh
@@ -8,14 +8,16 @@ test_description='git svn log tests'
test_expect_success 'setup repository and import' '
mkdir import &&
- (cd import &&
- for i in trunk branches/a branches/b \
- tags/0.1 tags/0.2 tags/0.3; do
- mkdir -p $i && \
- echo hello >> $i/README || exit 1
- done && \
+ (
+ cd import &&
+ for i in trunk branches/a branches/b tags/0.1 tags/0.2 tags/0.3
+ do
+ mkdir -p $i &&
+ echo hello >>$i/README ||
+ exit 1
+ done &&
svn_cmd import -m test . "$svnrepo"
- ) &&
+ ) &&
git svn init "$svnrepo" -T trunk -b branches -t tags &&
git svn fetch &&
git reset --hard trunk &&
diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh
index e3f08c4..f3f397c 100755
--- a/t/t9119-git-svn-info.sh
+++ b/t/t9119-git-svn-info.sh
@@ -39,9 +39,10 @@ quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
test_expect_success 'setup repository and import' '
mkdir info &&
- (cd info &&
- echo FIRST > A &&
- echo one > file &&
+ (
+ cd info &&
+ echo FIRST >A &&
+ echo one >file &&
ln -s file symlink-file &&
mkdir directory &&
touch directory/.placeholder &&
@@ -49,14 +50,16 @@ test_expect_success 'setup repository and import' '
svn_cmd import -m "initial" . "$svnrepo"
) &&
svn_cmd co "$svnrepo" svnwc &&
- (cd svnwc &&
- echo foo > foo &&
+ (
+ cd svnwc &&
+ echo foo >foo &&
svn_cmd add foo &&
svn_cmd commit -m "change outside directory" &&
svn_cmd update
) &&
mkdir gitwc &&
- (cd gitwc &&
+ (
+ cd gitwc &&
git svn init "$svnrepo" &&
git svn fetch
) &&
@@ -138,12 +141,14 @@ test_expect_success 'info --url symlink-directory' '
test_expect_success 'info added-file' "
echo two > gitwc/added-file &&
- (cd gitwc &&
+ (
+ cd gitwc &&
git add added-file
) &&
cp gitwc/added-file svnwc/added-file &&
ptouch gitwc/added-file svnwc/added-file &&
- (cd svnwc &&
+ (
+ cd svnwc &&
svn_cmd add added-file > /dev/null
) &&
(cd svnwc; svn info added-file) > expected.info-added-file &&
@@ -160,10 +165,12 @@ test_expect_success 'info added-directory' "
mkdir gitwc/added-directory svnwc/added-directory &&
ptouch gitwc/added-directory svnwc/added-directory &&
touch gitwc/added-directory/.placeholder &&
- (cd svnwc &&
+ (
+ cd svnwc &&
svn_cmd add added-directory > /dev/null
) &&
- (cd gitwc &&
+ (
+ cd gitwc &&
git add added-directory
) &&
(cd svnwc; svn info added-directory) \
@@ -179,11 +186,13 @@ test_expect_success 'info --url added-directory' '
'
test_expect_success 'info added-symlink-file' "
- (cd gitwc &&
+ (
+ cd gitwc &&
ln -s added-file added-symlink-file &&
git add added-symlink-file
) &&
- (cd svnwc &&
+ (
+ cd svnwc &&
ln -s added-file added-symlink-file &&
svn_cmd add added-symlink-file > /dev/null
) &&
@@ -202,11 +211,13 @@ test_expect_success 'info --url added-symlink-file' '
'
test_expect_success 'info added-symlink-directory' "
- (cd gitwc &&
+ (
+ cd gitwc &&
ln -s added-directory added-symlink-directory &&
git add added-symlink-directory
) &&
- (cd svnwc &&
+ (
+ cd svnwc &&
ln -s added-directory added-symlink-directory &&
svn_cmd add added-symlink-directory > /dev/null
) &&
@@ -230,10 +241,12 @@ test_expect_success 'info --url added-symlink-directory' '
# simply reuses the Last Changed Date.
test_expect_success 'info deleted-file' "
- (cd gitwc &&
+ (
+ cd gitwc &&
git rm -f file > /dev/null
) &&
- (cd svnwc &&
+ (
+ cd svnwc &&
svn_cmd rm --force file > /dev/null
) &&
(cd svnwc; svn info file) |
@@ -251,10 +264,12 @@ test_expect_success 'info --url file (deleted)' '
'
test_expect_success 'info deleted-directory' "
- (cd gitwc &&
+ (
+ cd gitwc &&
git rm -r -f directory > /dev/null
) &&
- (cd svnwc &&
+ (
+ cd svnwc &&
svn_cmd rm --force directory > /dev/null
) &&
(cd svnwc; svn info directory) |
@@ -272,10 +287,12 @@ test_expect_success 'info --url directory (deleted)' '
'
test_expect_success 'info deleted-symlink-file' "
- (cd gitwc &&
+ (
+ cd gitwc &&
git rm -f symlink-file > /dev/null
) &&
- (cd svnwc &&
+ (
+ cd svnwc &&
svn_cmd rm --force symlink-file > /dev/null
) &&
(cd svnwc; svn info symlink-file) |
@@ -294,10 +311,12 @@ test_expect_success 'info --url symlink-file (deleted)' '
'
test_expect_success 'info deleted-symlink-directory' "
- (cd gitwc &&
+ (
+ cd gitwc &&
git rm -f symlink-directory > /dev/null
) &&
- (cd svnwc &&
+ (
+ cd svnwc &&
svn_cmd rm --force symlink-directory > /dev/null
) &&
(cd svnwc; svn info symlink-directory) |
@@ -346,7 +365,8 @@ test_expect_success 'info --url unknown-directory' '
'
test_expect_success 'info unknown-symlink-file' "
- (cd gitwc &&
+ (
+ cd gitwc &&
ln -s unknown-file unknown-symlink-file
) &&
(cd gitwc; test_must_fail git svn info unknown-symlink-file) \
@@ -361,7 +381,8 @@ test_expect_success 'info --url unknown-symlink-file' '
'
test_expect_success 'info unknown-symlink-directory' "
- (cd gitwc &&
+ (
+ cd gitwc &&
ln -s unknown-directory unknown-symlink-directory
) &&
(cd gitwc; test_must_fail git svn info unknown-symlink-directory) \
diff --git a/t/t9120-git-svn-clone-with-percent-escapes.sh b/t/t9120-git-svn-clone-with-percent-escapes.sh
index cddb9d4..1d92c05 100755
--- a/t/t9120-git-svn-clone-with-percent-escapes.sh
+++ b/t/t9120-git-svn-clone-with-percent-escapes.sh
@@ -20,7 +20,8 @@ test_expect_success 'setup svnrepo' '
test_expect_success 'test clone with percent escapes' '
git svn clone "$svnrepo/pr%20ject" clone &&
- (cd clone &&
+ (
+ cd clone &&
git rev-parse refs/${remotes_git_svn}
)
'
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 1/7] tests: subshell indentation stylefix
2010-09-07 1:42 ` [PATCH 1/7] tests: subshell indentation stylefix Jonathan Nieder
@ 2010-09-07 3:44 ` Jonathan Nieder
0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 3:44 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List
Jonathan Nieder wrote:
> Format the subshells introduced by the previous patch (Several tests:
> cd inside subshell instead of around, 2010-09-06)
Review of said previous patch follows. Sorry for the confusing diffs.
> --- a/t/t1020-subdirectory.sh
> +++ b/t/t1020-subdirectory.sh
> @@ -27,12 +27,13 @@ test_expect_success 'update-index and ls-files' '
> one) echo pass one ;;
> *) echo bad one; exit 1 ;;
> esac &&
> - (cd dir &&
> - git update-index --add two &&
> - case "`git ls-files`" in
> - two) echo pass two ;;
> - *) echo bad two; exit 1 ;;
> - esac
> + (
> + cd dir &&
> + git update-index --add two &&
> + case "`git ls-files`" in
> + two) echo pass two ;;
> + *) echo bad two; exit 1 ;;
> + esac
> ) &&
Trapping the "exit" in a subshell improves behavior. I wonder why the
script does not use "false" or "(exit 1)"; the tests outside the
subshell have the same problem...
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -85,9 +85,10 @@ EOF
> "
>
> commit_file sm1 &&
> -head3=$(cd sm1 &&
> -git reset --hard HEAD~2 >/dev/null &&
> -git rev-parse --verify HEAD | cut -c1-7
> +head3=$(
> + cd sm1 &&
> + git reset --hard HEAD~2 >/dev/null &&
> + git rev-parse --verify HEAD | cut -c1-7
Unrelated: the --verify here does not have much effect on the upstream
of a pipeline. Maybe "git log -1 --abbrev=7 --format=%h", or even
better, "git log -1 --format=%h" (for DEFAULT_ABBREV) would do the
trick.
> --- a/t/t9100-git-svn-basic.sh
> +++ b/t/t9100-git-svn-basic.sh
> @@ -22,16 +22,17 @@ esac
> test_expect_success \
> 'initialize git svn' '
> mkdir import &&
> - (cd import &&
> - echo foo > foo &&
> - ln -s foo foo.link
> - mkdir -p dir/a/b/c/d/e &&
> - echo "deep dir" > dir/a/b/c/d/e/file &&
> - mkdir bar &&
> - echo "zzz" > bar/zzz &&
> - echo "#!/bin/sh" > exec.sh &&
> - chmod +x exec.sh &&
> - svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
> + (
> + cd import &&
> + echo foo >foo &&
> + ln -s foo foo.link
Missing SYMLINKS prerequisite?
> --- a/t/t9107-git-svn-migrate.sh
> +++ b/t/t9107-git-svn-migrate.sh
> @@ -6,14 +6,16 @@ test_description='git svn metadata migrations from previous versions'
> test_expect_success 'setup old-looking metadata' '
> cp "$GIT_DIR"/config "$GIT_DIR"/config-old-git-svn &&
> mkdir import &&
> - (cd import &&
> - for i in trunk branches/a branches/b \
> - tags/0.1 tags/0.2 tags/0.3; do
> - mkdir -p $i && \
> - echo hello >> $i/README || exit 1
> - done && \
> + (
> + cd import &&
> + for i in trunk branches/a branches/b tags/0.1 tags/0.2 tags/0.3
> + do
> + mkdir -p $i &&
> + echo hello >>$i/README ||
> + exit 1
An "exit" to avoid wasting time after a failing setup test might seem
appropriate, but I am happier to see it trapped by the subshell.
> --- a/t/t9116-git-svn-log.sh
> +++ b/t/t9116-git-svn-log.sh
> @@ -8,14 +8,16 @@ test_description='git svn log tests'
>
> test_expect_success 'setup repository and import' '
> mkdir import &&
> - (cd import &&
> - for i in trunk branches/a branches/b \
> - tags/0.1 tags/0.2 tags/0.3; do
> - mkdir -p $i && \
> - echo hello >> $i/README || exit 1
> - done && \
> + (
> + cd import &&
> + for i in trunk branches/a branches/b tags/0.1 tags/0.2 tags/0.3
> + do
> + mkdir -p $i &&
> + echo hello >>$i/README ||
> + exit 1
Likewise.
> --- a/t/t9119-git-svn-info.sh
> +++ b/t/t9119-git-svn-info.sh
> @@ -179,11 +186,13 @@ test_expect_success 'info --url added-directory' '
> '
>
> test_expect_success 'info added-symlink-file' "
> - (cd gitwc &&
> + (
> + cd gitwc &&
> ln -s added-file added-symlink-file &&
> git add added-symlink-file
> ) &&
> - (cd svnwc &&
> + (
> + cd svnwc &&
> ln -s added-file added-symlink-file &&
More missing SYMLINKS prerequisites.
To summarize, wherever you change behavior, it is improved. Thanks.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 2/7] t1450 (fsck): remove dangling objects
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
2010-09-07 1:42 ` [PATCH 1/7] tests: subshell indentation stylefix Jonathan Nieder
@ 2010-09-07 1:47 ` Jonathan Nieder
2010-09-07 1:49 ` [PATCH 3/7] t2105 (gitfile): add missing && Jonathan Nieder
` (4 subsequent siblings)
6 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:47 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List, Thomas Rast
The fsck test is generally careful to remove the corrupt objects
it inserts, but dangling objects are left behind due to some typos
and omissions. It is better to clean up more completely, to
simplify the addition of later tests. So:
- guard setup and cleanup with test_expect_success to catch
typos and errors;
- check both stdout and stderr when checking for empty fsck
output;
- use test_cmp empty file in place of test $(wc -l <file) = 0,
for better debugging output when running tests with -v;
- add a remove_object () helper and use it to replace broken
object removal code that forgot about the fanout in
.git/objects;
- disable gc.auto, to avoid tripping up object removal if the
number of objects ever reaches that threshold.
- use test_when_finished to ensure cleanup tasks are run and
succeed when tests fail;
- add a new final test that no breakage or dangling objects
was left behind.
While at it, add a brief description to test_description of the
history that is expected to persist between tests.
Part of a campaign to clean up subshell usage in tests.
Cc: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t1450-fsck.sh | 140 ++++++++++++++++++++++++++++++++-----------------------
1 files changed, 82 insertions(+), 58 deletions(-)
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 759cf12..1be415e 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -1,21 +1,23 @@
#!/bin/sh
-test_description='git fsck random collection of tests'
+test_description='git fsck random collection of tests
+
+* (HEAD) B
+* (master) A
+'
. ./test-lib.sh
test_expect_success setup '
+ git config gc.auto 0 &&
git config i18n.commitencoding ISO-8859-1 &&
test_commit A fileA one &&
git config --unset i18n.commitencoding &&
git checkout HEAD^0 &&
test_commit B fileB two &&
git tag -d A B &&
- git reflog expire --expire=now --all
-'
-
-test_expect_success 'HEAD is part of refs' '
- test 0 = $(git fsck | wc -l)
+ git reflog expire --expire=now --all &&
+ >empty
'
test_expect_success 'loose objects borrowed from alternate are not missing' '
@@ -25,110 +27,132 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
git init &&
echo ../../../.git/objects >.git/objects/info/alternates &&
test_commit C fileC one &&
- git fsck >out &&
- ! grep "missing blob" out
- )
+ git fsck >../out 2>&1
+ ) &&
+ {
+ grep -v dangling out >actual ||
+ :
+ } &&
+ test_cmp empty actual
'
-test_expect_success 'valid objects appear valid' '
- { git fsck 2>out; true; } &&
- ! grep error out &&
- ! grep fatal out
+test_expect_success 'HEAD is part of refs, valid objects appear valid' '
+ git fsck >actual 2>&1 &&
+ test_cmp empty actual
'
# Corruption tests follow. Make sure to remove all traces of the
# specific corruption you test afterwards, lest a later test trip over
# it.
+test_expect_success 'setup: helpers for corruption tests' '
+ sha1_file() {
+ echo "$*" | sed "s#..#.git/objects/&/#"
+ } &&
+
+ remove_object() {
+ file=$(sha1_file "$*") &&
+ test -e "$file" &&
+ rm -f "$file"
+ }
+'
+
test_expect_success 'object with bad sha1' '
sha=$(echo blob | git hash-object -w --stdin) &&
- echo $sha &&
old=$(echo $sha | sed "s+^..+&/+") &&
new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
sha="$(dirname $new)$(basename $new)"
mv .git/objects/$old .git/objects/$new &&
+ test_when_finished "remove_object $sha" &&
git update-index --add --cacheinfo 100644 $sha foo &&
+ test_when_finished "git read-tree -u --reset HEAD" &&
tree=$(git write-tree) &&
+ test_when_finished "remove_object $tree" &&
cmt=$(echo bogus | git commit-tree $tree) &&
+ test_when_finished "remove_object $cmt" &&
git update-ref refs/heads/bogus $cmt &&
- (git fsck 2>out; true) &&
- grep "$sha.*corrupt" out &&
- rm -f .git/objects/$new &&
- git update-ref -d refs/heads/bogus &&
- git read-tree -u --reset HEAD
+ test_when_finished "git update-ref -d refs/heads/bogus" &&
+
+ test_might_fail git fsck 2>out &&
+ cat out &&
+ grep "$sha.*corrupt" out
'
test_expect_success 'branch pointing to non-commit' '
- git rev-parse HEAD^{tree} > .git/refs/heads/invalid &&
+ git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
+ test_when_finished "git update-ref -d refs/heads/invalid" &&
git fsck 2>out &&
- grep "not a commit" out &&
- git update-ref -d refs/heads/invalid
+ cat out &&
+ grep "not a commit" out
'
-new=nothing
test_expect_success 'email without @ is okay' '
git cat-file commit HEAD >basis &&
sed "s/@/AT/" basis >okay &&
new=$(git hash-object -t commit -w --stdin <okay) &&
- echo "$new" &&
+ test_when_finished "remove_object $new" &&
git update-ref refs/heads/bogus "$new" &&
+ test_when_finished "git update-ref -d refs/heads/bogus" &&
git fsck 2>out &&
cat out &&
- ! grep "error in commit $new" out
+ ! grep "commit $new" out
'
-git update-ref -d refs/heads/bogus
-rm -f ".git/objects/$new"
-new=nothing
test_expect_success 'email with embedded > is not okay' '
git cat-file commit HEAD >basis &&
sed "s/@[a-z]/&>/" basis >bad-email &&
new=$(git hash-object -t commit -w --stdin <bad-email) &&
- echo "$new" &&
+ test_when_finished "remove_object $new" &&
git update-ref refs/heads/bogus "$new" &&
+ test_when_finished "git update-ref -d refs/heads/bogus" &&
git fsck 2>out &&
cat out &&
grep "error in commit $new" out
'
-git update-ref -d refs/heads/bogus
-rm -f ".git/objects/$new"
-
-cat > invalid-tag <<EOF
-object ffffffffffffffffffffffffffffffffffffffff
-type commit
-tag invalid
-tagger T A Gger <tagger@example.com> 1234567890 -0000
-
-This is an invalid tag.
-EOF
test_expect_success 'tag pointing to nonexistent' '
- tag=$(git hash-object -t tag -w --stdin < invalid-tag) &&
- echo $tag > .git/refs/tags/invalid &&
+ cat >invalid-tag <<-\EOF
+ object ffffffffffffffffffffffffffffffffffffffff
+ type commit
+ tag invalid
+ tagger T A Gger <tagger@example.com> 1234567890 -0000
+
+ This is an invalid tag.
+ EOF
+
+ tag=$(git hash-object -t tag -w --stdin <invalid-tag) &&
+ test_when_finished "remove_object $tag" &&
+ echo $tag >.git/refs/tags/invalid &&
+ test_when_finished "git update-ref -d refs/tags/invalid" &&
test_must_fail git fsck --tags >out &&
cat out &&
- grep "broken link" out &&
- rm .git/refs/tags/invalid
+ grep "broken link" out
'
-cat > wrong-tag <<EOF
-object $(echo blob | git hash-object -w --stdin)
-type commit
-tag wrong
-tagger T A Gger <tagger@example.com> 1234567890 -0000
-
-This is an invalid tag.
-EOF
-
test_expect_success 'tag pointing to something else than its type' '
- tag=$(git hash-object -t tag -w --stdin < wrong-tag) &&
- echo $tag > .git/refs/tags/wrong &&
+ sha=$(echo blob | git hash-object -w --stdin) &&
+ test_when_finished "remove_object $sha" &&
+ cat >wrong-tag <<-EOF &&
+ object $sha
+ type commit
+ tag wrong
+ tagger T A Gger <tagger@example.com> 1234567890 -0000
+
+ This is an invalid tag.
+ EOF
+
+ tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
+ test_when_finished "remove_object $tag" &&
+ echo $tag >.git/refs/tags/wrong &&
+ test_when_finished "git update-ref -d refs/tags/wrong" &&
test_must_fail git fsck --tags 2>out &&
cat out &&
- grep "error in tag.*broken links" out &&
- rm .git/refs/tags/wrong
+ grep "error in tag.*broken links" out
'
-
+test_expect_success 'cleaned up' '
+ git fsck >actual 2>&1 &&
+ test_cmp empty actual
+'
test_done
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 3/7] t2105 (gitfile): add missing &&
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
2010-09-07 1:42 ` [PATCH 1/7] tests: subshell indentation stylefix Jonathan Nieder
2010-09-07 1:47 ` [PATCH 2/7] t1450 (fsck): remove dangling objects Jonathan Nieder
@ 2010-09-07 1:49 ` Jonathan Nieder
2010-09-07 12:57 ` Brad King
2010-09-07 1:50 ` [PATCH 4/7] t0004 (unwritable files): simplify error handling Jonathan Nieder
` (3 subsequent siblings)
6 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:49 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List, Brad King
Make sure early failures are not masked by later successes.
Cc: Brad King <brad.king@kitware.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t2105-update-index-gitfile.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t2105-update-index-gitfile.sh b/t/t2105-update-index-gitfile.sh
index 641607d..a7f3d47 100755
--- a/t/t2105-update-index-gitfile.sh
+++ b/t/t2105-update-index-gitfile.sh
@@ -13,7 +13,7 @@ test_expect_success 'submodule with absolute .git file' '
(cd sub1 &&
git init &&
REAL="$(pwd)/.real" &&
- mv .git "$REAL"
+ mv .git "$REAL" &&
echo "gitdir: $REAL" >.git &&
test_commit first)
'
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 3/7] t2105 (gitfile): add missing &&
2010-09-07 1:49 ` [PATCH 3/7] t2105 (gitfile): add missing && Jonathan Nieder
@ 2010-09-07 12:57 ` Brad King
0 siblings, 0 replies; 27+ messages in thread
From: Brad King @ 2010-09-07 12:57 UTC (permalink / raw
To: Jonathan Nieder; +Cc: Jens Lehmann, Junio C Hamano, Git Mailing List
On 09/06/2010 09:49 PM, Jonathan Nieder wrote:
> Make sure early failures are not masked by later successes.
>
> Cc: Brad King <brad.king@kitware.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
An obvious oversight on my part.
Acked-by: Brad King <brad.king@kitware.com>
Thanks,
-Brad
> t/t2105-update-index-gitfile.sh | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/t/t2105-update-index-gitfile.sh b/t/t2105-update-index-gitfile.sh
> index 641607d..a7f3d47 100755
> --- a/t/t2105-update-index-gitfile.sh
> +++ b/t/t2105-update-index-gitfile.sh
> @@ -13,7 +13,7 @@ test_expect_success 'submodule with absolute .git file' '
> (cd sub1 &&
> git init &&
> REAL="$(pwd)/.real" &&
> - mv .git "$REAL"
> + mv .git "$REAL" &&
> echo "gitdir: $REAL" >.git &&
> test_commit first)
> '
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 4/7] t0004 (unwritable files): simplify error handling
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
` (2 preceding siblings ...)
2010-09-07 1:49 ` [PATCH 3/7] t2105 (gitfile): add missing && Jonathan Nieder
@ 2010-09-07 1:50 ` Jonathan Nieder
2010-09-07 1:52 ` [PATCH 5/7] t1302 (core.repositoryversion): style tweaks Jonathan Nieder
` (2 subsequent siblings)
6 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:50 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List
Instead of
... normal test script ...
status=$?
... cleanup ...
(exit $status)
set up cleanup commands with test_when_finished. This makes the
test script a little shorter, and more importantly, it ensures errors
during cleanup are reported.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t0004-unwritable.sh | 52 +++++++++++++-----------------------------------
1 files changed, 14 insertions(+), 38 deletions(-)
diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh
index 2342ac5..3e6a334 100755
--- a/t/t0004-unwritable.sh
+++ b/t/t0004-unwritable.sh
@@ -16,53 +16,29 @@ test_expect_success setup '
'
test_expect_success POSIXPERM 'write-tree should notice unwritable repository' '
-
- (
- chmod a-w .git/objects .git/objects/?? &&
- test_must_fail git write-tree
- )
- status=$?
- chmod 775 .git/objects .git/objects/??
- (exit $status)
-
+ test_when_finished "chmod 775 .git/objects .git/objects/??" &&
+ chmod a-w .git/objects .git/objects/?? &&
+ test_must_fail git write-tree
'
test_expect_success POSIXPERM 'commit should notice unwritable repository' '
-
- (
- chmod a-w .git/objects .git/objects/?? &&
- test_must_fail git commit -m second
- )
- status=$?
- chmod 775 .git/objects .git/objects/??
- (exit $status)
-
+ test_when_finished "chmod 775 .git/objects .git/objects/??" &&
+ chmod a-w .git/objects .git/objects/?? &&
+ test_must_fail git commit -m second
'
test_expect_success POSIXPERM 'update-index should notice unwritable repository' '
-
- (
- echo 6O >file &&
- chmod a-w .git/objects .git/objects/?? &&
- test_must_fail git update-index file
- )
- status=$?
- chmod 775 .git/objects .git/objects/??
- (exit $status)
-
+ test_when_finished "chmod 775 .git/objects .git/objects/??" &&
+ echo 6O >file &&
+ chmod a-w .git/objects .git/objects/?? &&
+ test_must_fail git update-index file
'
test_expect_success POSIXPERM 'add should notice unwritable repository' '
-
- (
- echo b >file &&
- chmod a-w .git/objects .git/objects/?? &&
- test_must_fail git add file
- )
- status=$?
- chmod 775 .git/objects .git/objects/??
- (exit $status)
-
+ test_when_finished "chmod 775 .git/objects .git/objects/??" &&
+ echo b >file &&
+ chmod a-w .git/objects .git/objects/?? &&
+ test_must_fail git add file
'
test_done
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 5/7] t1302 (core.repositoryversion): style tweaks
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
` (3 preceding siblings ...)
2010-09-07 1:50 ` [PATCH 4/7] t0004 (unwritable files): simplify error handling Jonathan Nieder
@ 2010-09-07 1:52 ` Jonathan Nieder
2010-09-07 23:45 ` Nguyen Thai Ngoc Duy
2010-09-07 1:53 ` [PATCH 6/7] t1303 (config): " Jonathan Nieder
2010-09-07 1:55 ` [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input Jonathan Nieder
6 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:52 UTC (permalink / raw
To: Jens Lehmann
Cc: Junio C Hamano, Git Mailing List,
Nguyễn Thái Ngọc Duy
This test is from 2007, which is late enough for the style to be
recognizably modern but still a while ago. Freshen it up to
follow new best practices:
- guard setup commands with test_expect_setup, so errors at
that stage can be caught;
- use <<\EOF in preference to <<EOF, to save reviewers the
trouble of looking for variable interpolations;
- use test_cmp instead of test "$foo" = "$bar", for better
output with -v on failure;
- indent commands in subshells and let them span multiple lines;
- combine the two "gitdir required mode" tests that do not make
as much sense alone.
Cc: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t1302-repo-version.sh | 64 +++++++++++++++++++++++++++++-----------------
1 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index 0da2799..a6bf1bf 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -7,29 +7,41 @@ test_description='Test repository version check'
. ./test-lib.sh
-cat >test.patch <<EOF
-diff --git a/test.txt b/test.txt
-new file mode 100644
---- /dev/null
-+++ b/test.txt
-@@ -0,0 +1 @@
-+123
-EOF
+test_expect_success 'setup' '
+ cat >test.patch <<-\EOF &&
+ diff --git a/test.txt b/test.txt
+ new file mode 100644
+ --- /dev/null
+ +++ b/test.txt
+ @@ -0,0 +1 @@
+ +123
+ EOF
-test_create_repo "test"
-test_create_repo "test2"
-
-GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99 || exit 1
+ test_create_repo "test" &&
+ test_create_repo "test2" &&
+ GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99
+'
test_expect_success 'gitdir selection on normal repos' '
- (test "$(git config core.repositoryformatversion)" = 0 &&
- cd test &&
- test "$(git config core.repositoryformatversion)" = 0)'
+ echo 0 >expect &&
+ git config core.repositoryformatversion >actual &&
+ (
+ cd test &&
+ git config core.repositoryformatversion >../actual2
+ ) &&
+ test_cmp expect actual &&
+ test_cmp expect actual2
+'
-# Make sure it would stop at test2, not trash
test_expect_success 'gitdir selection on unsupported repo' '
- (cd test2 &&
- test "$(git config core.repositoryformatversion)" = 99)'
+ # Make sure it would stop at test2, not trash
+ echo 99 >expect &&
+ (
+ cd test2 &&
+ git config core.repositoryformatversion >../actual
+ )
+ test_cmp expect actual
+'
test_expect_success 'gitdir not required mode' '
git apply --stat test.patch &&
@@ -43,12 +55,16 @@ test_expect_success 'gitdir not required mode' '
)
'
-test_expect_success 'gitdir required mode on normal repos' '
- (git apply --check --index test.patch &&
- cd test && git apply --check --index ../test.patch)'
-
-test_expect_success 'gitdir required mode on unsupported repo' '
- (cd test2 && test_must_fail git apply --check --index ../test.patch)
+test_expect_success 'gitdir required mode' '
+ git apply --check --index test.patch &&
+ (
+ cd test &&
+ git apply --check --index ../test.patch
+ ) &&
+ (
+ cd test2 &&
+ test_must_fail git apply --check --index ../test.patch
+ )
'
test_done
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 5/7] t1302 (core.repositoryversion): style tweaks
2010-09-07 1:52 ` [PATCH 5/7] t1302 (core.repositoryversion): style tweaks Jonathan Nieder
@ 2010-09-07 23:45 ` Nguyen Thai Ngoc Duy
0 siblings, 0 replies; 27+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-09-07 23:45 UTC (permalink / raw
To: Jonathan Nieder; +Cc: Jens Lehmann, Junio C Hamano, Git Mailing List
2010/9/7 Jonathan Nieder <jrnieder@gmail.com>:
> This test is from 2007, which is late enough for the style to be
> recognizably modern but still a while ago. Freshen it up to
> follow new best practices:
>
> - guard setup commands with test_expect_setup, so errors at
> that stage can be caught;
> - use <<\EOF in preference to <<EOF, to save reviewers the
> trouble of looking for variable interpolations;
> - use test_cmp instead of test "$foo" = "$bar", for better
> output with -v on failure;
> - indent commands in subshells and let them span multiple lines;
> - combine the two "gitdir required mode" tests that do not make
> as much sense alone.
>
> Cc: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Looks good to me.
--
Duy
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 6/7] t1303 (config): style tweaks
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
` (4 preceding siblings ...)
2010-09-07 1:52 ` [PATCH 5/7] t1302 (core.repositoryversion): style tweaks Jonathan Nieder
@ 2010-09-07 1:53 ` Jonathan Nieder
2010-09-07 4:30 ` Jeff King
2010-09-07 1:55 ` [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input Jonathan Nieder
6 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:53 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List, Jeff King
This test already has impeccable style, with one exception: there
is an unnecessary use of a subshell. Use a {} block instead.
While at it:
- guard setup commands with test_expect_success, so the commands
are printed when the test is run with "-v" and errors in setup
can be caught;
- use echo instead of printf to print simple text ending with a
newline, so the later use of printf stands out more;
- put a single space before () in function definitions, for
consistency with other shell scripts in git;
- reorder arguments to test_cmp as "test_cmp expected actual".
Cc: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t1303-wacky-config.sh | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh
index 080117c..ce7ce1c 100755
--- a/t/t1303-wacky-config.sh
+++ b/t/t1303-wacky-config.sh
@@ -3,16 +3,20 @@
test_description='Test wacky input to git config'
. ./test-lib.sh
-setup() {
- (printf "[section]\n" &&
- printf " key = foo") >.git/config
-}
-
-check() {
- echo "$2" >expected
- git config --get "$1" >actual 2>&1
- test_cmp actual expected
-}
+test_expect_success 'setup: helper functions' '
+ setup () {
+ {
+ echo "[section]" &&
+ printf " key = foo"
+ } >.git/config
+ } &&
+
+ check () {
+ echo "$2" >expected
+ git config --get "$1" >actual 2>&1
+ test_cmp expected actual
+ }
+'
test_expect_success 'modify same key' '
setup &&
@@ -34,14 +38,14 @@ test_expect_success 'add key in different section' '
check section2.key bar
'
-SECTION="test.q\"s\\sq'sp e.key"
test_expect_success 'make sure git config escapes section names properly' '
+ SECTION="test.q\"s\\sq'\''sp e.key" &&
git config "$SECTION" bar &&
check "$SECTION" bar
'
-LONG_VALUE=$(printf "x%01021dx a" 7)
test_expect_success 'do not crash on special long config line' '
+ LONG_VALUE=$(printf "x%01021dx a" 7) &&
setup &&
git config section.key "$LONG_VALUE" &&
check section.key "fatal: bad config file line 2 in .git/config"
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 6/7] t1303 (config): style tweaks
2010-09-07 1:53 ` [PATCH 6/7] t1303 (config): " Jonathan Nieder
@ 2010-09-07 4:30 ` Jeff King
2010-09-07 4:52 ` Junio C Hamano
2010-09-07 5:12 ` guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks) Jonathan Nieder
0 siblings, 2 replies; 27+ messages in thread
From: Jeff King @ 2010-09-07 4:30 UTC (permalink / raw
To: Jonathan Nieder; +Cc: Jens Lehmann, Junio C Hamano, Git Mailing List
On Mon, Sep 06, 2010 at 08:53:18PM -0500, Jonathan Nieder wrote:
> This test already has impeccable style,
I don't think my style has ever been called impeccable...
> with one exception: there is an unnecessary use of a subshell. Use a
> {} block instead.
OK. Does this actually matter for anything? I know Windows has slow
fork, but I doubt it is measurable here.
> While at it:
>
> - guard setup commands with test_expect_success, so the commands
> are printed when the test is run with "-v" and errors in setup
> can be caught;
This confuses me. The setup is _already_ run inside test_expect_success.
It is only the shell function definitions you are moving inside. Do we
really care about this? If so, aren't there a zillion other places where
we define shell functions in test scripts? Try "git grep
'^[a-z][a-z]* *('".
You do move some variable definitions inside, too,, but IMO you are
making at least one of them less readable, because you have to deal with
the extra quoting layer of test_expect_success. IOW:
> -SECTION="test.q\"s\\sq'sp e.key"
> test_expect_success 'make sure git config escapes section names properly' '
> + SECTION="test.q\"s\\sq'\''sp e.key" &&
seems like a net loss to me.
> - use echo instead of printf to print simple text ending with a
> newline, so the later use of printf stands out more;
No complaint here.
> - put a single space before () in function definitions, for
> consistency with other shell scripts in git;
Again, I am not sure we care, but if we do, there are a ton of other
places: git grep '^[a-z][a-z]*('.
> - reorder arguments to test_cmp as "test_cmp expected actual".
Yeah, I prefer it as "test_cmp expected actual". I'm surprised I ever
wrote it the other way (actually, I think it is because my writing
predates test_cmp, even).
So I dunno. Most of it I am fine with, though I question whether it is
really worth the effort. But I really don't want to be too draconian
about "everything must go into test_expect_success". Sure, if you are
executing commands that might have output, or might be of interest to
the user, put them there. But I find this a lot more readable:
cat >expect <<'EOF'
... some expected output ...
EOF
test_expect_success 'frob it' '
git frob &&
test_cmp expect actual
'
than:
test_expect_success 'frob it' '
cat >expect <<"EOF" &&
... some expected output ...
EOF
git frob &&
test_cmp expect actual
'
-Peff
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 6/7] t1303 (config): style tweaks
2010-09-07 4:30 ` Jeff King
@ 2010-09-07 4:52 ` Junio C Hamano
2010-09-07 5:27 ` Jonathan Nieder
2010-09-07 5:12 ` guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks) Jonathan Nieder
1 sibling, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2010-09-07 4:52 UTC (permalink / raw
To: Jeff King; +Cc: Jonathan Nieder, Jens Lehmann, Git Mailing List
Jeff King <peff@peff.net> writes:
> ... But I really don't want to be too draconian
> about "everything must go into test_expect_success". Sure, if you are
> executing commands that might have output, or might be of interest to
> the user, put them there. But I find this a lot more readable:
>
> cat >expect <<'EOF'
> ... some expected output ...
> EOF
> test_expect_success 'frob it' '
> git frob &&
> test_cmp expect actual
> '
>
> than:
>
> test_expect_success 'frob it' '
> cat >expect <<"EOF" &&
> ... some expected output ...
> EOF
> git frob &&
> test_cmp expect actual
> '
I agree.
My gut feeling has been that any set-up that uses "git" should never be
outside test_expect_success, but things like cat <<HERE / echo to prepare
test vector are not expected to fail (we are not in the business of
testing the build platform) and can be at the top of the script between
the inclusion of test-lib.sh and the first test_expect_success.
When you throw in tools that are platform dependent to the mix, however,
things get muddier. Setup that use stuff like "ln -s this that" and
"setacl" is easier to handle inside test_expect_success guarded by an
appropriate prerequisite. So even that "anything git should be inside,
everything else can go outside if it wants to" rule of thumb is not so
black and white.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 6/7] t1303 (config): style tweaks
2010-09-07 4:52 ` Junio C Hamano
@ 2010-09-07 5:27 ` Jonathan Nieder
0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 5:27 UTC (permalink / raw
To: Junio C Hamano
Cc: Jeff King, Jens Lehmann, Git Mailing List,
Ævar Arnfjörð Bjarmason
Junio C Hamano wrote:
> My gut feeling has been that any set-up that uses "git" should never be
> outside test_expect_success, but things like cat <<HERE / echo to prepare
> test vector are not expected to fail (we are not in the business of
> testing the build platform) and can be at the top of the script between
> the inclusion of test-lib.sh and the first test_expect_success.
Such a strategy sounds fine to me, for what it's worth.
(so:
test_description=...
. ./test-lib.sh
cat
...
mkdir
cat
...
cat
...
test_expect_success
...
test_expect_success
...
test_expect_failure
...
test_expect_success
...
test_done
)
^ permalink raw reply [flat|nested] 27+ messages in thread
* guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)
2010-09-07 4:30 ` Jeff King
2010-09-07 4:52 ` Junio C Hamano
@ 2010-09-07 5:12 ` Jonathan Nieder
2010-09-07 5:56 ` Jeff King
1 sibling, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 5:12 UTC (permalink / raw
To: Jeff King
Cc: Jens Lehmann, Junio C Hamano, Git Mailing List,
Ævar Arnfjörð Bjarmason
(+cc: Ævar in case he is interested)
Hi,
Jeff King wrote:
> So I dunno. Most of it I am fine with, though I question whether it is
> really worth the effort. But I really don't want to be too draconian
> about "everything must go into test_expect_success".
Thanks for the comments; that is very useful. I'm sure you won't
be surprised to hear that that is a part I am more attached to than
the () vs {}, say. I think I did not explain it well.
As you mentioned, it is a big departure from the style of the existing
tests. So why push it? A quick story:
1. Long ago, when I first debugged a test script with -v, I was a bit
confused because the transcript did not tell the whole story
(because some commands are run outside test assertions). No big
deal, but I remembered it.
2. Sometimes the setup commands outside of test scripts produce
output. This is annoying, so people silence it.
3. Sometimes the setup commands outside of test scripts are broken.
Tests do not use "set -e" or check for errors outside of test
assertions, so simple typos can go undetected for a long time.
4. What actually provoked me to care about it: when trying to add a
test to t9301-fast-import.sh, say, I found myself completely lost.
It is really hard to figure out what the state is supposed to be
at a particular point in the test script. Sometimes I am tempted
to write a new test script when adding a new behavior, only
because I do not understand the existing one on a topic. All the
tests can be well-behaved and follow sane invariants, but that
does not matter, because the invariants are not documented anywhere.
How to fix that? I would like to see tests look roughly like this:
test_description='description of purpose
description of state maintained between tests
'
. ./test-lib.sh
test_expect_success 'setup' '
...
'
test_expect_success 'some good thing holds' '
... commands that do not break global state ...
'
test_expect_success 'another good thing holds' '
... more peaceful test commands ...
'
test_expect_success 'setup: update global state somehow' '
...
'
...
test_done
Some of my other puzzling patches (test_might_fail, test_when_finished)
are also meant for this purpose. Of course, it will take a while.
The result would be:
- test commands all shown with "-v", output all suppressed without;
- all commands pass at least the sanity check of exiting with 0
status;
- easy to write a GIT_SKIP_TESTS specification. Would be possible
to add the ability to try a single test (plus all setup tests in
that script that precede it);
- as long as all the setup tests pass, the list of failed tests
from a test failure can be more informative;
- state can be tracked by just reading the setup tests.
> Sure, if you are
> executing commands that might have output, or might be of interest to
> the user, put them there. But I find this a lot more readable:
>
> cat >expect <<'EOF'
> ... some expected output ...
> EOF
> test_expect_success 'frob it' '
I don't know: I think
cat >expect <<-\EOF &&
...
EOF
is pretty readable. The problem with sticking to
cat >expect <<\EOF
...
EOF
is that once someone wants to include a commit id, they change
it to
cat >expect <<EOF
... $(git rev-parse ... )
...
EOF
and we have nontrivial code outside the test now.
On the other hand:
> , but IMO you are
> making at least one of them less readable, because you have to deal with
> the extra quoting layer of test_expect_success. IOW:
>
>> -SECTION="test.q\"s\\sq'sp e.key"
>> test_expect_success 'make sure git config escapes section names properly' '
>> + SECTION="test.q\"s\\sq'\''sp e.key" &&
>
> seems like a net loss to me.
I wholeheartedly agree, and maybe I should have done
apos="'\''" &&
SECTION="test.q\"s\\sq${apos}sp e.key" &&
or something; this detail of quoting has never brought much happiness
to me.
Sorry for the ramble. Thoughts welcome.
Jonathan
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)
2010-09-07 5:12 ` guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks) Jonathan Nieder
@ 2010-09-07 5:56 ` Jeff King
2010-09-07 6:12 ` Jonathan Nieder
0 siblings, 1 reply; 27+ messages in thread
From: Jeff King @ 2010-09-07 5:56 UTC (permalink / raw
To: Jonathan Nieder
Cc: Jens Lehmann, Junio C Hamano, Git Mailing List,
Ævar Arnfjörð Bjarmason
On Tue, Sep 07, 2010 at 12:12:18AM -0500, Jonathan Nieder wrote:
> As you mentioned, it is a big departure from the style of the existing
> tests. So why push it? A quick story:
>
> 1. Long ago, when I first debugged a test script with -v, I was a bit
> confused because the transcript did not tell the whole story
> (because some commands are run outside test assertions). No big
> deal, but I remembered it.
Yeah, that can be frustrating. However, I have found (as I think you
have, from your point 4 below) that it is not just about seeing the
whole story with "-v", but rather about reaching some state in the test
script which may depend on prior tests. So yes, if everything were in
"-v", you could in theory cut and paste it all into a terminal. But
would you necessarily _want_ to, if it is test 25 in the script?
What I often end up doing is sticking "&& bash" into the test, running
the script, and exploring from that state. Perhaps we could have more
support for that. E.g., something like:
$ ./t1303-wacky-config.sh --debug=2
expecting success:
setup &&
git config section.key bar &&
check section.key bar
ok 1 - modify same key
entering debug session for test 2; test text is:
setup &&
git config section2.key bar &&
check section.key foo &&
check section2.key bar
$ [now try running commands]
The obvious problem is that you're actually in a subshell, not the same
shell. We would probably want to do some behind-the-scenes magic to
import variables and functions from the parent shell (unless you can
think of a clever way to suddenly turn the existing shell interactive).
> 2. Sometimes the setup commands outside of test scripts produce
> output. This is annoying, so people silence it.
Yeah, it is annoying. And I am totally in favor of things that might
produce output going into test_expect_success blocks. And...
> 3. Sometimes the setup commands outside of test scripts are broken.
> Tests do not use "set -e" or check for errors outside of test
> assertions, so simple typos can go undetected for a long time.
I agree here. And I'm totally in favor of things that might fail going
into test_expect_success blocks. I don't consider running "printf", or
dumping a here-document into a file via cat to be likely to fail.
> 4. What actually provoked me to care about it: when trying to add a
> test to t9301-fast-import.sh, say, I found myself completely lost.
> It is really hard to figure out what the state is supposed to be
> at a particular point in the test script. Sometimes I am tempted
> to write a new test script when adding a new behavior, only
> because I do not understand the existing one on a topic. All the
> tests can be well-behaved and follow sane invariants, but that
> does not matter, because the invariants are not documented anywhere.
To some degree, I addressed this above. But yeah, even with a nice
drop-to-shell debug support, undocumented invariants are going to be a
pain when debugging a test. But I don't think moving them into a
test_expect_success block is going to help that. The problem is subtle
state changes of the test directory.
Things like test_when_finished help with that, and I hope people will
use them. But I fear that tests will always suffer from being somewhat
messier than actual code, and will always be written in a bit of a
procedural fashion. That is, I don't think we will ever achieve a level
of modularity and orthogonality in writing tests that would mean you
could just run some tests in isolation. It's just not worth the effort
most of the time.
Still, I encourage you to try to push in that direction by leading by
example. You obviously have some ideas. My only real complaint about
your patch was that I find the syntax uglier. And your suggestions are
not alone in that. We have tons of ugly quoting because of the need to
double-quote in test_expect_success. Perhaps we could refactor it into a
set of two functions that keep state? E.g., something like:
test_start 'setup'
cat >expect <<EOF
... whatever ...
EOF
test_end success
test_start 'description'
git frob >actual &&
test_cmp expect actual
test_end success
where test_start would set up >&3 and >&4 as usual, and test_end would
check $? and report the status. The biggest problem I see is that we
never have the actual shell script snippet as a string, so we don't have
a way of printing it for "-v" (or on failure). Hmm.
> The result would be:
>
> - test commands all shown with "-v", output all suppressed without;
> - all commands pass at least the sanity check of exiting with 0
> status;
> - easy to write a GIT_SKIP_TESTS specification. Would be possible
> to add the ability to try a single test (plus all setup tests in
> that script that precede it);
> - as long as all the setup tests pass, the list of failed tests
> from a test failure can be more informative;
> - state can be tracked by just reading the setup tests.
Again, I think these are great goals. I'm not sure we will ever reach
them, or whether we will find the work that goes into them to be worth
the effort (especially because it is so easy to break these properties
with new tests, and there is not a good test harness for testing how
well you have written your tests).
> I don't know: I think
>
> cat >expect <<-\EOF &&
> ...
> EOF
>
> is pretty readable. The problem with sticking to
Yeah, I almost mentioned that, but for some reason in the back of my
mind <<- is not actually portable. Perhaps I am just thinking of the
fact that perl does not support it.
-Peff
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)
2010-09-07 5:56 ` Jeff King
@ 2010-09-07 6:12 ` Jonathan Nieder
0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 6:12 UTC (permalink / raw
To: Jeff King
Cc: Jens Lehmann, Junio C Hamano, Git Mailing List,
Ævar Arnfjörð Bjarmason
Jeff King wrote:
> Perhaps we could refactor it into a
> set of two functions that keep state? E.g., something like:
>
> test_start 'setup'
> cat >expect <<EOF
> ... whatever ...
> EOF
> test_end success
>
> test_start 'description'
> git frob >actual &&
> test_cmp expect actual
> test_end success
>
> where test_start would set up >&3 and >&4 as usual, and test_end would
> check $? and report the status. The biggest problem I see is that we
> never have the actual shell script snippet as a string, so we don't have
> a way of printing it for "-v" (or on failure). Hmm.
FWIW I don't mind this idea (to be used as an alternative to
test_expect_success when quoting issues get ugly). Maybe the harness
could fetch the snippet by parsing $0? (Sorry, couldn't resist.
Something simpler might be possible: e.g., a special
test_expect_success 'description' - <<\test_end
cat >expect <<EOF
... whatever ...
EOF
test_end
syntax.)
>> I don't know: I think
>>
>> cat >expect <<-\EOF &&
>> ...
>> EOF
>>
>> is pretty readable. The problem with sticking to
>
> Yeah, I almost mentioned that, but for some reason in the back of my
> mind <<- is not actually portable. Perhaps I am just thinking of the
> fact that perl does not support it.
I seem to remember some language where the here documents would snip
some well determined constant amount of whitespace from the enclosed
lines. Unfortunately in the shell, that is not the rule: <<- just
trims out all the leading tabs.
So when expected output includes leading tabs, it is ugly again.
q_to_tab <<-\EOF
Like this:
Q1. indented line
Q2. second indented line
EOF
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
` (5 preceding siblings ...)
2010-09-07 1:53 ` [PATCH 6/7] t1303 (config): " Jonathan Nieder
@ 2010-09-07 1:55 ` Jonathan Nieder
2010-09-07 8:06 ` Thomas Rast
6 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 1:55 UTC (permalink / raw
To: Jens Lehmann; +Cc: Junio C Hamano, Git Mailing List, Thomas Rast
Instead of
(echo y; echo n; echo n) | git checkout -p HEAD^ -- dir
write
printf "%s\n" y n n |
git checkout -p HEAD^ -- dir
which means the same thing but might be easier to read.
While at it, add a missing && to the "git checkout -p HEAD with change
already staged" test.
Cc: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t2016-checkout-patch.sh | 43 +++++++++++++++++++++++++++++--------------
1 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh
index 2144184..8cb7f46 100755
--- a/t/t2016-checkout-patch.sh
+++ b/t/t2016-checkout-patch.sh
@@ -20,48 +20,55 @@ test_expect_success 'setup' '
test_expect_success 'saying "n" does nothing' '
set_and_save_state dir/foo work head &&
- (echo n; echo n) | git checkout -p &&
+ printf "%s\n" n n |
+ git checkout -p &&
verify_saved_state bar &&
verify_saved_state dir/foo
'
test_expect_success 'git checkout -p' '
- (echo n; echo y) | git checkout -p &&
+ printf "%s\n" n y |
+ git checkout -p &&
verify_saved_state bar &&
verify_state dir/foo head head
'
test_expect_success 'git checkout -p with staged changes' '
- set_state dir/foo work index
- (echo n; echo y) | git checkout -p &&
+ set_state dir/foo work index &&
+ printf "%s\n" n y |
+ git checkout -p &&
verify_saved_state bar &&
verify_state dir/foo index index
'
test_expect_success 'git checkout -p HEAD with NO staged changes: abort' '
set_and_save_state dir/foo work head &&
- (echo n; echo y; echo n) | git checkout -p HEAD &&
+ printf "%s\n" n y n |
+ git checkout -p HEAD &&
verify_saved_state bar &&
verify_saved_state dir/foo
'
test_expect_success 'git checkout -p HEAD with NO staged changes: apply' '
- (echo n; echo y; echo y) | git checkout -p HEAD &&
+ printf "%s\n" n y y |
+ git checkout -p HEAD &&
verify_saved_state bar &&
verify_state dir/foo head head
'
test_expect_success 'git checkout -p HEAD with change already staged' '
- set_state dir/foo index index
+ set_state dir/foo index index &&
# the third n is to get out in case it mistakenly does not apply
- (echo n; echo y; echo n) | git checkout -p HEAD &&
+ printf "%s\n" n y n |
+ git checkout -p HEAD &&
verify_saved_state bar &&
verify_state dir/foo head head
'
test_expect_success 'git checkout -p HEAD^' '
# the third n is to get out in case it mistakenly does not apply
- (echo n; echo y; echo n) | git checkout -p HEAD^ &&
+ printf "%s\n" n y n |
+ git checkout -p HEAD^ &&
verify_saved_state bar &&
verify_state dir/foo parent parent
'
@@ -69,7 +76,8 @@ test_expect_success 'git checkout -p HEAD^' '
test_expect_success 'git checkout -p handles deletion' '
set_state dir/foo work index &&
rm dir/foo &&
- (echo n; echo y) | git checkout -p &&
+ printf "%s\n" n y |
+ git checkout -p &&
verify_saved_state bar &&
verify_state dir/foo index index
'
@@ -81,21 +89,24 @@ test_expect_success 'git checkout -p handles deletion' '
test_expect_success 'path limiting works: dir' '
set_state dir/foo work head &&
- (echo y; echo n) | git checkout -p dir &&
+ printf "%s\n" y n |
+ git checkout -p dir &&
verify_saved_state bar &&
verify_state dir/foo head head
'
test_expect_success 'path limiting works: -- dir' '
set_state dir/foo work head &&
- (echo y; echo n) | git checkout -p -- dir &&
+ printf "%s\n" y n |
+ git checkout -p -- dir &&
verify_saved_state bar &&
verify_state dir/foo head head
'
test_expect_success 'path limiting works: HEAD^ -- dir' '
# the third n is to get out in case it mistakenly does not apply
- (echo y; echo n; echo n) | git checkout -p HEAD^ -- dir &&
+ printf "%s\n" y n n |
+ git checkout -p HEAD^ -- dir &&
verify_saved_state bar &&
verify_state dir/foo parent parent
'
@@ -103,7 +114,11 @@ test_expect_success 'path limiting works: HEAD^ -- dir' '
test_expect_success 'path limiting works: foo inside dir' '
set_state dir/foo work head &&
# the third n is to get out in case it mistakenly does not apply
- (echo y; echo n; echo n) | (cd dir && git checkout -p foo) &&
+ printf "%s\n" y n n |
+ (
+ cd dir &&
+ git checkout -p foo
+ ) &&
verify_saved_state bar &&
verify_state dir/foo head head
'
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input
2010-09-07 1:55 ` [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input Jonathan Nieder
@ 2010-09-07 8:06 ` Thomas Rast
2010-09-07 8:22 ` Jonathan Nieder
0 siblings, 1 reply; 27+ messages in thread
From: Thomas Rast @ 2010-09-07 8:06 UTC (permalink / raw
To: Jonathan Nieder; +Cc: Jens Lehmann, Junio C Hamano, Git Mailing List
Jonathan Nieder wrote:
> Instead of
>
> (echo y; echo n; echo n) | git checkout -p HEAD^ -- dir
>
> write
>
> printf "%s\n" y n n |
> git checkout -p HEAD^ -- dir
>
> which means the same thing but might be easier to read.
I'm indifferent about this. It does save a process, but (maybe that's
just me though) I had to look up a POSIX manpage to verify that the
repeating behaviour is guaranteed.
> While at it, add a missing && to the "git checkout -p HEAD with change
> already staged" test.
Good catch.
--
Thomas Rast
trast@{inf,student}.ethz.ch
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input
2010-09-07 8:06 ` Thomas Rast
@ 2010-09-07 8:22 ` Jonathan Nieder
0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 8:22 UTC (permalink / raw
To: Thomas Rast; +Cc: Jens Lehmann, Junio C Hamano, Git Mailing List
Thomas Rast wrote:
> I'm indifferent about this. It does save a process, but (maybe that's
> just me though) I had to look up a POSIX manpage to verify that the
> repeating behaviour is guaranteed.
If saving a process is the only benefit, let's forget it.
>> While at it, add a missing && to the "git checkout -p HEAD with change
>> already staged" test.
>
> Good catch.
Here's a patch with just that.
-- 8< --
Subject: t2016 (checkout -p): add missing &&
Although the set_state command is not likely to fail, it is best to
stay in the habit of checking for failures.
Cc: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t2016-checkout-patch.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh
index 7657ec1..a463b13 100755
--- a/t/t2016-checkout-patch.sh
+++ b/t/t2016-checkout-patch.sh
@@ -52,7 +52,7 @@ test_expect_success PERL 'git checkout -p HEAD with NO staged changes: apply' '
'
test_expect_success PERL 'git checkout -p HEAD with change already staged' '
- set_state dir/foo index index
+ set_state dir/foo index index &&
# the third n is to get out in case it mistakenly does not apply
(echo n; echo y; echo n) | git checkout -p HEAD &&
verify_saved_state bar &&
--
1.7.2.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-06 18:39 [PATCH] Several tests: cd inside subshell instead of around Jens Lehmann
2010-09-06 19:06 ` Jonathan Nieder
@ 2010-09-06 23:16 ` Junio C Hamano
2010-09-07 2:37 ` Jonathan Nieder
2010-09-07 10:29 ` [PATCH] t1020: Get rid of 'cd "$HERE"' at the start of each test Jens Lehmann
1 sibling, 2 replies; 27+ messages in thread
From: Junio C Hamano @ 2010-09-06 23:16 UTC (permalink / raw
To: Jens Lehmann; +Cc: Git Mailing List
Jens Lehmann <Jens.Lehmann@web.de> writes:
> Fixed all places where it was a straightforward change from cd'ing into a
> directory and back via "cd .." to a cd inside a subshell.
>
> Found these places with "git grep -w "cd \.\.".
>
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> ---
Thanks; that is a huge effort of cleaning things up.
> diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
> index 5687499..c36157a 100755
> --- a/t/t1020-subdirectory.sh
> +++ b/t/t1020-subdirectory.sh
> @@ -27,13 +27,13 @@ test_expect_success 'update-index and ls-files' '
> one) echo pass one ;;
> *) echo bad one; exit 1 ;;
> esac &&
> - cd dir &&
> + (cd dir &&
> git update-index --add two &&
> case "`git ls-files`" in
> two) echo pass two ;;
> *) echo bad two; exit 1 ;;
> - esac &&
> - cd .. &&
> + esac
> + ) &&
> case "`git ls-files`" in
> dir/two"$LF"one) echo pass both ;;
> *) echo bad; exit 1 ;;
If we were to do this, shouldn't we be able to lose 'cd "$HERE"' at the
beginning of each test? The test after this one does "cd dir" without
even coming back up and relies on the next one to go back itself,
suggesting that grepping for 'cd ..' may not be sufficient, depending on
what we are trying to fix.
If we were to insist that no matter how an individual test fail, the test
that follows it must start in a known location (namely, $TRASH), then we
might want to use something like the attached patch. On the other hand,
we might want to be lenient to a test suite whose one test moves around
and the test that follows such a test knows that, and also anticipates
that the previous one _can_ fail and tries recover from that failure (e.g.
use of 'cd "$HERE"' in the test that follows the above one.
Thoughts?
t/test-lib.sh | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 29fd720..f07f275 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -432,10 +432,14 @@ test_expect_success () {
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
if ! test_skip "$@"
then
+ test ",$TRASH_DIRECTORY" = ",$(pwd)" ||
+ error "bug in the test script: starting from a different directory"
say >&3 "expecting success: $2"
test_run_ "$2"
if [ "$?" = 0 -a "$eval_ret" = 0 ]
then
+ test ",$TRASH_DIRECTORY" = ",$(pwd)" ||
+ error "bug in the test script: moved to a different directory"
test_ok_ "$1"
else
test_failure_ "$@"
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-06 23:16 ` [PATCH] Several tests: cd inside subshell instead of around Junio C Hamano
@ 2010-09-07 2:37 ` Jonathan Nieder
2010-09-07 5:08 ` Junio C Hamano
2010-09-07 10:29 ` [PATCH] t1020: Get rid of 'cd "$HERE"' at the start of each test Jens Lehmann
1 sibling, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 2:37 UTC (permalink / raw
To: Junio C Hamano; +Cc: Jens Lehmann, Git Mailing List
Junio C Hamano wrote:
> If we were to insist that no matter how an individual test fail, the test
> that follows it must start in a known location (namely, $TRASH), then we
> might want to use something like the attached patch.
I like it. Affected test scripts:
t0003-attributes.sh t0050-filesystem.sh
t1007-hash-object.sh t1020-subdirectory.sh
t1301-shared-repo.sh t1500-rev-parse.sh
t1501-worktree.sh t1504-ceiling-dirs.sh
t2050-git-dir-relative.sh t2300-cd-to-toplevel.sh
t3407-rebase-abort.sh t4119-apply-config.sh
t5300-pack-object.sh t5404-tracking-branches.sh
t5406-remote-rejects.sh t5510-fetch.sh
t5515-fetch-merge-logic.sh t5520-pull.sh
t5530-upload-pack-error.sh t5600-clone-fail-cleanup.sh
t5700-clone-reference.sh t5701-clone-local.sh
t5710-info-alternate.sh t6029-merge-subtree.sh
t7001-mv.sh t7103-reset-bare.sh
t7400-submodule-basic.sh t7401-submodule-summary.sh
t7408-submodule-reference.sh t7610-mergetool.sh
t9101-git-svn-props.sh t9103-git-svn-tracked-directory-removed.sh
t9113-git-svn-dcommit-new-file.sh
t9115-git-svn-dcommit-funky-renames.sh
t9117-git-svn-init-clone.sh
t9137-git-svn-dcommit-clobber-series.sh
t9400-git-cvsserver-server.sh
and probably some others.
What is the ",$(pwd)" for?
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 29fd720..90ed4d9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -370,6 +370,11 @@ test_debug () {
}
test_run_ () {
+ if test ",$(pwd)" != ",$TRASH_DIRECTORY"
+ then
+ error "bug in test script: starting from a different directory"
+ fi
+
test_cleanup=:
eval >&3 2>&4 "$1"
eval_ret=$?
@@ -377,6 +382,11 @@ test_run_ () {
if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
echo ""
fi
+
+ if test ",$(pwd)" != ",$TRASH_DIRECTORY"
+ then
+ error "bug in test script: moved to a different directory"
+ fi
return 0
}
--
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-07 2:37 ` Jonathan Nieder
@ 2010-09-07 5:08 ` Junio C Hamano
2010-09-07 5:19 ` Jonathan Nieder
0 siblings, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2010-09-07 5:08 UTC (permalink / raw
To: Jonathan Nieder; +Cc: Junio C Hamano, Jens Lehmann, Git Mailing List
Jonathan Nieder <jrnieder@gmail.com> writes:
> Junio C Hamano wrote:
>
>> If we were to insist that no matter how an individual test fail, the test
>> that follows it must start in a known location (namely, $TRASH), then we
>> might want to use something like the attached patch.
>
> I like it. Affected test scripts:
> ... (many) ...
> and probably some others.
For the record, I _do not_ like it at all. Is it worth being that
draconian and say each test must start at $TRASH? What do we gain by it?
We certainly do _not_ want any test to wander around, escape out of the
$TRASH directory and running random "git" command, but as long as N+1th
test knows and expects Nth test might move to a subdirectory of $TRASH and
is prepared to start, I personally do not think it is such a big deal. It
certainly makes it harder to insert a new test between such a pair of
tests, but like it or not, many of the tests already depend on the state
of the repository that earlier tests left behind. I think we could just
declare that $cwd is just a small part of that initial state for
individual test that was left behind the earlier test.
After we vet and apply Jens and your "turn 'cd there && do this && cd ..'
into a subshell" series, and the "modernize indentation style" series,
perhaps we should stop and think? In an ideal world, it would be really
nice if each "test_expect_success/failure" in a single script were
independent from each other (if we did so, GIT_SKIP_TESTS=4321.4 starts to
be more useful), but realistically, I don't think it is worth the effort.
So it may be worth it to check $(pwd) against $TRASH and make sure we
didn't escape $TRASH by mistake at the beginning of each test in test_run_
function, but to me, "must be at $TRASH" feels like a rule for the sake of
it, without really helping us very much.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH] Several tests: cd inside subshell instead of around
2010-09-07 5:08 ` Junio C Hamano
@ 2010-09-07 5:19 ` Jonathan Nieder
0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2010-09-07 5:19 UTC (permalink / raw
To: Junio C Hamano; +Cc: Jens Lehmann, Git Mailing List
Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:
>> I like it. Affected test scripts:
>> ... (many) ...
>> and probably some others.
>
> For the record, I _do not_ like it at all. Is it worth being that
> draconian and say each test must start at $TRASH? What do we gain by it?
To clarify, what I meant was something like "I like it, but reality
does not seem to permit it now".
> After we vet and apply Jens and your "turn 'cd there && do this && cd ..'
> into a subshell" series, and the "modernize indentation style" series,
> perhaps we should stop and think? In an ideal world, it would be really
> nice if each "test_expect_success/failure" in a single script were
> independent from each other (if we did so, GIT_SKIP_TESTS=4321.4 starts to
> be more useful), but realistically, I don't think it is worth the effort.
Ah, our emails crossed. I would rather that tests that affect the
state be marked as such, nothing more. The "always return to $TRASH"
rule is a lot stronger than that, unfortunately. What I really liked
about your suggestion is that the "tests must start and end in $TRASH"
rule could be checked with very little effort. Unfortunately, as the
list of scripts illustrates, that rule doesn't describe what our
current tests do.
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH] t1020: Get rid of 'cd "$HERE"' at the start of each test
2010-09-06 23:16 ` [PATCH] Several tests: cd inside subshell instead of around Junio C Hamano
2010-09-07 2:37 ` Jonathan Nieder
@ 2010-09-07 10:29 ` Jens Lehmann
1 sibling, 0 replies; 27+ messages in thread
From: Jens Lehmann @ 2010-09-07 10:29 UTC (permalink / raw
To: Junio C Hamano; +Cc: Git Mailing List, Jonathan Nieder
To achieve that, all cd commands which weren't inside a subshell had to
be put into a new one.
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
Am 07.09.2010 01:16, schrieb Junio C Hamano:
> If we were to do this, shouldn't we be able to lose 'cd "$HERE"' at the
> beginning of each test? The test after this one does "cd dir" without
> even coming back up and relies on the next one to go back itself,
You are right, patch included. I had to introduce some new subshells
for that and used the new formatting proposed by Jonathan (but I didn't
touch the one introduced by my earlier patch which is reformatted by
Jonathan's "[PATCH 1/7] tests: subshell indentation stylefix", so both
patches won't conflict.
> suggesting that grepping for 'cd ..' may not be sufficient, depending on
> what we are trying to fix.
Yeah, I knew this would only show a part of the problems. But you have
to start somewhere, no? :-)
(My first intention was to systematically search for missing &&, as
those really can be nasty, but my script-fu was not up to that task)
> If we were to insist that no matter how an individual test fail, the test
> that follows it must start in a known location (namely, $TRASH), then we
> might want to use something like the attached patch. On the other hand,
> we might want to be lenient to a test suite whose one test moves around
> and the test that follows such a test knows that, and also anticipates
> that the previous one _can_ fail and tries recover from that failure (e.g.
> use of 'cd "$HERE"' in the test that follows the above one.
I think we should force that each test finishes somewhere inside $TRASH,
but not necessarily at the top level.
t/t1020-subdirectory.sh | 91 ++++++++++++++++++++++++++---------------------
1 files changed, 50 insertions(+), 41 deletions(-)
diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index c36157a..0eb4488 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -16,12 +16,10 @@ test_expect_success setup '
cp one original.one &&
cp dir/two original.two
'
-HERE=`pwd`
LF='
'
test_expect_success 'update-index and ls-files' '
- cd "$HERE" &&
git update-index --add one &&
case "`git ls-files`" in
one) echo pass one ;;
@@ -41,20 +39,20 @@ test_expect_success 'update-index and ls-files' '
'
test_expect_success 'cat-file' '
- cd "$HERE" &&
two=`git ls-files -s dir/two` &&
two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
echo "$two" &&
git cat-file -p "$two" >actual &&
cmp dir/two actual &&
- cd dir &&
- git cat-file -p "$two" >actual &&
- cmp two actual
+ (
+ cd dir &&
+ git cat-file -p "$two" >actual &&
+ cmp two actual
+ )
'
rm -f actual dir/actual
test_expect_success 'diff-files' '
- cd "$HERE" &&
echo a >>one &&
echo d >>dir/two &&
case "`git diff-files --name-only`" in
@@ -62,77 +60,88 @@ test_expect_success 'diff-files' '
*) echo bad top; exit 1 ;;
esac &&
# diff should not omit leading paths
- cd dir &&
- case "`git diff-files --name-only`" in
- dir/two"$LF"one) echo pass subdir ;;
- *) echo bad subdir; exit 1 ;;
- esac &&
- case "`git diff-files --name-only .`" in
- dir/two) echo pass subdir limited ;;
- *) echo bad subdir limited; exit 1 ;;
- esac
+ (
+ cd dir &&
+ case "`git diff-files --name-only`" in
+ dir/two"$LF"one) echo pass subdir ;;
+ *) echo bad subdir; exit 1 ;;
+ esac &&
+ case "`git diff-files --name-only .`" in
+ dir/two) echo pass subdir limited ;;
+ *) echo bad subdir limited; exit 1 ;;
+ esac
+ )
'
test_expect_success 'write-tree' '
- cd "$HERE" &&
top=`git write-tree` &&
echo $top &&
- cd dir &&
- sub=`git write-tree` &&
- echo $sub &&
- test "z$top" = "z$sub"
+ (
+ cd dir &&
+ sub=`git write-tree` &&
+ echo $sub &&
+ test "z$top" = "z$sub"
+ )
'
test_expect_success 'checkout-index' '
- cd "$HERE" &&
git checkout-index -f -u one &&
cmp one original.one &&
- cd dir &&
- git checkout-index -f -u two &&
- cmp two ../original.two
+ (
+ cd dir &&
+ git checkout-index -f -u two &&
+ cmp two ../original.two
+ )
'
test_expect_success 'read-tree' '
- cd "$HERE" &&
rm -f one dir/two &&
tree=`git write-tree` &&
git read-tree --reset -u "$tree" &&
cmp one original.one &&
cmp dir/two original.two &&
- cd dir &&
- rm -f two &&
- git read-tree --reset -u "$tree" &&
- cmp two ../original.two &&
- cmp ../one ../original.one
+ (
+ cd dir &&
+ rm -f two &&
+ git read-tree --reset -u "$tree" &&
+ cmp two ../original.two &&
+ cmp ../one ../original.one
+ )
'
test_expect_success 'no file/rev ambiguity check inside .git' '
- cd "$HERE" &&
git commit -a -m 1 &&
- cd "$HERE"/.git &&
- git show -s HEAD
+ (
+ cd .git &&
+ git show -s HEAD
+ )
'
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
- cd "$HERE" &&
git clone -s --bare .git foo.git &&
- cd foo.git && GIT_DIR=. git show -s HEAD
+ (
+ 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" &&
git clone -s --bare .git foo.git &&
- cd foo.git && git show -s HEAD
+ (
+ cd foo.git &&
+ git show -s HEAD
+ )
'
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
- cd "$HERE" &&
rm -fr foo.git &&
git clone -s .git another &&
ln -s another yetanother &&
- cd yetanother/.git &&
- git show -s HEAD
+ (
+ cd yetanother/.git &&
+ git show -s HEAD
+ )
'
test_done
--
1.7.3.rc0.182.g5433f
^ permalink raw reply related [flat|nested] 27+ messages in thread
end of thread, other threads:[~2010-09-07 23:45 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-06 18:39 [PATCH] Several tests: cd inside subshell instead of around Jens Lehmann
2010-09-06 19:06 ` Jonathan Nieder
2010-09-06 20:12 ` Jens Lehmann
2010-09-07 1:41 ` [PATCH 0/7] " Jonathan Nieder
2010-09-07 1:42 ` [PATCH 1/7] tests: subshell indentation stylefix Jonathan Nieder
2010-09-07 3:44 ` Jonathan Nieder
2010-09-07 1:47 ` [PATCH 2/7] t1450 (fsck): remove dangling objects Jonathan Nieder
2010-09-07 1:49 ` [PATCH 3/7] t2105 (gitfile): add missing && Jonathan Nieder
2010-09-07 12:57 ` Brad King
2010-09-07 1:50 ` [PATCH 4/7] t0004 (unwritable files): simplify error handling Jonathan Nieder
2010-09-07 1:52 ` [PATCH 5/7] t1302 (core.repositoryversion): style tweaks Jonathan Nieder
2010-09-07 23:45 ` Nguyen Thai Ngoc Duy
2010-09-07 1:53 ` [PATCH 6/7] t1303 (config): " Jonathan Nieder
2010-09-07 4:30 ` Jeff King
2010-09-07 4:52 ` Junio C Hamano
2010-09-07 5:27 ` Jonathan Nieder
2010-09-07 5:12 ` guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks) Jonathan Nieder
2010-09-07 5:56 ` Jeff King
2010-09-07 6:12 ` Jonathan Nieder
2010-09-07 1:55 ` [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input Jonathan Nieder
2010-09-07 8:06 ` Thomas Rast
2010-09-07 8:22 ` Jonathan Nieder
2010-09-06 23:16 ` [PATCH] Several tests: cd inside subshell instead of around Junio C Hamano
2010-09-07 2:37 ` Jonathan Nieder
2010-09-07 5:08 ` Junio C Hamano
2010-09-07 5:19 ` Jonathan Nieder
2010-09-07 10:29 ` [PATCH] t1020: Get rid of 'cd "$HERE"' at the start of each test Jens Lehmann
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).