t5533: test "push --force-with-lease"

Prepare two repositories, src and dst, the latter of which is a clone of the former (with tracking branches), and push from the latter into the former, with various --force-with-lease options. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 9, 2013 at 12:09 UTC d887cc184d49f5e8982c1db433996fae26fb20c0
1 file changed +189
t/t5533-push-cas.sh new
+189
@@ -0,0 +1,189 @@
1 +#!/bin/sh
2 +
3 +test_description='compare & swap push force/delete safety'
4 +
5 +. ./test-lib.sh
6 +
7 +setup_srcdst_basic () {
8 + rm -fr src dst &&
9 + git clone --no-local . src &&
10 + git clone --no-local src dst &&
11 + (
12 + cd src && git checkout HEAD^0
13 + )
14 +}
15 +
16 +test_expect_success setup '
17 + : create template repository
18 + test_commit A &&
19 + test_commit B &&
20 + test_commit C
21 +'
22 +
23 +test_expect_success 'push to update (protected)' '
24 + setup_srcdst_basic &&
25 + (
26 + cd dst &&
27 + test_commit D &&
28 + test_must_fail git push --force-with-lease=master:master origin master
29 + ) &&
30 + git ls-remote . refs/heads/master >expect &&
31 + git ls-remote src refs/heads/master >actual &&
32 + test_cmp expect actual
33 +'
34 +
35 +test_expect_success 'push to update (protected, forced)' '
36 + setup_srcdst_basic &&
37 + (
38 + cd dst &&
39 + test_commit D &&
40 + git push --force --force-with-lease=master:master origin master
41 + ) &&
42 + git ls-remote dst refs/heads/master >expect &&
43 + git ls-remote src refs/heads/master >actual &&
44 + test_cmp expect actual
45 +'
46 +
47 +test_expect_success 'push to update (protected, tracking)' '
48 + setup_srcdst_basic &&
49 + (
50 + cd src &&
51 + git checkout master &&
52 + test_commit D &&
53 + git checkout HEAD^0
54 + ) &&
55 + git ls-remote src refs/heads/master >expect &&
56 + (
57 + cd dst &&
58 + test_commit E &&
59 + git ls-remote . refs/remotes/origin/master >expect &&
60 + test_must_fail git push --force-with-lease=master origin master &&
61 + git ls-remote . refs/remotes/origin/master >actual &&
62 + test_cmp expect actual
63 + ) &&
64 + git ls-remote src refs/heads/master >actual &&
65 + test_cmp expect actual
66 +'
67 +
68 +test_expect_success 'push to update (protected, tracking, forced)' '
69 + setup_srcdst_basic &&
70 + (
71 + cd src &&
72 + git checkout master &&
73 + test_commit D &&
74 + git checkout HEAD^0
75 + ) &&
76 + (
77 + cd dst &&
78 + test_commit E &&
79 + git ls-remote . refs/remotes/origin/master >expect &&
80 + git push --force --force-with-lease=master origin master
81 + ) &&
82 + git ls-remote dst refs/heads/master >expect &&
83 + git ls-remote src refs/heads/master >actual &&
84 + test_cmp expect actual
85 +'
86 +
87 +test_expect_success 'push to update (allowed)' '
88 + setup_srcdst_basic &&
89 + (
90 + cd dst &&
91 + test_commit D &&
92 + git push --force-with-lease=master:master^ origin master
93 + ) &&
94 + git ls-remote dst refs/heads/master >expect &&
95 + git ls-remote src refs/heads/master >actual &&
96 + test_cmp expect actual
97 +'
98 +
99 +test_expect_success 'push to update (allowed, tracking)' '
100 + setup_srcdst_basic &&
101 + (
102 + cd dst &&
103 + test_commit D &&
104 + git push --force-with-lease=master origin master
105 + ) &&
106 + git ls-remote dst refs/heads/master >expect &&
107 + git ls-remote src refs/heads/master >actual &&
108 + test_cmp expect actual
109 +'
110 +
111 +test_expect_success 'push to update (allowed even though no-ff)' '
112 + setup_srcdst_basic &&
113 + (
114 + cd dst &&
115 + git reset --hard HEAD^ &&
116 + test_commit D &&
117 + git push --force-with-lease=master origin master
118 + ) &&
119 + git ls-remote dst refs/heads/master >expect &&
120 + git ls-remote src refs/heads/master >actual &&
121 + test_cmp expect actual
122 +'
123 +
124 +test_expect_success 'push to delete (protected)' '
125 + setup_srcdst_basic &&
126 + git ls-remote src refs/heads/master >expect &&
127 + (
128 + cd dst &&
129 + test_must_fail git push --force-with-lease=master:master^ origin :master
130 + ) &&
131 + git ls-remote src refs/heads/master >actual &&
132 + test_cmp expect actual
133 +'
134 +
135 +test_expect_success 'push to delete (protected, forced)' '
136 + setup_srcdst_basic &&
137 + (
138 + cd dst &&
139 + git push --force --force-with-lease=master:master^ origin :master
140 + ) &&
141 + >expect &&
142 + git ls-remote src refs/heads/master >actual &&
143 + test_cmp expect actual
144 +'
145 +
146 +test_expect_success 'push to delete (allowed)' '
147 + setup_srcdst_basic &&
148 + (
149 + cd dst &&
150 + git push --force-with-lease=master origin :master
151 + ) &&
152 + >expect &&
153 + git ls-remote src refs/heads/master >actual &&
154 + test_cmp expect actual
155 +'
156 +
157 +test_expect_success 'cover everything with default force-with-lease (protected)' '
158 + setup_srcdst_basic &&
159 + (
160 + cd src &&
161 + git branch naster master^
162 + )
163 + git ls-remote src refs/heads/\* >expect &&
164 + (
165 + cd dst &&
166 + test_must_fail git push --force-with-lease origin master master:naster
167 + ) &&
168 + git ls-remote src refs/heads/\* >actual &&
169 + test_cmp expect actual
170 +'
171 +
172 +test_expect_success 'cover everything with default force-with-lease (allowed)' '
173 + setup_srcdst_basic &&
174 + (
175 + cd src &&
176 + git branch naster master^
177 + )
178 + (
179 + cd dst &&
180 + git fetch &&
181 + git push --force-with-lease origin master master:naster
182 + ) &&
183 + git ls-remote dst refs/heads/master |
184 + sed -e "s/master/naster/" >expect &&
185 + git ls-remote src refs/heads/naster >actual &&
186 + test_cmp expect actual
187 +'
188 +
189 +test_done