Skip to content

Commit 2f33415

Browse files
committed
Modernize t5400 test script
Many tests checked for failure by hand without using test_must_fail (they probably predate the shell function). When we know the desired outcome, explicitly check for it, instead of checking if the result does not match one possible incorrect outcome. E.g. if you expect a push to be refused, you do not test if the result is different from what was pushed. Instead, make sure that the ref did not before and after the push. The test sequence chdir'ed around and any failure at one point could have started the next test in an unexpected directory. Fix this problem by using subshells as necessary. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ab9a8b commit 2f33415

File tree

1 file changed

+94
-86
lines changed

1 file changed

+94
-86
lines changed

t/t5400-send-pack.sh

Lines changed: 94 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ test_expect_success setup '
3232
done &&
3333
git update-ref HEAD "$commit" &&
3434
git clone ./. victim &&
35-
cd victim &&
36-
git log &&
37-
cd .. &&
35+
( cd victim && git log ) &&
3836
git update-ref HEAD "$zero" &&
3937
parent=$zero &&
4038
i=0 &&
@@ -59,88 +57,84 @@ test_expect_success 'pack the source repository' '
5957
'
6058

6159
test_expect_success 'pack the destination repository' '
60+
(
6261
cd victim &&
6362
git repack -a -d &&
64-
git prune &&
65-
cd ..
63+
git prune
64+
)
6665
'
6766

68-
test_expect_success \
69-
'pushing rewound head should not barf but require --force' '
70-
# should not fail but refuse to update.
71-
if git send-pack ./victim/.git/ master
72-
then
73-
# now it should fail with Pasky patch
74-
echo >&2 Gaah, it should have failed.
75-
false
76-
else
77-
echo >&2 Thanks, it correctly failed.
78-
true
79-
fi &&
80-
if cmp victim/.git/refs/heads/master .git/refs/heads/master
81-
then
82-
# should have been left as it was!
83-
false
84-
else
85-
true
86-
fi &&
67+
test_expect_success 'refuse pushing rewound head without --force' '
68+
pushed_head=$(git rev-parse --verify master) &&
69+
victim_orig=$(cd victim && git rev-parse --verify master) &&
70+
test_must_fail git send-pack ./victim master &&
71+
victim_head=$(cd victim && git rev-parse --verify master) &&
72+
test "$victim_head" = "$victim_orig" &&
8773
# this should update
88-
git send-pack --force ./victim/.git/ master &&
89-
cmp victim/.git/refs/heads/master .git/refs/heads/master
74+
git send-pack --force ./victim master &&
75+
victim_head=$(cd victim && git rev-parse --verify master) &&
76+
test "$victim_head" = "$pushed_head"
9077
'
9178

9279
test_expect_success \
9380
'push can be used to delete a ref' '
94-
cd victim &&
95-
git branch extra master &&
96-
cd .. &&
97-
test -f victim/.git/refs/heads/extra &&
98-
git send-pack ./victim/.git/ :extra master &&
99-
! test -f victim/.git/refs/heads/extra
81+
( cd victim && git branch extra master ) &&
82+
git send-pack ./victim :extra master &&
83+
( cd victim &&
84+
test_must_fail git rev-parse --verify extra )
10085
'
10186

102-
unset GIT_CONFIG
103-
HOME=`pwd`/no-such-directory
104-
export HOME ;# this way we force the victim/.git/config to be used.
105-
106-
test_expect_success \
107-
'pushing a delete should be denied with denyDeletes' '
108-
cd victim &&
109-
git config receive.denyDeletes true &&
110-
git branch extra master &&
111-
cd .. &&
112-
test -f victim/.git/refs/heads/extra &&
113-
test_must_fail git send-pack ./victim/.git/ :extra master
87+
test_expect_success 'refuse deleting push with denyDeletes' '
88+
(
89+
cd victim &&
90+
( git branch -D extra || : ) &&
91+
git config receive.denyDeletes true &&
92+
git branch extra master
93+
) &&
94+
test_must_fail git send-pack ./victim :extra master
11495
'
115-
rm -f victim/.git/refs/heads/extra
11696

