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"
79 test_expect_success
'push can be used to delete a ref' '
80 ( cd victim && git branch extra master ) &&
81 git send-pack ./victim :extra master &&
83 test_must_fail git rev-parse --verify extra )
86 test_expect_success
'refuse deleting push with denyDeletes' '
89 ( git branch -D extra || : ) &&
90 git config receive.denyDeletes true &&
91 git branch extra master
93 test_must_fail git send-pack ./victim :extra master
96 test_expect_success
'cannot override denyDeletes with git -c send-pack' '
99 test_might_fail git branch -D extra &&
100 git config receive.denyDeletes true &&
101 git branch extra master
103 test_must_fail git -c receive.denyDeletes=false \
104 send-pack ./victim :extra master
107 test_expect_success
'override denyDeletes with git -c receive-pack' '
110 test_might_fail git branch -D extra &&
111 git config receive.denyDeletes true &&
112 git branch extra master
115 --receive-pack="git -c receive.denyDeletes=false receive-pack" \
116 ./victim :extra master
119 test_expect_success
'denyNonFastforwards trumps --force' '
122 ( git branch -D extra || : ) &&
123 git config receive.denyNonFastforwards true
125 victim_orig=$(cd victim && git rev-parse --verify master) &&
126 test_must_fail git send-pack --force ./victim master^:master &&
127 victim_head=$(cd victim && git rev-parse --verify master) &&
128 test "$victim_orig" = "$victim_head"
131 test_expect_success
'push --all excludes remote-tracking hierarchy' '
135 git init && : >file && git add file && git commit -m add
137 git clone parent child &&
139 cd child && git push --all
143 test -z "$(git for-each-ref refs/remotes/origin)"
147 test_expect_success
'receive-pack runs auto-gc in remote repo' '
148 rm -rf parent child &&
151 # Setup a repo with 2 packs
153 echo "Some text" >file.txt &&
155 git commit -m "Initial commit" &&
157 echo "Some more text" >>file.txt &&
158 git commit -a -m "Second commit" &&
161 cp -R parent child &&
163 # Set the child to auto-pack if more than one pack exists
165 git config gc.autopacklimit 1 &&
166 git config gc.autodetach false &&
167 git branch test_auto_gc &&
168 # And create a file that follows the temporary object naming
169 # convention for the auto-gc to remove
170 : >.git/objects/tmp_test_object &&
171 test-chmtime =-1209601 .git/objects/tmp_test_object
175 echo "Even more text" >>file.txt &&
176 git commit -a -m "Third commit" &&
177 git send-pack ../child HEAD:refs/heads/test_auto_gc
179 test ! -e child/.git/objects/tmp_test_object
182 rewound_push_setup
() {
183 rm -rf parent child
&&
188 echo one
>file && git add
file && git commit
-m one
&&
189 git config receive.denyCurrentBranch warn
&&
190 echo two
>file && git commit
-a -m two
192 git clone parent child
&&
194 cd child
&& git
reset --hard HEAD^
198 test_expect_success
'pushing explicit refspecs respects forcing' '
199 rewound_push_setup &&
200 parent_orig=$(cd parent && git rev-parse --verify master) &&
203 test_must_fail git send-pack ../parent \
204 refs/heads/master:refs/heads/master
206 parent_head=$(cd parent && git rev-parse --verify master) &&
207 test "$parent_orig" = "$parent_head" &&
210 git send-pack ../parent \
211 +refs/heads/master:refs/heads/master
213 parent_head=$(cd parent && git rev-parse --verify master) &&
214 child_head=$(cd child && git rev-parse --verify master) &&
215 test "$parent_head" = "$child_head"
218 test_expect_success
'pushing wildcard refspecs respects forcing' '
219 rewound_push_setup &&
220 parent_orig=$(cd parent && git rev-parse --verify master) &&
223 test_must_fail git send-pack ../parent \
224 "refs/heads/*:refs/heads/*"
226 parent_head=$(cd parent && git rev-parse --verify master) &&
227 test "$parent_orig" = "$parent_head" &&
230 git send-pack ../parent \
231 "+refs/heads/*:refs/heads/*"
233 parent_head=$(cd parent && git rev-parse --verify master) &&
234 child_head=$(cd child && git rev-parse --verify master) &&
235 test "$parent_head" = "$child_head"
238 test_expect_success
'deny pushing to delete current branch' '
239 rewound_push_setup &&
242 test_must_fail git send-pack ../parent :refs/heads/master 2>errs