log: add -P as a synonym for --perl-regexp
[alt-git.git] / t / t5533-push-cas.sh
blobd38ecee2172a6e5599cfbeb18e472816e98e553c
1 #!/bin/sh
3 test_description='compare & swap push force/delete safety'
5 . ./test-lib.sh
7 setup_srcdst_basic () {
8 rm -fr src dst &&
9 git clone --no-local . src &&
10 git clone --no-local src dst &&
12 cd src && git checkout HEAD^0
16 test_expect_success setup '
17 # create template repository
18 test_commit A &&
19 test_commit B &&
20 test_commit C
23 test_expect_success 'push to update (protected)' '
24 setup_srcdst_basic &&
26 cd dst &&
27 test_commit D &&
28 test_must_fail git push --force-with-lease=master:master origin master 2>err &&
29 grep "stale info" err
30 ) &&
31 git ls-remote . refs/heads/master >expect &&
32 git ls-remote src refs/heads/master >actual &&
33 test_cmp expect actual
36 test_expect_success 'push to update (protected, forced)' '
37 setup_srcdst_basic &&
39 cd dst &&
40 test_commit D &&
41 git push --force --force-with-lease=master:master origin master 2>err &&
42 grep "forced update" err
43 ) &&
44 git ls-remote dst refs/heads/master >expect &&
45 git ls-remote src refs/heads/master >actual &&
46 test_cmp expect actual
49 test_expect_success 'push to update (protected, tracking)' '
50 setup_srcdst_basic &&
52 cd src &&
53 git checkout master &&
54 test_commit D &&
55 git checkout HEAD^0
56 ) &&
57 git ls-remote src refs/heads/master >expect &&
59 cd dst &&
60 test_commit E &&
61 git ls-remote . refs/remotes/origin/master >expect &&
62 test_must_fail git push --force-with-lease=master origin master &&
63 git ls-remote . refs/remotes/origin/master >actual &&
64 test_cmp expect actual
65 ) &&
66 git ls-remote src refs/heads/master >actual &&
67 test_cmp expect actual
70 test_expect_success 'push to update (protected, tracking, forced)' '
71 setup_srcdst_basic &&
73 cd src &&
74 git checkout master &&
75 test_commit D &&
76 git checkout HEAD^0
77 ) &&
79 cd dst &&
80 test_commit E &&
81 git ls-remote . refs/remotes/origin/master >expect &&
82 git push --force --force-with-lease=master origin master
83 ) &&
84 git ls-remote dst refs/heads/master >expect &&
85 git ls-remote src refs/heads/master >actual &&
86 test_cmp expect actual
89 test_expect_success 'push to update (allowed)' '
90 setup_srcdst_basic &&
92 cd dst &&
93 test_commit D &&
94 git push --force-with-lease=master:master^ origin master
95 ) &&
96 git ls-remote dst refs/heads/master >expect &&
97 git ls-remote src refs/heads/master >actual &&
98 test_cmp expect actual
101 test_expect_success 'push to update (allowed, tracking)' '
102 setup_srcdst_basic &&
104 cd dst &&
105 test_commit D &&
106 git push --force-with-lease=master origin master 2>err &&
107 ! grep "forced update" err
108 ) &&
109 git ls-remote dst refs/heads/master >expect &&
110 git ls-remote src refs/heads/master >actual &&
111 test_cmp expect actual
114 test_expect_success 'push to update (allowed even though no-ff)' '
115 setup_srcdst_basic &&
117 cd dst &&
118 git reset --hard HEAD^ &&
119 test_commit D &&
120 git push --force-with-lease=master origin master 2>err &&
121 grep "forced update" err
122 ) &&
123 git ls-remote dst refs/heads/master >expect &&
124 git ls-remote src refs/heads/master >actual &&
125 test_cmp expect actual
128 test_expect_success 'push to delete (protected)' '
129 setup_srcdst_basic &&
130 git ls-remote src refs/heads/master >expect &&
132 cd dst &&
133 test_must_fail git push --force-with-lease=master:master^ origin :master
134 ) &&
135 git ls-remote src refs/heads/master >actual &&
136 test_cmp expect actual
139 test_expect_success 'push to delete (protected, forced)' '
140 setup_srcdst_basic &&
142 cd dst &&
143 git push --force --force-with-lease=master:master^ origin :master
144 ) &&
145 >expect &&
146 git ls-remote src refs/heads/master >actual &&
147 test_cmp expect actual
150 test_expect_success 'push to delete (allowed)' '
151 setup_srcdst_basic &&
153 cd dst &&
154 git push --force-with-lease=master origin :master 2>err &&
155 grep deleted err
156 ) &&
157 >expect &&
158 git ls-remote src refs/heads/master >actual &&
159 test_cmp expect actual
162 test_expect_success 'cover everything with default force-with-lease (protected)' '
163 setup_srcdst_basic &&
165 cd src &&
166 git branch naster master^
167 ) &&
168 git ls-remote src refs/heads/\* >expect &&
170 cd dst &&
171 test_must_fail git push --force-with-lease origin master master:naster
172 ) &&
173 git ls-remote src refs/heads/\* >actual &&
174 test_cmp expect actual
177 test_expect_success 'cover everything with default force-with-lease (allowed)' '
178 setup_srcdst_basic &&
180 cd src &&
181 git branch naster master^
182 ) &&
184 cd dst &&
185 git fetch &&
186 git push --force-with-lease origin master master:naster
187 ) &&
188 git ls-remote dst refs/heads/master |
189 sed -e "s/master/naster/" >expect &&
190 git ls-remote src refs/heads/naster >actual &&
191 test_cmp expect actual
194 test_expect_success 'new branch covered by force-with-lease' '
195 setup_srcdst_basic &&
197 cd dst &&
198 git branch branch master &&
199 git push --force-with-lease=branch origin branch
200 ) &&
201 git ls-remote dst refs/heads/branch >expect &&
202 git ls-remote src refs/heads/branch >actual &&
203 test_cmp expect actual
206 test_expect_success 'new branch covered by force-with-lease (explicit)' '
207 setup_srcdst_basic &&
209 cd dst &&
210 git branch branch master &&
211 git push --force-with-lease=branch: origin branch
212 ) &&
213 git ls-remote dst refs/heads/branch >expect &&
214 git ls-remote src refs/heads/branch >actual &&
215 test_cmp expect actual
218 test_expect_success 'new branch already exists' '
219 setup_srcdst_basic &&
221 cd src &&
222 git checkout -b branch master &&
223 test_commit F
224 ) &&
226 cd dst &&
227 git branch branch master &&
228 test_must_fail git push --force-with-lease=branch: origin branch
232 test_expect_success 'background updates of REMOTE can be mitigated with a non-updated REMOTE-push' '
233 rm -rf src dst &&
234 git init --bare src.bare &&
235 test_when_finished "rm -rf src.bare" &&
236 git clone --no-local src.bare dst &&
237 test_when_finished "rm -rf dst" &&
239 cd dst &&
240 test_commit G &&
241 git remote add origin-push ../src.bare &&
242 git push origin-push master:master
243 ) &&
244 git clone --no-local src.bare dst2 &&
245 test_when_finished "rm -rf dst2" &&
247 cd dst2 &&
248 test_commit H &&
249 git push
250 ) &&
252 cd dst &&
253 test_commit I &&
254 git fetch origin &&
255 test_must_fail git push --force-with-lease origin-push &&
256 git fetch origin-push &&
257 git push --force-with-lease origin-push
261 test_done