@matheusbsbs / matheus-bagliano / commits / 763b47bafa
Fork 0

t5703: stop losing return codes of git commands

Currently, there are two ways where the return codes of git commands are lost. The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream. The other way is when a command is in a non-assignment command substitution. The return code will be lost in favour of the surrounding command's. Rewrite instances of this such that git commands are in an assignment-only command substitution. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Nov 27, 2019 at 11:53 UTC 763b47bafab6f781dc52461985b3300d447d1332
1 file changed +29 -17
t/t5703-upload-pack-ref-in-want.sh
+29 -17
@@ -18,14 +18,16 @@ get_actual_commits () {
18 p
19 }' <out | test-tool pkt-line unpack-sideband >o.pack &&
20 git index-pack o.pack &&
21 - git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits
21 + git verify-pack -v o.idx >objs &&
22 + grep commit objs | cut -c-40 | sort >actual_commits
23 }
24
25 check_output () {
26 get_actual_refs &&
27 test_cmp expected_refs actual_refs &&
28 get_actual_commits &&
28 - test_cmp expected_commits actual_commits
29 + sort expected_commits >sorted_commits &&
30 + test_cmp sorted_commits actual_commits
31 }
32
33 # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
77 '
78
79 test_expect_success 'basic want-ref' '
80 + oid=$(git rev-parse f) &&
81 cat >expected_refs <<-EOF &&
79 - $(git rev-parse f) refs/heads/master
82 + $oid refs/heads/master
83 EOF
81 - git rev-parse f | sort >expected_commits &&
84 + git rev-parse f >expected_commits &&
85
86 + oid=$(git rev-parse a) &&
87 test-tool pkt-line pack >in <<-EOF &&
88 command=fetch
89 0001
90 no-progress
91 want-ref refs/heads/master
88 - have $(git rev-parse a)
92 + have $oid
93 done
94 0000
95 EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
99 '
100
101 test_expect_success 'multiple want-ref lines' '
102 + oid_c=$(git rev-parse c) &&
103 + oid_d=$(git rev-parse d) &&
104 cat >expected_refs <<-EOF &&
99 - $(git rev-parse c) refs/heads/o/foo
100 - $(git rev-parse d) refs/heads/o/bar
105 + $oid_c refs/heads/o/foo
106 + $oid_d refs/heads/o/bar
107 EOF
102 - git rev-parse c d | sort >expected_commits &&
108 + git rev-parse c d >expected_commits &&
109
110 + oid=$(git rev-parse b) &&
111 test-tool pkt-line pack >in <<-EOF &&
112 command=fetch
113 0001
114 no-progress
115 want-ref refs/heads/o/foo
116 want-ref refs/heads/o/bar
110 - have $(git rev-parse b)
117 + have $oid
118 done
119 0000
120 EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
124 '
125
126 test_expect_success 'mix want and want-ref' '
127 + oid=$(git rev-parse f) &&
128 cat >expected_refs <<-EOF &&
121 - $(git rev-parse f) refs/heads/master
129 + $oid refs/heads/master
130 EOF
123 - git rev-parse e f | sort >expected_commits &&
131 + git rev-parse e f >expected_commits &&
132
133 test-tool pkt-line pack >in <<-EOF &&
134 command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
146 '
147
148 test_expect_success 'want-ref with ref we already have commit for' '
149 + oid=$(git rev-parse c) &&
150 cat >expected_refs <<-EOF &&
142 - $(git rev-parse c) refs/heads/o/foo
151 + $oid refs/heads/o/foo
152 EOF
153 >expected_commits &&
154
155 + oid=$(git rev-parse c) &&
156 test-tool pkt-line pack >in <<-EOF &&
157 command=fetch
158 0001
159 no-progress
160 want-ref refs/heads/o/foo
151 - have $(git rev-parse c)
161 + have $oid
162 done
163 0000
164 EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
221
222 rm -rf local &&
223 cp -r "$LOCAL_PRISTINE" local &&
224 + oid=$(git -C "$REPO" rev-parse d) &&
225 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
215 - $(git -C "$REPO" rev-parse d):refs/heads/actual &&
226 + "$oid":refs/heads/actual &&
227
228 git -C "$REPO" rev-parse "d" >expected &&
229 git -C local rev-parse refs/heads/actual >actual &&
230 test_cmp expected actual &&
220 - grep "want $(git -C "$REPO" rev-parse d)" log
231 + grep "want $oid" log
232 '
233
234 test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
250
251 rm -rf local &&
252 cp -r "$LOCAL_PRISTINE" local &&
253 + oid=$(git -C "$REPO" rev-parse b) &&
254 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
243 - master $(git -C "$REPO" rev-parse b):refs/heads/actual &&
255 + master "$oid":refs/heads/actual &&
256
257 git -C "$REPO" rev-parse "master" "b" >expected &&
258 git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
259 test_cmp expected actual &&
248 - grep "want $(git -C "$REPO" rev-parse b)" log &&
260 + grep "want $oid" log &&
261 grep "want-ref refs/heads/master" log
262 '
263