Merge branch 'maint-1.6.4' into maint
[git/gitweb.git] / t / t5400-send-pack.sh
blobf2d5581b12f7d70c9f346da75dced81e12bd4c7f
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='See why rewinding head breaks send-pack
9 . ./test-lib.sh
11 cnt=64
12 test_expect_success setup '
13 test_tick &&
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) &&
19 zero=$commit &&
20 parent=$zero &&
21 i=0 &&
22 while test $i -le $cnt
24 i=$(($i+1)) &&
25 test_tick &&
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
32 done &&
33 git update-ref HEAD "$commit" &&
34 git clone ./. victim &&
35 ( cd victim && git log ) &&
36 git update-ref HEAD "$zero" &&
37 parent=$zero &&
38 i=0 &&
39 while test $i -le $cnt
41 i=$(($i+1)) &&
42 test_tick &&
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
49 done &&
50 git update-ref HEAD "$commit" &&
51 echo Rebase &&
52 git log'
54 test_expect_success 'pack the source repository' '
55 git repack -a -d &&
56 git prune
59 test_expect_success 'pack the destination repository' '
61 cd victim &&
62 git repack -a -d &&
63 git prune
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" &&
73 # this should update
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 \
80 'push can be used to delete a ref' '
81 ( cd victim && git branch extra master ) &&
82 git send-pack ./victim :extra master &&
83 ( cd victim &&
84 test_must_fail git rev-parse --verify extra )
87 test_expect_success 'refuse deleting push with denyDeletes' '
89 cd victim &&
90 ( git branch -D extra || : ) &&
91 git config receive.denyDeletes true &&
92 git branch extra master
93 ) &&
94 test_must_fail git send-pack ./victim :extra master
97 test_expect_success 'denyNonFastforwards trumps --force' '
99 cd victim &&
100 ( git branch -D extra || : ) &&
101 git config receive.denyNonFastforwards true
102 ) &&
103 victim_orig=$(cd victim && git rev-parse --verify master) &&
104 test_must_fail git send-pack --force ./victim master^:master &&
105 victim_head=$(cd victim && git rev-parse --verify master) &&
106 test "$victim_orig" = "$victim_head"
109 test_expect_success 'push --all excludes remote tracking hierarchy' '
110 mkdir parent &&
112 cd parent &&
113 git init && : >file && git add file && git commit -m add
114 ) &&
115 git clone parent child &&
117 cd child && git push --all
118 ) &&
120 cd parent &&
121 test -z "$(git for-each-ref refs/remotes/origin)"
125 rewound_push_setup() {
126 rm -rf parent child &&
127 mkdir parent &&
129 cd parent &&
130 git init &&
131 echo one >file && git add file && git commit -m one &&
132 echo two >file && git commit -a -m two
133 ) &&
134 git clone parent child &&
136 cd child && git reset --hard HEAD^
140 rewound_push_succeeded() {
141 cmp ../parent/.git/refs/heads/master .git/refs/heads/master
144 rewound_push_failed() {
145 if rewound_push_succeeded
146 then
147 false
148 else
149 true
153 test_expect_success 'pushing explicit refspecs respects forcing' '
154 rewound_push_setup &&
155 parent_orig=$(cd parent && git rev-parse --verify master) &&
157 cd child &&
158 test_must_fail git send-pack ../parent \
159 refs/heads/master:refs/heads/master
160 ) &&
161 parent_head=$(cd parent && git rev-parse --verify master) &&
162 test "$parent_orig" = "$parent_head" &&
164 cd child &&
165 git send-pack ../parent \
166 +refs/heads/master:refs/heads/master
167 ) &&
168 parent_head=$(cd parent && git rev-parse --verify master) &&
169 child_head=$(cd parent && git rev-parse --verify master) &&
170 test "$parent_head" = "$child_head"
173 test_expect_success 'pushing wildcard refspecs respects forcing' '
174 rewound_push_setup &&
175 parent_orig=$(cd parent && git rev-parse --verify master) &&
177 cd child &&
178 test_must_fail git send-pack ../parent \
179 "refs/heads/*:refs/heads/*"
180 ) &&
181 parent_head=$(cd parent && git rev-parse --verify master) &&
182 test "$parent_orig" = "$parent_head" &&
184 cd child &&
185 git send-pack ../parent \
186 "+refs/heads/*:refs/heads/*"
187 ) &&
188 parent_head=$(cd parent && git rev-parse --verify master) &&
189 child_head=$(cd parent && git rev-parse --verify master) &&
190 test "$parent_head" = "$child_head"
193 test_expect_success 'warn pushing to delete current branch' '
194 rewound_push_setup &&
196 cd child &&
197 git send-pack ../parent :refs/heads/master 2>errs
198 ) &&
199 grep "warning: to refuse deleting" child/errs &&
201 cd parent &&
202 test_must_fail git rev-parse --verify master
206 test_done