3 # Copyright (c) 2005 Junio C Hamano
6 test_description='See why rewinding head breaks send-pack
12 test_expect_success setup '
14 mkdir mozart mozart/is &&
15 echo "Commit #0" >mozart/is/pink &&
16 git update-index --add mozart/is/pink &&
17 tree=$(git write-tree) &&
18 commit=$(echo "Commit #0" | git commit-tree $tree) &&
22 while test $i -le $cnt
26 echo "Commit #$i" >mozart/is/pink &&
27 git update-index --add mozart/is/pink &&
28 tree=$(git write-tree) &&
29 commit=$(echo "Commit #$i" | git commit-tree $tree -p $parent) &&
30 git update-ref refs/tags/commit$i $commit &&
31 parent=$commit || return 1
33 git update-ref HEAD "$commit" &&
34 git clone ./. victim &&
35 ( cd victim && git config receive.denyCurrentBranch warn && git log ) &&
36 git update-ref HEAD "$zero" &&
39 while test $i -le $cnt
43 echo "Rebase #$i" >mozart/is/pink &&
44 git update-index --add mozart/is/pink &&
45 tree=$(git write-tree) &&
46 commit=$(echo "Rebase #$i" | git commit-tree $tree -p $parent) &&
47 git update-ref refs/tags/rebase$i $commit &&
48 parent=$commit || return 1
50 git update-ref HEAD "$commit" &&
54 test_expect_success 'pack the source repository' '
59 test_expect_success 'pack the destination repository' '
67 test_expect_success 'refuse pushing rewound head without --force' '
68 pushed_head=$(git rev-parse --verify master) &&
69 victim_orig=$(cd victim && git rev-parse --verify master) &&
70 test_must_fail git send-pack ./victim master &&
71 victim_head=$(cd victim && git rev-parse --verify master) &&
72 test "$victim_head" = "$victim_orig" &&
74 git send-pack --force ./victim master &&
75 victim_head=$(cd victim && git rev-parse --verify master) &&
76 test "$victim_head" = "$pushed_head"
80 'push can be used to delete a ref' '
81 ( cd victim && git branch extra master ) &&
82 git send-pack ./victim :extra master &&
84 test_must_fail git rev-parse --verify extra )
87 test_expect_success 'refuse deleting push with denyDeletes' '
90 ( git branch -D extra || : ) &&
91 git config receive.denyDeletes true &&
92 git branch extra master
94 test_must_fail git send-pack ./victim :extra master
97 test_expect_success 'cannot override denyDeletes with git -c send-pack' '
100 test_might_fail git branch -D extra &&
101 git config receive.denyDeletes true &&
102 git branch extra master
104 test_must_fail git -c receive.denyDeletes=false \
105 send-pack ./victim :extra master
108 test_expect_success 'override denyDeletes with git -c receive-pack' '
111 test_might_fail git branch -D extra &&
112 git config receive.denyDeletes true &&
113 git branch extra master
116 --receive-pack="git -c receive.denyDeletes=false receive-pack" \
117 ./victim :extra master
120 test_expect_success 'denyNonFastforwards trumps --force' '
123 ( git branch -D extra || : ) &&
124 git config receive.denyNonFastforwards true
126 victim_orig=$(cd victim && git rev-parse --verify master) &&
127 test_must_fail git send-pack --force ./victim master^:master &&
128 victim_head=$(cd victim && git rev-parse --verify master) &&
129 test "$victim_orig" = "$victim_head"
132 test_expect_success 'push --all excludes remote tracking hierarchy' '
136 git init && : >file && git add file && git commit -m add
138 git clone parent child &&
140 cd child && git push --all
144 test -z "$(git for-each-ref refs/remotes/origin)"
148 rewound_push_setup() {
149 rm -rf parent child &&
154 echo one >file && git add file && git commit -m one &&
155 git config receive.denyCurrentBranch warn &&
156 echo two >file && git commit -a -m two
158 git clone parent child &&
160 cd child && git reset --hard HEAD^
164 rewound_push_succeeded() {
165 cmp ../parent/.git/refs/heads/master .git/refs/heads/master
168 rewound_push_failed() {
169 if rewound_push_succeeded
177 test_expect_success 'pushing explicit refspecs respects forcing' '
178 rewound_push_setup &&
179 parent_orig=$(cd parent && git rev-parse --verify master) &&
182 test_must_fail git send-pack ../parent \
183 refs/heads/master:refs/heads/master
185 parent_head=$(cd parent && git rev-parse --verify master) &&
186 test "$parent_orig" = "$parent_head" &&
189 git send-pack ../parent \
190 +refs/heads/master:refs/heads/master
192 parent_head=$(cd parent && git rev-parse --verify master) &&
193 child_head=$(cd parent && git rev-parse --verify master) &&
194 test "$parent_head" = "$child_head"
197 test_expect_success 'pushing wildcard refspecs respects forcing' '
198 rewound_push_setup &&
199 parent_orig=$(cd parent && git rev-parse --verify master) &&
202 test_must_fail git send-pack ../parent \
203 "refs/heads/*:refs/heads/*"
205 parent_head=$(cd parent && git rev-parse --verify master) &&
206 test "$parent_orig" = "$parent_head" &&
209 git send-pack ../parent \
210 "+refs/heads/*:refs/heads/*"
212 parent_head=$(cd parent && git rev-parse --verify master) &&
213 child_head=$(cd parent && git rev-parse --verify master) &&
214 test "$parent_head" = "$child_head"
217 test_expect_success 'deny pushing to delete current branch' '
218 rewound_push_setup &&
221 test_must_fail git send-pack ../parent :refs/heads/master 2>errs