@matheusbsbs / matheus-bagliano / commits / 5236fce6b4
Fork 0

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 <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Dec 20, 2019 at 10:16 UTC 5236fce6b4b597588f5e3955b309195f376a858f
1 file changed +32 -13
t/t1507-rev-parse-upstream.sh
+32 -13
@@ -35,7 +35,7 @@ full_name () {
35
36 commit_subject () {
37 (cd clone &&
38 - git show -s --pretty=format:%s "$@")
38 + git show -s --pretty=tformat:%s "$@")
39 }
40
41 error_message () {
@@ -44,18 +44,27 @@ error_message () {
44 }
45
46 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
54 '
55
56 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
62 '
63
64 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
68 '
69
70 test_expect_success 'upstream of branch with @ in middle' '
@@ -86,8 +95,11 @@ test_expect_success 'my-side@{u} resolves to correct commit' '
95 git checkout side &&
96 test_commit 5 &&
97 (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
103 '
104
105 test_expect_success 'not-tracking@{u} fails' '
@@ -99,8 +111,11 @@ test_expect_success 'not-tracking@{u} fails' '
111 test_expect_success '<branch>@{u}@{1} resolves correctly' '
112 test_commit 6 &&
113 (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
119 '
120
121 test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
@@ -149,7 +164,9 @@ test_expect_success 'checkout other@{u}' '
164 '
165
166 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
170 '
171
172 test_expect_success 'branch@{u} error message when no upstream' '
@@ -203,7 +220,9 @@ test_expect_success 'pull works when tracking a local branch' '
220
221 # makes sense if the previous one succeeded
222 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
226 '
227
228 commit=$(git rev-parse HEAD)