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
30 git ls-remote . refs/heads/master >expect &&
31 git ls-remote src refs/heads/master >actual &&
32 test_cmp expect actual
35 test_expect_success 'push to update (protected, forced)' '
40 git push --force --force-with-lease=master:master origin master
42 git ls-remote dst refs/heads/master >expect &&
43 git ls-remote src refs/heads/master >actual &&
44 test_cmp expect actual
47 test_expect_success 'push to update (protected, tracking)' '
51 git checkout master &&
55 git ls-remote src refs/heads/master >expect &&
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
64 git ls-remote src refs/heads/master >actual &&
65 test_cmp expect actual
68 test_expect_success 'push to update (protected, tracking, forced)' '
72 git checkout master &&
79 git ls-remote . refs/remotes/origin/master >expect &&
80 git push --force --force-with-lease=master origin master
82 git ls-remote dst refs/heads/master >expect &&
83 git ls-remote src refs/heads/master >actual &&
84 test_cmp expect actual
87 test_expect_success 'push to update (allowed)' '
92 git push --force-with-lease=master:master^ origin master
94 git ls-remote dst refs/heads/master >expect &&
95 git ls-remote src refs/heads/master >actual &&
96 test_cmp expect actual
99 test_expect_success 'push to update (allowed, tracking)' '
100 setup_srcdst_basic &&
104 git push --force-with-lease=master origin master
106 git ls-remote dst refs/heads/master >expect &&
107 git ls-remote src refs/heads/master >actual &&
108 test_cmp expect actual
111 test_expect_success 'push to update (allowed even though no-ff)' '
112 setup_srcdst_basic &&
115 git reset --hard HEAD^ &&
117 git push --force-with-lease=master origin master
119 git ls-remote dst refs/heads/master >expect &&
120 git ls-remote src refs/heads/master >actual &&
121 test_cmp expect actual
124 test_expect_success 'push to delete (protected)' '
125 setup_srcdst_basic &&
126 git ls-remote src refs/heads/master >expect &&
129 test_must_fail git push --force-with-lease=master:master^ origin :master
131 git ls-remote src refs/heads/master >actual &&
132 test_cmp expect actual
135 test_expect_success 'push to delete (protected, forced)' '
136 setup_srcdst_basic &&
139 git push --force --force-with-lease=master:master^ origin :master
142 git ls-remote src refs/heads/master >actual &&
143 test_cmp expect actual
146 test_expect_success 'push to delete (allowed)' '
147 setup_srcdst_basic &&
150 git push --force-with-lease=master origin :master
153 git ls-remote src refs/heads/master >actual &&
154 test_cmp expect actual
157 test_expect_success 'cover everything with default force-with-lease (protected)' '
158 setup_srcdst_basic &&
161 git branch naster master^
163 git ls-remote src refs/heads/\* >expect &&
166 test_must_fail git push --force-with-lease origin master master:naster
168 git ls-remote src refs/heads/\* >actual &&
169 test_cmp expect actual
172 test_expect_success 'cover everything with default force-with-lease (allowed)' '
173 setup_srcdst_basic &&
176 git branch naster master^
181 git push --force-with-lease origin master master:naster
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