t5701: modernize style

This test is pretty old and did not follow some of our more modern best practices. In particular: 1. It chdir'd all over the place, leaving later tests to deal with the fallout. Do our chdirs in subshells instead. 2. It did not use test_must_fail. 3. It did not use test_line_count. 4. It checked for the non-existence of a ref by looking in the .git/refs directory (since we pack refs during clone these days, this will always be succeed, making the test useless). Note that one call to "-e .git/refs/..." remains, because it is checking for the existence of a symbolic ref, not a ref itself. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 25, 2012 at 23:42 UTC f27e7654de8ff609bf5c48e35f2d27ef1ff3676e
1 file changed +20 -53
t/t5701-clone-local.sh
+20 -53
@@ -3,7 +3,10 @@
3 test_description='test local clone'
4 . ./test-lib.sh
5
6 -D=`pwd`
6 +repo_is_hardlinked() {
7 + find "$1/objects" -type f -links 1 >output &&
8 + test_line_count = 0 output
9 +}
10
11 test_expect_success 'preparing origin repository' '
12 : >file && git add . && git commit -m1 &&
@@ -19,105 +22,72 @@ test_expect_success 'preparing origin repository' '
22 '
23
24 test_expect_success 'local clone without .git suffix' '
22 - cd "$D" &&
25 git clone -l -s a b &&
24 - cd b &&
26 + (cd b &&
27 test "$(GIT_CONFIG=.git/config git config --bool core.bare)" = false &&
26 - git fetch
28 + git fetch)
29 '
30
31 test_expect_success 'local clone with .git suffix' '
30 - cd "$D" &&
32 git clone -l -s a.git c &&
32 - cd c &&
33 - git fetch
33 + (cd c && git fetch)
34 '
35
36 test_expect_success 'local clone from x' '
37 - cd "$D" &&
37 git clone -l -s x y &&
39 - cd y &&
40 - git fetch
38 + (cd y && git fetch)
39 '
40
41 test_expect_success 'local clone from x.git that does not exist' '
44 - cd "$D" &&
45 - if git clone -l -s x.git z
46 - then
47 - echo "Oops, should have failed"
48 - false
49 - else
50 - echo happy
51 - fi
42 + test_must_fail git clone -l -s x.git z
43 '
44
45 test_expect_success 'With -no-hardlinks, local will make a copy' '
55 - cd "$D" &&
46 git clone --bare --no-hardlinks x w &&
57 - cd w &&
58 - linked=$(find objects -type f ! -links 1 | wc -l) &&
59 - test 0 = $linked
47 + ! repo_is_hardlinked w
48 '
49
50 test_expect_success 'Even without -l, local will make a hardlink' '
63 - cd "$D" &&
51 rm -fr w &&
52 git clone -l --bare x w &&
66 - cd w &&
67 - copied=$(find objects -type f -links 1 | wc -l) &&
68 - test 0 = $copied
53 + repo_is_hardlinked w
54 '
55
56 test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
72 - cd "$D" &&
57 echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
58 git clone a d &&
75 - cd d &&
59 + (cd d &&
60 git fetch &&
77 - test ! -e .git/refs/remotes/origin/HEAD'
61 + test ! -e .git/refs/remotes/origin/HEAD)
62 +'
63
64 test_expect_success 'bundle clone without .bundle suffix' '
80 - cd "$D" &&
65 git clone dir/b3 &&
82 - cd b3 &&
83 - git fetch
66 + (cd b3 && git fetch)
67 '
68
69 test_expect_success 'bundle clone with .bundle suffix' '
87 - cd "$D" &&
70 git clone b1.bundle &&
89 - cd b1 &&
90 - git fetch
71 + (cd b1 && git fetch)
72 '
73
74 test_expect_success 'bundle clone from b4' '
94 - cd "$D" &&
75 git clone b4 bdl &&
96 - cd bdl &&
97 - git fetch
76 + (cd bdl && git fetch)
77 '
78
79 test_expect_success 'bundle clone from b4.bundle that does not exist' '
101 - cd "$D" &&
102 - if git clone b4.bundle bb
103 - then
104 - echo "Oops, should have failed"
105 - false
106 - else
107 - echo happy
108 - fi
80 + test_must_fail git clone b4.bundle bb
81 '
82
83 test_expect_success 'bundle clone with nonexistent HEAD' '
112 - cd "$D" &&
84 git clone b2.bundle b2 &&
114 - cd b2 &&
85 + (cd b2 &&
86 git fetch &&
116 - test ! -e .git/refs/heads/master
87 + test_must_fail git rev-parse --verify refs/heads/master)
88 '
89
90 test_expect_success 'clone empty repository' '
120 - cd "$D" &&
91 mkdir empty &&
92 (cd empty &&
93 git init &&
@@ -135,7 +105,6 @@ test_expect_success 'clone empty repository' '
105 '
106
107 test_expect_success 'clone empty repository, and then push should not segfault.' '
138 - cd "$D" &&
108 rm -fr empty/ empty-clone/ &&
109 mkdir empty &&
110 (cd empty && git init) &&
@@ -145,13 +114,11 @@ test_expect_success 'clone empty repository, and then push should not segfault.'
114 '
115
116 test_expect_success 'cloning non-existent directory fails' '
148 - cd "$D" &&
117 rm -rf does-not-exist &&
118 test_must_fail git clone does-not-exist
119 '
120
121 test_expect_success 'cloning non-git directory fails' '
154 - cd "$D" &&
122 rm -rf not-a-git-repo not-a-git-repo-clone &&
123 mkdir not-a-git-repo &&
124 test_must_fail git clone not-a-git-repo not-a-git-repo-clone