Skip to content

Commit 5236fce

Browse files
Denton-Lgitster
authored andcommitted
t1507: stop losing return codes of git commands
The return code of git commands are lost when a command is in a non-assignment command substitution in favour of the surrounding command's. Rewrite instances of this so that git commands run on their own. In commit_subject(), use a `tformat` instead of `format` since, previously, we were testing the output of a command substitution which didn't care if there was a trailing newline since it was automatically stripped. Since we use test_cmp() now, the trailing newline matters so use `tformat` to always output it. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10812c2 commit 5236fce

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

t/t1507-rev-parse-upstream.sh

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ full_name () {
3535

3636
commit_subject () {
3737
(cd clone &&
38-
git show -s --pretty=format:%s "$@")
38+
git show -s --pretty=tformat:%s "$@")
3939
}
4040

4141
error_message () {
@@ -44,18 +44,27 @@ error_message () {
4444
}
4545

4646
test_expect_success '@{upstream} resolves to correct full name' '
47-
test refs/remotes/origin/master = "$(full_name @{upstream})" &&
48-
test refs/remotes/origin/master = "$(full_name @{UPSTREAM})" &&
49-
test refs/remotes/origin/master = "$(full_name @{UpSTReam})"
47+
echo refs/remotes/origin/master >expect &&
48+
full_name @{upstream} >actual &&
49+
test_cmp expect actual &&
50+
full_name @{UPSTREAM} >actual &&
51+
test_cmp expect actual &&
52+
full_name @{UpSTReam} >actual &&
53+
test_cmp expect actual
5054
'
5155

5256
test_expect_success '@{u} resolves to correct full name' '
53-
test refs/remotes/origin/master = "$(full_name @{u})" &&
54-
test refs/remotes/origin/master = "$(full_name @{U})"
57+
echo refs/remotes/origin/master >expect &&
58+
full_name @{u} >actual &&
59+
test_cmp expect actual &&
60+
full_name @{U} >actual &&
61+
test_cmp expect actual
5562
'
5663

5764
test_expect_success 'my-side@{upstream} resolves to correct full name' '
58-
test refs/remotes/origin/side = "$(full_name my-side@{u})"
65+
echo refs/remotes/origin/side >expect &&
66+
full_name my-side@{u} >actual &&
67+
test_cmp expect actual
5968
'
6069

6170
test_expect_success 'upstream of branch with @ in middle' '
@@ -86,8 +95,11 @@ test_expect_success 'my-side@{u} resolves to correct commit' '
8695
git checkout side &&
8796
test_commit 5 &&
8897
(cd clone && git fetch) &&
89-
test 2 = "$(commit_subject my-side)" &&
90-
test 5 = "$(commit_subject my-side@{u})"
98+
echo 2 >expect &&
99+
commit_subject my-side >actual &&
100+
test_cmp expect actual &&
101+
echo 5 >expect &&
102+
commit_subject my-side@{u} >actual
91103
'
92104

93105
test_expect_success 'not-tracking@{u} fails' '
@@ -99,8 +111,11 @@ test_expect_success 'not-tracking@{u} fails' '
99111
test_expect_success '<branch>@{u}@{1} resolves correctly' '
100112
test_commit 6 &&
101113
(cd clone && git fetch) &&
102-
test 5 = $(commit_subject my-side@{u}@{1}) &&
103-
test 5 = $(commit_subject my-side@{U}@{1})
114+
echo 5 >expect &&
115+
commit_subject my-side@{u}@{1} >actual &&
116+
test_cmp expect actual &&
117+
commit_subject my-side@{U}@{1} >actual &&
118+
test_cmp expect actual
104119
'
105120

106121
test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
@@ -149,7 +164,9 @@ test_expect_success 'checkout other@{u}' '
149164
'
150165

151166
test_expect_success 'branch@{u} works when tracking a local branch' '
152-
test refs/heads/master = "$(full_name local-master@{u})"
167+
echo refs/heads/master >expect &&
168+
full_name local-master@{u} >actual &&
169+
test_cmp expect actual
153170
'
154171

155172
test_expect_success 'branch@{u} error message when no upstream' '
@@ -203,7 +220,9 @@ test_expect_success 'pull works when tracking a local branch' '
203220

204221
# makes sense if the previous one succeeded
205222
test_expect_success '@{u} works when tracking a local branch' '
206-
test refs/heads/master = "$(full_name @{u})"
223+
echo refs/heads/master >expect &&
224+
full_name @{u} >actual &&
225+
test_cmp expect actual
207226
'
208227

209228
commit=$(git rev-parse HEAD)

0 commit comments

Comments
 (0)