@matheusbsbs / matheus-bagliano / commits / b441717256
Fork 0

t1507: inline full_name()

Before, we were running `test_must_fail full_name`. However, `test_must_fail` should only be used on git commands. Inline full_name() so that we can use test_must_fail on the git command directly. When full_name() was introduced in 28fb84382b (Introduce <branch>@{upstream} notation, 2009-09-10), the `git -C` option wasn't available yet (since it was introduced in 44e1e4d67d (git: run in a directory given with -C option, 2013-09-09)). As a result, the helper function removed the need to manually cd each time. However, since `git -C` is available now, we can just use that instead and inline full_name(). An alternate approach was taken where we taught full_name() to accept an optional `!` arg to trigger test_must_fail behavior. However, this added more unnecessary complexity than inlining so we inline instead. 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 b44171725646880db07cbee6446e15b4afaa1930
1 file changed +15 -20
t/t1507-rev-parse-upstream.sh
+15 -20
@@ -28,11 +28,6 @@ test_expect_success 'setup' '
28 )
29 '
30
31 -full_name () {
32 - (cd clone &&
33 - git rev-parse --symbolic-full-name "$@")
34 -}
35 -
31 commit_subject () {
32 (cd clone &&
33 git show -s --pretty=tformat:%s "$@")
@@ -45,50 +40,50 @@ error_message () {
40
41 test_expect_success '@{upstream} resolves to correct full name' '
42 echo refs/remotes/origin/master >expect &&
48 - full_name @{upstream} >actual &&
43 + git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
44 test_cmp expect actual &&
50 - full_name @{UPSTREAM} >actual &&
45 + git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
46 test_cmp expect actual &&
52 - full_name @{UpSTReam} >actual &&
47 + git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
48 test_cmp expect actual
49 '
50
51 test_expect_success '@{u} resolves to correct full name' '
52 echo refs/remotes/origin/master >expect &&
58 - full_name @{u} >actual &&
53 + git -C clone rev-parse --symbolic-full-name @{u} >actual &&
54 test_cmp expect actual &&
60 - full_name @{U} >actual &&
55 + git -C clone rev-parse --symbolic-full-name @{U} >actual &&
56 test_cmp expect actual
57 '
58
59 test_expect_success 'my-side@{upstream} resolves to correct full name' '
60 echo refs/remotes/origin/side >expect &&
66 - full_name my-side@{u} >actual &&
61 + git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
62 test_cmp expect actual
63 '
64
65 test_expect_success 'upstream of branch with @ in middle' '
71 - full_name fun@ny@{u} >actual &&
66 + git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual &&
67 echo refs/remotes/origin/side >expect &&
68 test_cmp expect actual &&
74 - full_name fun@ny@{U} >actual &&
69 + git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
70 test_cmp expect actual
71 '
72
73 test_expect_success 'upstream of branch with @ at start' '
79 - full_name @funny@{u} >actual &&
74 + git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
75 echo refs/remotes/origin/side >expect &&
76 test_cmp expect actual
77 '
78
79 test_expect_success 'upstream of branch with @ at end' '
85 - full_name funny@@{u} >actual &&
80 + git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
81 echo refs/remotes/origin/side >expect &&
82 test_cmp expect actual
83 '
84
85 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
91 - test_must_fail full_name refs/heads/my-side@{upstream}
86 + test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
87 '
88
89 test_expect_success 'my-side@{u} resolves to correct commit' '
@@ -103,9 +98,9 @@ test_expect_success 'my-side@{u} resolves to correct commit' '
98 '
99
100 test_expect_success 'not-tracking@{u} fails' '
106 - test_must_fail full_name non-tracking@{u} &&
101 + test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
102 (cd clone && git checkout --no-track -b non-tracking) &&
108 - test_must_fail full_name non-tracking@{u}
103 + test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
104 '
105
106 test_expect_success '<branch>@{u}@{1} resolves correctly' '
@@ -165,7 +160,7 @@ test_expect_success 'checkout other@{u}' '
160
161 test_expect_success 'branch@{u} works when tracking a local branch' '
162 echo refs/heads/master >expect &&
168 - full_name local-master@{u} >actual &&
163 + git -C clone rev-parse --symbolic-full-name local-master@{u} >actual &&
164 test_cmp expect actual
165 '
166
@@ -221,7 +216,7 @@ test_expect_success 'pull works when tracking a local branch' '
216 # makes sense if the previous one succeeded
217 test_expect_success '@{u} works when tracking a local branch' '
218 echo refs/heads/master >expect &&
224 - full_name @{u} >actual &&
219 + git -C clone rev-parse --symbolic-full-name @{u} >actual &&
220 test_cmp expect actual
221 '
222