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 <jrnieder@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Apr 21, 2013 at 23:52 UTC
ec2764ee8fb9a37cc92e0a1bce3b49ae2de0ffbc
1 file changed
+69
-1
t/t2024-checkout-dwim.sh
+69
-1
@@ -24,6 +24,7 @@ test_branch_upstream () {
24
}
25
26
test_expect_success 'setup' '
27
+ test_commit my_master &&
28
git init repo_a &&
29
(
30
cd repo_a &&
@@ -58,7 +59,7 @@ test_expect_success 'checkout of non-existing branch fails' '
59
test_branch master
60
'
61
61
-test_expect_success 'checkout of branch from multiple remotes fails' '
62
+test_expect_success 'checkout of branch from multiple remotes fails #1' '
63
git checkout -B master &&
64
test_might_fail git branch -D foo &&
65
@@ -96,4 +97,71 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '
97
test_branch master
98
'
99
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
+
167
test_done