Skip to content

Commit e3f213c

Browse files
committed
Merge branch 'jl/fix-test'
* jl/fix-test: t1020: Get rid of 'cd "$HERE"' at the start of each test t2016 (checkout -p): add missing && t1302 (core.repositoryversion): style tweaks t2105 (gitfile): add missing && t1450 (fsck): remove dangling objects tests: subshell indentation stylefix Several tests: cd inside subshell instead of around
2 parents 43d268e + fd3c32c commit e3f213c

35 files changed

+604
-491
lines changed

t/t1020-subdirectory.sh

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,123 +16,133 @@ test_expect_success setup '
1616
cp one original.one &&
1717
cp dir/two original.two
1818
'
19-
HERE=`pwd`
2019
LF='
2120
'
2221

2322
test_expect_success 'update-index and ls-files' '
24-
cd "$HERE" &&
2523
git update-index --add one &&
2624
case "`git ls-files`" in
2725
one) echo pass one ;;
2826
*) echo bad one; exit 1 ;;
2927
esac &&
30-
cd dir &&
31-
git update-index --add two &&
32-
case "`git ls-files`" in
33-
two) echo pass two ;;
34-
*) echo bad two; exit 1 ;;
35-
esac &&
36-
cd .. &&
28+
(
29+
cd dir &&
30+
git update-index --add two &&
31+
case "`git ls-files`" in
32+
two) echo pass two ;;
33+
*) echo bad two; exit 1 ;;
34+
esac
35+
) &&
3736
case "`git ls-files`" in
3837
dir/two"$LF"one) echo pass both ;;
3938
*) echo bad; exit 1 ;;
4039
esac
4140
'
4241

4342
test_expect_success 'cat-file' '
44-
cd "$HERE" &&
4543
two=`git ls-files -s dir/two` &&
4644
two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
4745
echo "$two" &&
4846
git cat-file -p "$two" >actual &&
4947
cmp dir/two actual &&
50-
cd dir &&
51-
git cat-file -p "$two" >actual &&
52-
cmp two actual
48+
(
49+
cd dir &&
50+
git cat-file -p "$two" >actual &&
51+
cmp two actual
52+
)
5353
'
5454
rm -f actual dir/actual
5555

5656
test_expect_success 'diff-files' '
57-
cd "$HERE" &&
5857
echo a >>one &&
5958
echo d >>dir/two &&
6059
case "`git diff-files --name-only`" in
6160
dir/two"$LF"one) echo pass top ;;
6261
*) echo bad top; exit 1 ;;
6362
esac &&
6463
# diff should not omit leading paths
65-
cd dir &&
66-
case "`git diff-files --name-only`" in
67-
dir/two"$LF"one) echo pass subdir ;;
68-
*) echo bad subdir; exit 1 ;;
69-
esac &&
70-
case "`git diff-files --name-only .`" in
71-
dir/two) echo pass subdir limited ;;
72-
*) echo bad subdir limited; exit 1 ;;
73-
esac
64+
(
65+
cd dir &&
66+
case "`git diff-files --name-only`" in
67+
dir/two"$LF"one) echo pass subdir ;;
68+
*) echo bad subdir; exit 1 ;;
69+
esac &&
70+
case "`git diff-files --name-only .`" in
71+
dir/two) echo pass subdir limited ;;
72+
*) echo bad subdir limited; exit 1 ;;
73+
esac
74+
)
7475
'
7576

7677
test_expect_success 'write-tree' '
77-
cd "$HERE" &&
7878
top=`git write-tree` &&
7979
echo $top &&
80-
cd dir &&
81-
sub=`git write-tree` &&
82-
echo $sub &&
83-
test "z$top" = "z$sub"
80+
(
81+
cd dir &&
82+
sub=`git write-tree` &&
83+
echo $sub &&
84+
test "z$top" = "z$sub"
85+
)
8486
'
8587

8688
test_expect_success 'checkout-index' '
87-
cd "$HERE" &&
8889
git checkout-index -f -u one &&
8990
cmp one original.one &&
90-
cd dir &&
91-
git checkout-index -f -u two &&
92-
cmp two ../original.two
91+
(
92+
cd dir &&
93+
git checkout-index -f -u two &&
94+
cmp two ../original.two
95+
)
9396
'
9497

9598
test_expect_success 'read-tree' '
96-
cd "$HERE" &&
9799
rm -f one dir/two &&
98100
tree=`git write-tree` &&
99101
git read-tree --reset -u "$tree" &&
100102
cmp one original.one &&
101103
cmp dir/two original.two &&
102-
cd dir &&
103-
rm -f two &&
104-
git read-tree --reset -u "$tree" &&
105-
cmp two ../original.two &&
106-
cmp ../one ../original.one
104+
(
105+
cd dir &&
106+
rm -f two &&
107+
git read-tree --reset -u "$tree" &&
108+
cmp two ../original.two &&
109+
cmp ../one ../original.one
110+
)
107111
'
108112

