Skip to content

Commit ec2764e

Browse files
jherlandgitster
authored andcommitted
t2024: Show failure to use refspec when DWIMming remote branch names
When using "git checkout foo" to DWIM the creation of local "foo" from some existing upstream "foo", we assume conventional refspecs as created by "git clone" or "git remote add", and fail to work correctly if the current refspecs do not follow the conventional "refs/remotes/$remote/*" pattern. Improved-by: Jonathan Nieder <[email protected]> Signed-off-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 399e4a1 commit ec2764e

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

t/t2024-checkout-dwim.sh

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_branch_upstream () {
2424
}
2525

2626
test_expect_success 'setup' '
27+
test_commit my_master &&
2728
git init repo_a &&
2829
(
2930
cd repo_a &&
@@ -58,7 +59,7 @@ test_expect_success 'checkout of non-existing branch fails' '
5859
test_branch master
5960
'
6061

61-
test_expect_success 'checkout of branch from multiple remotes fails' '
62+
test_expect_success 'checkout of branch from multiple remotes fails #1' '
6263
git checkout -B master &&
6364
test_might_fail git branch -D foo &&
6465
@@ -96,4 +97,71 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '
9697
test_branch master
9798
'
9899

100+
test_expect_success 'setup more remotes with unconventional refspecs' '
101+
git checkout -B master &&
102+
git init repo_c &&
103+
(
104+
cd repo_c &&
105+
test_commit c_master &&
106+
git checkout -b bar &&
107+
test_commit c_bar
108+
git checkout -b spam &&
109+
test_commit c_spam
110+
) &&
111+
git init repo_d &&
112+
(
113+
cd repo_d &&
114+
test_commit d_master &&
115+
git checkout -b baz &&
116+
test_commit f_baz
117+
git checkout -b eggs &&
118+
test_commit c_eggs
119+
) &&
120+
git remote add repo_c repo_c &&
121+
git config remote.repo_c.fetch \
122+
"+refs/heads/*:refs/remotes/extra_dir/repo_c/extra_dir/*" &&
123+
git remote add repo_d repo_d &&
124+
git config remote.repo_d.fetch \
125+
"+refs/heads/*:refs/repo_d/*" &&
126+
git fetch --all
127+
'
128+
129+
test_expect_failure 'checkout of branch from multiple remotes fails #2' '
130+
git checkout -B master &&
131+
test_might_fail git branch -D bar &&
132+
133+
test_must_fail git checkout bar &&
134+
test_must_fail git rev-parse --verify refs/heads/bar &&
135+
test_branch master
136+
'
137+
138+
test_expect_failure 'checkout of branch from multiple remotes fails #3' '
139+
git checkout -B master &&
140+
test_might_fail git branch -D baz &&
141+
142+
test_must_fail git checkout baz &&
143+
test_must_fail git rev-parse --verify refs/heads/baz &&
144+
test_branch master
145+
'
146+
147+
test_expect_failure 'checkout of branch from a single remote succeeds #3' '
148+
git checkout -B master &&
149+
test_might_fail git branch -D spam &&
150+
151+
git checkout spam &&
152+
test_branch spam &&
153+
test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
154+
test_branch_upstream spam repo_c spam
155+
'
156+
157+
test_expect_failure 'checkout of branch from a single remote succeeds #4' '
158+
git checkout -B master &&
159+
test_might_fail git branch -D eggs &&
160+
161+
git checkout eggs &&
162+
test_branch eggs &&
163+
test_cmp_rev refs/repo_d/eggs HEAD &&
164+
test_branch_upstream eggs repo_d eggs
165+
'
166+
99167
test_done

0 commit comments

Comments
 (0)