15
)
16
}
17
18
+mk_test () {
19
+ mk_empty &&
20
+ (
21
+ for ref in "$@"
22
+ do
23
+ git push testrepo $the_first_commit:refs/$ref || {
24
+ echo "Oops, push refs/$ref failure"
25
+ exit 1
26
+ }
27
+ done &&
28
+ cd testrepo &&
29
+ for ref in "$@"
30
+ do
31
+ r=$(git show-ref -s --verify refs/$ref) &&
32
+ test "z$r" = "z$the_first_commit" || {
33
+ echo "Oops, refs/$ref is wrong"
34
+ exit 1
35
+ }
36
+ done &&
37
+ git fsck --full
38
+ )
39
+}
40
+
41
+check_push_result () {
42
+ (
43
+ cd testrepo &&
44
+ it="$1" &&
45
+ shift
46
+ for ref in "$@"
47
+ do
48
+ r=$(git show-ref -s --verify refs/$ref) &&
49
+ test "z$r" = "z$it" || {
50
+ echo "Oops, refs/$ref is wrong"
51
+ exit 1
52
+ }
53
+ done &&
54
+ git fsck --full
55
+ )
56
+}
57
+
58
test_expect_success setup '
59
60
: >path1 &&
61
git add path1 &&
62
test_tick &&
63
git commit -a -m repo &&
64
+ the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
65
+
66
+ : >path2 &&
67
+ git add path2 &&
68
+ test_tick &&
69
+ git commit -a -m second &&
70
the_commit=$(git show-ref -s --verify refs/heads/master)
71
72
'
125
)
126
'
127
128
+test_expect_success 'push with matching heads' '
129
+
130
+ mk_test heads/master &&
131
+ git push testrepo &&
132
+ check_push_result $the_commit heads/master
133
+
134
+'
135
+
136
+test_expect_success 'push with no ambiguity (1)' '
137
+
138
+ mk_test heads/master &&
139
+ git push testrepo master:master &&
140
+ check_push_result $the_commit heads/master
141
+
142
+'
143
+
144
+test_expect_success 'push with no ambiguity (2)' '
145
+
146
+ mk_test remotes/origin/master &&
147
+ git push testrepo master:master &&
148
+ check_push_result $the_commit remotes/origin/master
149
+
150
+'
151
+
152
+test_expect_success 'push with weak ambiguity (1)' '
153
+
154
+ mk_test heads/master remotes/origin/master &&
155
+ git push testrepo master:master &&
156
+ check_push_result $the_commit heads/master &&
157
+ check_push_result $the_first_commit remotes/origin/master
158
+
159
+'
160
+
161
+test_expect_success 'push with weak ambiguity (2)' '
162
+
163
+ mk_test heads/master remotes/origin/master remotes/another/master &&
164
+ git push testrepo master:master &&
165
+ check_push_result $the_commit heads/master &&
166
+ check_push_result $the_first_commit remotes/origin/master remotes/another/master
167
+
168
+'
169
+
170
+test_expect_success 'push with ambiguity (1)' '
171
+
172
+ mk_test remotes/origin/master remotes/frotz/master &&
173
+ if git push testrepo master:master
174
+ then
175
+ echo "Oops, should have failed"
176
+ false
177
+ else
178
+ check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
179
+ fi
180
+'
181
+
182
+test_expect_success 'push with ambiguity (2)' '
183
+
184
+ mk_test heads/frotz tags/frotz &&
185
+ if git push testrepo master:frotz
186
+ then
187
+ echo "Oops, should have failed"
188
+ false
189
+ else
190
+ check_push_result $the_first_commit heads/frotz tags/frotz
191
+ fi
192
+'
193
+
194
test_done