3 test_description
='compare & swap push force/delete safety'
7 setup_srcdst_basic
() {
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
23 test_expect_success
'push to update (protected)' '
28 test_must_fail git push --force-with-lease=master:master origin master 2>err &&
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)' '
41 git push --force --force-with-lease=master:master origin master 2>err &&
42 grep "forced update" err
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)' '
53 git checkout master &&
57 git ls-remote src refs/heads/master >expect &&
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
66 git ls-remote src refs/heads/master >actual &&
67 test_cmp expect actual
70 test_expect_success
'push to update (protected, tracking, forced)' '
74 git checkout master &&
81 git ls-remote . refs/remotes/origin/master >expect &&
82 git push --force --force-with-lease=master origin master
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)' '
94 git push --force-with-lease=master:master^ origin master
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 &&
106 git push --force-with-lease=master origin master 2>err &&
107 ! grep "forced update" err
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 &&
118 git reset --hard HEAD^ &&
120 git push --force-with-lease=master origin master 2>err &&
121 grep "forced update" err
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 &&
133 test_must_fail git push --force-with-lease=master:master^ origin :master
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 &&
143 git push --force --force-with-lease=master:master^ origin :master
145 git ls-remote src refs/heads/master >actual &&
146 test_must_be_empty actual
149 test_expect_success
'push to delete (allowed)' '
150 setup_srcdst_basic &&
153 git push --force-with-lease=master origin :master 2>err &&
156 git ls-remote src refs/heads/master >actual &&
157 test_must_be_empty actual
160 test_expect_success
'cover everything with default force-with-lease (protected)' '
161 setup_srcdst_basic &&
164 git branch naster master^
166 git ls-remote src refs/heads/\* >expect &&
169 test_must_fail git push --force-with-lease origin master master:naster
171 git ls-remote src refs/heads/\* >actual &&
172 test_cmp expect actual
175 test_expect_success
'cover everything with default force-with-lease (allowed)' '
176 setup_srcdst_basic &&
179 git branch naster master^
184 git push --force-with-lease origin master master:naster
186 git ls-remote dst refs/heads/master |
187 sed -e "s/master/naster/" >expect &&
188 git ls-remote src refs/heads/naster >actual &&
189 test_cmp expect actual
192 test_expect_success
'new branch covered by force-with-lease' '
193 setup_srcdst_basic &&
196 git branch branch master &&
197 git push --force-with-lease=branch origin branch
199 git ls-remote dst refs/heads/branch >expect &&
200 git ls-remote src refs/heads/branch >actual &&
201 test_cmp expect actual
204 test_expect_success
'new branch covered by force-with-lease (explicit)' '
205 setup_srcdst_basic &&
208 git branch branch master &&
209 git push --force-with-lease=branch: origin branch
211 git ls-remote dst refs/heads/branch >expect &&
212 git ls-remote src refs/heads/branch >actual &&
213 test_cmp expect actual
216 test_expect_success
'new branch already exists' '
217 setup_srcdst_basic &&
220 git checkout -b branch master &&
225 git branch branch master &&
226 test_must_fail git push --force-with-lease=branch: origin branch
230 test_expect_success
'background updates of REMOTE can be mitigated with a non-updated REMOTE-push' '
232 git init --bare src.bare &&
233 test_when_finished "rm -rf src.bare" &&
234 git clone --no-local src.bare dst &&
235 test_when_finished "rm -rf dst" &&
239 git remote add origin-push ../src.bare &&
240 git push origin-push master:master
242 git clone --no-local src.bare dst2 &&
243 test_when_finished "rm -rf dst2" &&
253 test_must_fail git push --force-with-lease origin-push &&
254 git fetch origin-push &&
255 git push --force-with-lease origin-push