109113
test_expect_success 'no file/rev ambiguity check inside .git' '
110-
cd "$HERE" &&
111114
git commit -a -m 1 &&
112-
cd "$HERE"/.git &&
113-
git show -s HEAD
115+
(
116+
cd .git &&
117+
git show -s HEAD
118+
)
114119
'
115120

116121
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
117-
cd "$HERE" &&
118122
git clone -s --bare .git foo.git &&
119-
cd foo.git && GIT_DIR=. git show -s HEAD
123+
(
124+
cd foo.git &&
125+
GIT_DIR=. git show -s HEAD
126+
)
120127
'
121128

122129
# This still does not work as it should...
123130
: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
124-
cd "$HERE" &&
125131
git clone -s --bare .git foo.git &&
126-
cd foo.git && git show -s HEAD
132+
(
133+
cd foo.git &&
134+
git show -s HEAD
135+
)
127136
'
128137

129138
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
130-
cd "$HERE" &&
131139
rm -fr foo.git &&
132140
git clone -s .git another &&
133141
ln -s another yetanother &&
134-
cd yetanother/.git &&
135-
git show -s HEAD
142+
(
143+
cd yetanother/.git &&
144+
git show -s HEAD
145+
)
136146
'
137147

138148
test_done

t/t1302-repo-version.sh

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,64 @@ test_description='Test repository version check'
77

88
. ./test-lib.sh
99

10-
cat >test.patch <<EOF
11-
diff --git a/test.txt b/test.txt
12-
new file mode 100644
13-
--- /dev/null
14-
+++ b/test.txt
15-
@@ -0,0 +1 @@
16-
+123
17-
EOF
10+
test_expect_success 'setup' '
11+
cat >test.patch <<-\EOF &&
12+
diff --git a/test.txt b/test.txt
13+
new file mode 100644
14+
--- /dev/null
15+
+++ b/test.txt
16+
@@ -0,0 +1 @@
17+
+123
18+
EOF
1819
19-
test_create_repo "test"
20-
test_create_repo "test2"
21-
22-
GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99 || exit 1
20+
test_create_repo "test" &&
21+
test_create_repo "test2" &&
22+
GIT_CONFIG=test2/.git/config git config core.repositoryformatversion 99
23+
'
2324

2425
test_expect_success 'gitdir selection on normal repos' '
25-
(test "$(git config core.repositoryformatversion)" = 0 &&
26-
cd test &&
27-
test "$(git config core.repositoryformatversion)" = 0)'
26+
echo 0 >expect &&
27+
git config core.repositoryformatversion >actual &&
28+
(
29+
cd test &&
30+
git config core.repositoryformatversion >../actual2
31+
) &&
32+
test_cmp expect actual &&
33+
test_cmp expect actual2
34+
'
2835

29-
# Make sure it would stop at test2, not trash
3036
test_expect_success 'gitdir selection on unsupported repo' '
31-
(cd test2 &&
32-
test "$(git config core.repositoryformatversion)" = 99)'
37+
# Make sure it would stop at test2, not trash
38+
echo 99 >expect &&
39+
(
40+
cd test2 &&
41+
git config core.repositoryformatversion >../actual
42+
)
43+
test_cmp expect actual
44+
'
3345

3446
test_expect_success 'gitdir not required mode' '
35-
(git apply --stat test.patch &&
36-
cd test && git apply --stat ../test.patch &&
37-
cd ../test2 && git apply --stat ../test.patch)'
38-
39-
test_expect_success 'gitdir required mode on normal repos' '
40-
(git apply --check --index test.patch &&
41-
cd test && git apply --check --index ../test.patch)'
47+
git apply --stat test.patch &&
48+
(
49+
cd test &&
50+
git apply --stat ../test.patch
51+
) &&
52+
(
53+
cd test2 &&
54+
git apply --stat ../test.patch
55+
)
56+
'
4257

43-
test_expect_success 'gitdir required mode on unsupported repo' '
44-
(cd test2 && test_must_fail git apply --check --index ../test.patch)
58+
test_expect_success 'gitdir required mode' '
59+
git apply --check --index test.patch &&
60+
(
61+
cd test &&
62+
git apply --check --index ../test.patch
63+
) &&
64+
(
65+
cd test2 &&
66+
test_must_fail git apply --check --index ../test.patch
67+
)
4568
'
4669

4770
test_done

0 commit comments

Comments
 (0)