117-
test_expect_success \
118-
'pushing with --force should be denied with denyNonFastforwards' '
119-
cd victim &&
120-
git config receive.denyNonFastforwards true &&
121-
cd .. &&
122-
git update-ref refs/heads/master master^ || return 1
123-
git send-pack --force ./victim/.git/ master && return 1
124-
! test_cmp .git/refs/heads/master victim/.git/refs/heads/master
97+
test_expect_success 'denyNonFastforwards trumps --force' '
98+
(
99+
cd victim &&
100+
( git branch -D extra || : ) &&
101+
git config receive.denyNonFastforwards true
102+
) &&
103+
victim_orig=$(cd victim && git rev-parse --verify master) &&
104+
test_must_fail git send-pack --force ./victim master^:master &&
105+
victim_head=$(cd victim && git rev-parse --verify master) &&
106+
test "$victim_orig" = "$victim_head"
125107
'
126108

127-
test_expect_success \
128-
'pushing does not include non-head refs' '
129-
mkdir parent && cd parent &&
130-
git init && touch file && git add file && git commit -m add &&
131-
cd .. &&
132-
git clone parent child && cd child && git push --all &&
133-
cd ../parent &&
134-
git branch -a >branches && ! grep origin/master branches
109+
test_expect_success 'push --all excludes remote tracking hierarchy' '
110+
mkdir parent &&
111+
(
112+
cd parent &&
113+
git init && : >file && git add file && git commit -m add
114+
) &&
115+
git clone parent child &&
116+
(
117+
cd child && git push --all
118+
) &&
119+
(
120+
cd parent &&
121+
test -z "$(git for-each-ref refs/remotes/origin)"
122+
)
135123
'
136124

137125
rewound_push_setup() {
138126
rm -rf parent child &&
139-
mkdir parent && cd parent &&
140-
git init && echo one >file && git add file && git commit -m one &&
141-
echo two >file && git commit -a -m two &&
142-
cd .. &&
143-
git clone parent child && cd child && git reset --hard HEAD^
127+
mkdir parent &&
128+
(
129+
cd parent &&
130+
git init &&
131+
echo one >file && git add file && git commit -m one &&
132+
echo two >file && git commit -a -m two
133+
) &&
134+
git clone parent child &&
135+
(
136+
cd child && git reset --hard HEAD^
137+
)
144138
}
145139

146140
rewound_push_succeeded() {
@@ -156,30 +150,44 @@ rewound_push_failed() {
156150
fi
157151
}
158152

159-
test_expect_success \
160-
'pushing explicit refspecs respects forcing' '
153+
test_expect_success 'pushing explicit refspecs respects forcing' '
161154
rewound_push_setup &&
162-
if git send-pack ../parent/.git refs/heads/master:refs/heads/master
163-
then
164-
false
165-
else
166-
true
167-
fi && rewound_push_failed &&
168-
git send-pack ../parent/.git +refs/heads/master:refs/heads/master &&
169-
rewound_push_succeeded
155+
parent_orig=$(cd parent && git rev-parse --verify master) &&
156+
(
157+
cd child &&
158+
test_must_fail git send-pack ../parent \
159+
refs/heads/master:refs/heads/master
160+
) &&
161+
parent_head=$(cd parent && git rev-parse --verify master) &&
162+
test "$parent_orig" = "$parent_head" &&
163+
(
164+
cd child &&
165+
git send-pack ../parent \
166+
+refs/heads/master:refs/heads/master
167+
) &&
168+
parent_head=$(cd parent && git rev-parse --verify master) &&
169+
child_head=$(cd parent && git rev-parse --verify master) &&
170+
test "$parent_head" = "$child_head"
170171
'
171172

172-
test_expect_success \
173-
'pushing wildcard refspecs respects forcing' '
173+
test_expect_success 'pushing wildcard refspecs respects forcing' '
174174
rewound_push_setup &&
175-
if git send-pack ../parent/.git refs/heads/*:refs/heads/*
176-
then
177-
false
178-
else
179-
true
180-
fi && rewound_push_failed &&
181-
git send-pack ../parent/.git +refs/heads/*:refs/heads/* &&
182-
rewound_push_succeeded
175+
parent_orig=$(cd parent && git rev-parse --verify master) &&
176+
(
177+
cd child &&
178+
test_must_fail git send-pack ../parent \
179+
"refs/heads/*:refs/heads/*"
180+
) &&
181+
parent_head=$(cd parent && git rev-parse --verify master) &&
182+
test "$parent_orig" = "$parent_head" &&
183+
(
184+
cd child &&
185+
git send-pack ../parent \
186+
"+refs/heads/*:refs/heads/*"
187+
) &&
188+
parent_head=$(cd parent && git rev-parse --verify master) &&
189+
child_head=$(cd parent && git rev-parse --verify master) &&
190+
test "$parent_head" = "$child_head"
183191
'
184192

185193
test_done

0 commit comments

Comments
 (0)