Several tests: cd inside subshell instead of around
PATCH 1/1 Several tests: cd inside subshell instead of around
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 \.\.".
---
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(-)
t/t1020-subdirectory.sh +3 -3
@@ -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 ;;
t/t1302-repo-version.sh +3 -3
@@ -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 &&
t/t2101-update-index-reupdate.sh +3 -3
@@ -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'
t/t3060-ls-files-with-tree.sh +1 -3
@@ -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'
t/t3409-rebase-preserve-merges.sh +6 -6
@@ -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 &&
t/t3903-stash.sh +3 -3
@@ -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' '
t/t4041-diff-submodule-option.sh +3 -3
@@ -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 &&
t/t5510-fetch.sh +9 -9
@@ -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 '
t/t6050-replace.sh +11 -11
@@ -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' '
t/t7400-submodule-basic.sh +3 -3
@@ -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" &&
t/t7401-submodule-summary.sh +3 -3
@@ -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 &&
t/t9100-git-svn-basic.sh +3 -3
@@ -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"'
t/t9101-git-svn-props.sh +8 -8
@@ -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 "
t/t9102-git-svn-deep-rmdir.sh +3 -3
@@ -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' '
t/t9104-git-svn-follow-parent.sh +15 -15
@@ -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 &&
t/t9105-git-svn-commit-diff.sh +3 -3
@@ -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" &&
t/t9106-git-svn-commit-diff-clobber.sh +12 -12
@@ -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 '
t/t9107-git-svn-migrate.sh +2 -2
@@ -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 &&
t/t9114-git-svn-dcommit-merge.sh +3 -3
@@ -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' '
t/t9115-git-svn-dcommit-funky-renames.sh +3 -3
@@ -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' '
t/t9116-git-svn-log.sh +2 -2
@@ -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 &&
t/t9119-git-svn-info.sh +63 -63
210 lines not on this page · raw message
t/t9120-git-svn-clone-with-percent-escapes.sh +3 -3
@@ -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...
t/t9123-git-svn-rebuild-with-rewriteroot.sh +2 -2
@@ -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' '
t/t9125-git-svn-multi-glob-branch-names.sh +6 -6
@@ -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
t/t9127-git-svn-partial-rebuild.sh +15 -15
@@ -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 + ) ) '
t/t9128-git-svn-cmd-branch.sh +9 -9
@@ -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 ) '
t/t9137-git-svn-dcommit-clobber-series.sh +6 -6
@@ -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' "
t/t9300-fast-import.sh +2 -3
@@ -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'
t/t9401-git-cvsserver-crlf.sh +27 -26
112 lines not on this page · raw message
t/t9600-cvsimport.sh +18 -20
@@ -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 + ) '
t/t9603-cvsimport-patchsets.sh +3 -3
@@ -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
Signature · 1 line
1.7.3.rc0.181.g885f40
Quoted 2 lines · Jens Lehmann
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.
Quoted 1 line
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.
Am 06.09.2010 21:06, schrieb Jonathan Nieder:
Quoted 22 lines
Do you think it would be a bad idea if I send a follow-on patch that changes code like this:
(cd dir &&t/t1020-subdirectory.sh +0
-0git 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 )
Quoted 2 lines
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 ...
Quoted 4 lines · Jens Lehmann
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(-)
Signature · 1 line
1.7.2.3
PATCH 1/7 tests: subshell indentation stylefix
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.
--- 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(-)
t/t1020-subdirectory.sh +7 -6
@@ -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 ;;
t/t1302-repo-version.sh +9 -2
@@ -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 &&
t/t3060-ls-files-with-tree.sh +6 -6
@@ -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 \
t/t3409-rebase-preserve-merges.sh +7 -6
@@ -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 &&
t/t3903-stash.sh +3 -2
@@ -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 ) '
t/t4041-diff-submodule-option.sh +4 -3
@@ -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)' "
t/t5510-fetch.sh +19 -16
@@ -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
t/t6050-replace.sh +25 -21
69 lines not on this page · raw message
t/t7400-submodule-basic.sh +6 -5
@@ -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 &&
t/t7401-submodule-summary.sh +4 -3
@@ -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)' "
t/t9100-git-svn-basic.sh +11 -10
@@ -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"'
t/t9101-git-svn-props.sh +19 -14
@@ -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*
t/t9102-git-svn-deep-rmdir.sh +7 -6
@@ -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" ) '
t/t9104-git-svn-follow-parent.sh +32 -24
81 lines not on this page · raw message
t/t9105-git-svn-commit-diff.sh +4 -3
@@ -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 &&
t/t9106-git-svn-commit-diff-clobber.sh +17 -13
@@ -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" ) &&
t/t9107-git-svn-migrate.sh +9 -7
@@ -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 &&
t/t9114-git-svn-dcommit-merge.sh +4 -3
@@ -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' '
t/t9115-git-svn-dcommit-funky-renames.sh +4 -3
@@ -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' '
t/t9116-git-svn-log.sh +9 -7
@@ -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 &&
t/t9119-git-svn-info.sh +45 -24
166 lines not on this page · raw message
t/t9120-git-svn-clone-with-percent-escapes.sh +2 -1
@@ -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} ) '
Signature · 1 line
1.7.2.3
Re: [PATCH 1/7] tests: subshell indentation stylefix
Quoted 2 lines · Jonathan Nieder
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.
Quoted 10 lines
t/t1020-subdirectory.sh +0
-4@@ -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 ;;
t/t1020-subdirectory.sh test_expect_success 'update-index and ls-files' ' · line 37
Quoted 10 lines
t/t1020-subdirectory.sh +7
-2- *) 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...
t/t4041-diff-submodule-option.sh EOF · line 91
Quoted 13 lines
t/t4041-diff-submodule-option.sh +4
-3@@ -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.
Quoted 10 lines
t/t9100-git-svn-basic.sh +0
-4@@ -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 &&
t/t9100-git-svn-basic.sh esac · line 28
Quoted 10 lines
t/t9100-git-svn-basic.sh +4
-6- 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?
Quoted 9 lines
t/t9107-git-svn-migrate.sh +0
-3@@ -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
t/t9107-git-svn-migrate.sh test_description='git svn metadata migrations from previous versions' · line 15
Quoted 10 lines
t/t9107-git-svn-migrate.sh +7
-3- 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.
Quoted 9 lines
t/t9116-git-svn-log.sh +0
-3@@ -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
t/t9116-git-svn-log.sh test_description='git svn log tests' · line 17
Quoted 10 lines
t/t9116-git-svn-log.sh +7
-3- 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.
Quoted 6 lines
t/t9119-git-svn-info.sh +0
-0@@ -179,11 +186,13 @@ test_expect_success 'info --url added-directory' ' ' test_expect_success 'info added-symlink-file' "
t/t9119-git-svn-info.sh test_expect_success 'info --url added-directory' ' · line 196
Quoted 10 lines
t/t9119-git-svn-info.sh +4
-2- (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.
PATCH 2/7 t1450 (fsck): remove dangling objects
In reply to Jonathan NiederThe 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.
--- t/t1450-fsck.sh | 140 ++++++++++++++++++++++++++++++++----------------------- 1 files changed, 82 insertions(+), 58 deletions(-)
t/t1450-fsck.sh +82 -58
@@ -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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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
Signature · 1 line
1.7.2.3
PATCH 3/7 t2105 (gitfile): add missing &&
In reply to Jonathan NiederMake sure early failures are not masked by later successes.
--- t/t2105-update-index-gitfile.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
t/t2105-update-index-gitfile.sh +1 -1
@@ -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) '
Signature · 1 line
1.7.2.3
Re: [PATCH 3/7] t2105 (gitfile): add missing &&
Quoted 5 lines · Jonathan Nieder
Make sure early failures are not masked by later successes.
Cc Brad King <[email protected]>Signed-off-by Jonathan Nieder <[email protected]>---
An obvious oversight on my part.
Thanks,
-Brad
Quoted 16 lines
t/t2105-update-index-gitfile.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)t/t2105-update-index-gitfile.sh +1
-1@@ -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) '
PATCH 4/7 t0004 (unwritable files): simplify error handling
In reply to Jonathan NiederInstead 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.
--- t/t0004-unwritable.sh | 52 +++++++++++++----------------------------------- 1 files changed, 14 insertions(+), 38 deletions(-)
t/t0004-unwritable.sh +14 -38
@@ -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
Signature · 1 line
1.7.2.3
PATCH 5/7 t1302 (core.repositoryversion): style tweaks
In reply to Jonathan NiederThis 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.
--- t/t1302-repo-version.sh | 64 +++++++++++++++++++++++++++++----------------- 1 files changed, 40 insertions(+), 24 deletions(-)
t/t1302-repo-version.sh +40 -24
@@ -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
Signature · 1 line
1.7.2.3
Re: [PATCH 5/7] t1302 (core.repositoryversion): style tweaks
2010/9/7 Jonathan Nieder <[email protected]>:
Quoted 14 lines
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;
- usetest_cmpinstead 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.
Quoted 2 lines
Cc Nguyễn Thái Ngọc Duy <[email protected]>Signed-off-by Jonathan Nieder <[email protected]>
Looks good to me.
Signature · 1 line
Duy
PATCH 6/7 t1303 (config): style tweaks
In reply to Jonathan NiederThis 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".
--- t/t1303-wacky-config.sh | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-)
t/t1303-wacky-config.sh +16 -12
@@ -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"
Signature · 1 line
1.7.2.3
Re: [PATCH 6/7] t1303 (config): style tweaks
Quoted 1 line · Jonathan Nieder
This test already has impeccable style,
I don't think my style has ever been called impeccable...
Quoted 2 lines
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.
Quoted 5 lines
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:
t/t1303-wacky-config.sh test_expect_success 'add key in different section' ' · line 42
Quoted 3 lines
t/t1303-wacky-config.sh +1
-1-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.
Quoted 2 lines
- 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.
Quoted 2 lines
- 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]*('.
Quoted 1 line
- reorder arguments to
test_cmpas "test_cmpexpected 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 ...
EOFtest_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
guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)
(+cc: Ævar in case he is interested)
Hi,
Quoted 3 lines · Jeff King
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.
Quoted 8 lines
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 ...
EOFtest_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:
Quoted 9 lines
, but IMO you are
making at least one of them less readable, because you have to deal with the extra quoting layer oftest_expect_success. IOW:t/t1303-wacky-config.sh test_expect_success 'add key in different section' ' · line 42
Quoted 3 lines
t/t1303-wacky-config.sh +1
-1-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
Re: guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)
Quoted 7 lines · Jonathan Nieder
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 keyentering 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).
Quoted 2 lines
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...
Quoted 3 lines
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.
Quoted 8 lines
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 ...
EOFtest_end success
test_start 'description'
git frob >actual &&test_cmp expect actualtest_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.
Quoted 11 lines
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 aGIT_SKIP_TESTSspecification. 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).
Quoted 7 lines
I don't know: I think
cat >expect <<-\EOF && ... EOFis 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
Re: guarding everything with test_expect_success (Re: [PATCH 6/7] t1303 (config): style tweaks)
Quoted 14 lines · Jeff King
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 ...
EOFtest_endsuccess
test_start'description'
git frob >actual &&test_cmpexpect actualtest_endsuccess
Quoted 4 lines
where
test_startwould set up >&3 and >&4 as usual, andtest_endwould 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 ...
EOFtest_end
syntax.)
Quoted 11 lines
Quoted 7 lines
I don't know: I think
cat >expect <<-\EOF && ... EOFis 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
Re: [PATCH 6/7] t1303 (config): style tweaks
In reply to Jeff KingQuoted 15 lines · Jeff King
... But I really don't want to be too draconian
about "everything must go intotest_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 ...
EOFtest_expect_success'frob it' '
git frob &&
test_cmpexpect actual
'than:
Quoted 7 lines
test_expect_success'frob it' 'cat >expect <<"EOF" &&... some expected output ...
EOF
git frob &&
test_cmpexpect 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.
Re: [PATCH 6/7] t1303 (config): style tweaks
Quoted 5 lines · Junio C Hamano
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 oftest-lib.shand the firsttest_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
)
PATCH 7/7 t2016 (checkout -p): use printf for multiline y/n input
In reply to Jonathan NiederInstead 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.
--- t/t2016-checkout-patch.sh | 43 +++++++++++++++++++++++++++++-------------- 1 files changed, 29 insertions(+), 14 deletions(-)
t/t2016-checkout-patch.sh +29 -14
@@ -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 '
Signature · 1 line
1.7.2.3
Re: [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input
Quoted 10 lines · Jonathan Nieder
Instead of
(echo y; echo n; echo n) | git checkout -p HEAD^ -- dir
write
printf "%s\n" y n n |
git checkout -p HEAD^ -- dirwhich 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.
Quoted 2 lines
While at it, add a missing && to the "git checkout -p HEAD with change already staged" test.
Good catch.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH/RFC 7/7] t2016 (checkout -p): use printf for multiline y/n input
Quoted 3 lines · Thomas Rast
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.
Quoted 4 lines
Quoted 2 lines
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.
--- t/t2016-checkout-patch.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
t/t2016-checkout-patch.sh +1 -1
@@ -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 &&
Signature · 1 line
1.7.2.3
Quoted 7 lines · Jens Lehmann
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 <[email protected]>---
Thanks; that is a huge effort of cleaning things up.
Quoted 11 lines
t/t1020-subdirectory.sh +1
-1@@ -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 &&
t/t1020-subdirectory.sh test_expect_success 'update-index and ls-files' ' · line 39
Quoted 10 lines
t/t1020-subdirectory.sh +2
-2case "`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(-)
t/test-lib.sh +4 -0
@@ -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_ "$@"
Quoted 3 lines · Junio C Hamano
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?
t/test-lib.sh +10 -0
@@ -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 }
Quoted 9 lines · Jonathan Nieder
Quoted 3 lines · Junio C Hamano
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.
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Jonathan Nieder
I like it. Affected test scripts:
... (many) ...
and probably some others.For the record, I
_donot_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".
Quoted 6 lines
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.
PATCH 1/1 t1020: Get rid of 'cd "$HERE"' at the start of each test
In reply to Junio C HamanoTo achieve that, all cd commands which weren't inside a subshell had to be put into a new one.
---
Am 07.09.2010 01:16, schrieb Junio C Hamano:
Quoted 3 lines
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.
Quoted 2 lines
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)
Quoted 7 lines
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(-)
t/t1020-subdirectory.sh +50 -41
@@ -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
Signature · 1 line
1.7.3.rc0.182.g5433f