]>
Commit | Line | Data |
---|---|---|
bdf25142 LT |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='See why rewinding head breaks send-pack | |
7 | ||
8 | ' | |
9 | . ./test-lib.sh | |
10 | ||
04509738 | 11 | cnt=64 |
bdf25142 | 12 | test_expect_success setup ' |
04509738 JH |
13 | test_tick && |
14 | mkdir mozart mozart/is && | |
15 | echo "Commit #0" >mozart/is/pink && | |
5be60078 JH |
16 | git update-index --add mozart/is/pink && |
17 | tree=$(git write-tree) && | |
18 | commit=$(echo "Commit #0" | git commit-tree $tree) && | |
bdf25142 LT |
19 | zero=$commit && |
20 | parent=$zero && | |
04509738 JH |
21 | i=0 && |
22 | while test $i -le $cnt | |
bdf25142 | 23 | do |
04509738 JH |
24 | i=$(($i+1)) && |
25 | test_tick && | |
26 | echo "Commit #$i" >mozart/is/pink && | |
5be60078 JH |
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 && | |
4d9d62fa | 31 | parent=$commit || return 1 |
bdf25142 | 32 | done && |
5be60078 | 33 | git update-ref HEAD "$commit" && |
3604e7c5 | 34 | git clone ./. victim && |
acd2a45b | 35 | ( cd victim && git config receive.denyCurrentBranch warn && git log ) && |
5be60078 | 36 | git update-ref HEAD "$zero" && |
bdf25142 | 37 | parent=$zero && |
04509738 JH |
38 | i=0 && |
39 | while test $i -le $cnt | |
bdf25142 | 40 | do |
04509738 JH |
41 | i=$(($i+1)) && |
42 | test_tick && | |
43 | echo "Rebase #$i" >mozart/is/pink && | |
5be60078 JH |
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 && | |
4d9d62fa | 48 | parent=$commit || return 1 |
bdf25142 | 49 | done && |
5be60078 | 50 | git update-ref HEAD "$commit" && |
bdf25142 | 51 | echo Rebase && |
5be60078 | 52 | git log' |
bdf25142 | 53 | |
04509738 JH |
54 | test_expect_success 'pack the source repository' ' |
55 | git repack -a -d && | |
026aa938 | 56 | git prune |
04509738 JH |
57 | ' |
58 | ||
59 | test_expect_success 'pack the destination repository' ' | |
2f334155 | 60 | ( |
04509738 JH |
61 | cd victim && |
62 | git repack -a -d && | |
2f334155 JH |
63 | git prune |
64 | ) | |
04509738 JH |
65 | ' |
66 | ||
2f334155 JH |
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" && | |
bdf25142 | 73 | # this should update |
2f334155 JH |
74 | git send-pack --force ./victim master && |
75 | victim_head=$(cd victim && git rev-parse --verify master) && | |
76 | test "$victim_head" = "$pushed_head" | |
bdf25142 | 77 | ' |
da7bc9b0 | 78 | |
d4f694ba JH |
79 | test_expect_success \ |
80 | 'push can be used to delete a ref' ' | |
2f334155 JH |
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 ) | |
d4f694ba JH |
85 | ' |
86 | ||
2f334155 JH |
87 | test_expect_success 'refuse deleting push with denyDeletes' ' |
88 | ( | |
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 | |
a240de11 | 95 | ' |
a240de11 | 96 | |
2f334155 JH |
97 | test_expect_success 'denyNonFastforwards trumps --force' ' |
98 | ( | |
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" | |
199a9218 JS |
107 | ' |
108 | ||
2f334155 JH |
109 | test_expect_success 'push --all excludes remote tracking hierarchy' ' |
110 | mkdir parent && | |
111 | ( | |
112 | cd parent && | |
113 | git init && : >file && git add file && git commit -m add | |
114 | ) && | |
115 | git clone parent child && | |
116 | ( | |
117 | cd child && git push --all | |
118 | ) && | |
119 | ( | |
120 | cd parent && | |
121 | test -z "$(git for-each-ref refs/remotes/origin)" | |
122 | ) | |
5c633a4c JK |
123 | ' |
124 | ||
5eb73581 JK |
125 | rewound_push_setup() { |
126 | rm -rf parent child && | |
2f334155 JH |
127 | mkdir parent && |
128 | ( | |
129 | cd parent && | |
130 | git init && | |
131 | echo one >file && git add file && git commit -m one && | |
acd2a45b | 132 | git config receive.denyCurrentBranch warn && |
2f334155 JH |
133 | echo two >file && git commit -a -m two |
134 | ) && | |
135 | git clone parent child && | |
136 | ( | |
137 | cd child && git reset --hard HEAD^ | |
138 | ) | |
5eb73581 JK |
139 | } |
140 | ||
141 | rewound_push_succeeded() { | |
142 | cmp ../parent/.git/refs/heads/master .git/refs/heads/master | |
143 | } | |
144 | ||
145 | rewound_push_failed() { | |
146 | if rewound_push_succeeded | |
147 | then | |
148 | false | |
149 | else | |
150 | true | |
151 | fi | |
152 | } | |
153 | ||
2f334155 | 154 | test_expect_success 'pushing explicit refspecs respects forcing' ' |
5eb73581 | 155 | rewound_push_setup && |
2f334155 JH |
156 | parent_orig=$(cd parent && git rev-parse --verify master) && |
157 | ( | |
158 | cd child && | |
159 | test_must_fail git send-pack ../parent \ | |
160 | refs/heads/master:refs/heads/master | |
161 | ) && | |
162 | parent_head=$(cd parent && git rev-parse --verify master) && | |
163 | test "$parent_orig" = "$parent_head" && | |
164 | ( | |
165 | cd child && | |
166 | git send-pack ../parent \ | |
167 | +refs/heads/master:refs/heads/master | |
168 | ) && | |
169 | parent_head=$(cd parent && git rev-parse --verify master) && | |
170 | child_head=$(cd parent && git rev-parse --verify master) && | |
171 | test "$parent_head" = "$child_head" | |
5eb73581 JK |
172 | ' |
173 | ||
2f334155 | 174 | test_expect_success 'pushing wildcard refspecs respects forcing' ' |
5eb73581 | 175 | rewound_push_setup && |
2f334155 JH |
176 | parent_orig=$(cd parent && git rev-parse --verify master) && |
177 | ( | |
178 | cd child && | |
179 | test_must_fail git send-pack ../parent \ | |
180 | "refs/heads/*:refs/heads/*" | |
181 | ) && | |
182 | parent_head=$(cd parent && git rev-parse --verify master) && | |
183 | test "$parent_orig" = "$parent_head" && | |
184 | ( | |
185 | cd child && | |
186 | git send-pack ../parent \ | |
187 | "+refs/heads/*:refs/heads/*" | |
188 | ) && | |
189 | parent_head=$(cd parent && git rev-parse --verify master) && | |
190 | child_head=$(cd parent && git rev-parse --verify master) && | |
191 | test "$parent_head" = "$child_head" | |
5eb73581 JK |
192 | ' |
193 | ||
375881fa | 194 | test_expect_success 'deny pushing to delete current branch' ' |
747ca245 JH |
195 | rewound_push_setup && |
196 | ( | |
197 | cd child && | |
375881fa | 198 | test_must_fail git send-pack ../parent :refs/heads/master 2>errs |
747ca245 JH |
199 | ) |
200 | ' | |
201 | ||
da7bc9b0 | 202 | test_done |