Skip to content

Commit f27e765

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8f4933 commit f27e765

File tree

1 file changed

+20
-53
lines changed

1 file changed

+20
-53
lines changed

t/t5701-clone-local.sh

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
test_description='test local clone'
44
. ./test-lib.sh
55

6-
D=`pwd`
6+
repo_is_hardlinked() {
7+
find "$1/objects" -type f -links 1 >output &&
8+
test_line_count = 0 output
9+
}
710

811
test_expect_success 'preparing origin repository' '
912
: >file && git add . && git commit -m1 &&
@@ -19,105 +22,72 @@ test_expect_success 'preparing origin repository' '
1922
'
2023

2124
test_expect_success 'local clone without .git suffix' '
22-
cd "$D" &&
2325
git clone -l -s a b &&
24-
cd b &&
26+
(cd b &&
2527
test "$(GIT_CONFIG=.git/config git config --bool core.bare)" = false &&
26-
git fetch
28+
git fetch)
2729
'
2830

2931
test_expect_success 'local clone with .git suffix' '
30-
cd "$D" &&
3132
git clone -l -s a.git c &&
32-
cd c &&
33-
git fetch
33+
(cd c && git fetch)
3434
'
3535

3636
test_expect_success 'local clone from x' '
37-
cd "$D" &&
3837
git clone -l -s x y &&
39-
cd y &&
40-
git fetch
38+
(cd y && git fetch)
4139
'
4240

4341
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
5243
'
5344

5445
test_expect_success 'With -no-hardlinks, local will make a copy' '
55-
cd "$D" &&
5646
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
6048
'
6149

6250
test_expect_success 'Even without -l, local will make a hardlink' '
63-
cd "$D" &&
6451
rm -fr w &&
6552
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
6954
'
7055

7156
test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
72-
cd "$D" &&
7357
echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
7458
git clone a d &&
75-
cd d &&
59+
(cd d &&
7660
git fetch &&
77-
test ! -e .git/refs/remotes/origin/HEAD'
61+
test ! -e .git/refs/remotes/origin/HEAD)
62+
'
7863

7964
test_expect_success 'bundle clone without .bundle suffix' '
80-
cd "$D" &&
8165
git clone dir/b3 &&
82-
cd b3 &&
83-
git fetch
66+
(cd b3 && git fetch)
8467
'
8568

8669
test_expect_success 'bundle clone with .bundle suffix' '
87-
cd "$D" &&
8870
git clone b1.bundle &&
89-
cd b1 &&
90-
git fetch
71+
(cd b1 && git fetch)
9172
'
9273

9374
test_expect_success 'bundle clone from b4' '
94-
cd "$D" &&
9575
git clone b4 bdl &&
96-
cd bdl &&
97-
git fetch
76+
(cd bdl && git fetch)
9877
'
9978

10079
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
10981
'
11082

11183
test_expect_success 'bundle clone with nonexistent HEAD' '
112-
cd "$D" &&
11384
git clone b2.bundle b2 &&
114-
cd b2 &&
85+
(cd b2 &&
11586
git fetch &&
116-
test ! -e .git/refs/heads/master
87+
test_must_fail git rev-parse --verify refs/heads/master)
11788
'
11889

11990
test_expect_success 'clone empty repository' '
120-
cd "$D" &&
12191
mkdir empty &&
12292
(cd empty &&
12393
git init &&
@@ -135,7 +105,6 @@ test_expect_success 'clone empty repository' '
135105
'
136106

137107
test_expect_success 'clone empty repository, and then push should not segfault.' '
138-
cd "$D" &&
139108
rm -fr empty/ empty-clone/ &&
140109
mkdir empty &&
141110
(cd empty && git init) &&
@@ -145,13 +114,11 @@ test_expect_success 'clone empty repository, and then push should not segfault.'
145114
'
146115

147116
test_expect_success 'cloning non-existent directory fails' '
148-
cd "$D" &&
149117
rm -rf does-not-exist &&
150118
test_must_fail git clone does-not-exist
151119
'
152120

153121
test_expect_success 'cloning non-git directory fails' '
154-
cd "$D" &&
155122
rm -rf not-a-git-repo not-a-git-repo-clone &&
156123
mkdir not-a-git-repo &&
157124
test_must_fail git clone not-a-git-repo not-a-git-repo-clone

0 commit comments

Comments
 (0)