]>
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 && |
bdf25142 | 35 | cd victim && |
5be60078 | 36 | git log && |
bdf25142 | 37 | cd .. && |
5be60078 | 38 | git update-ref HEAD "$zero" && |
bdf25142 | 39 | parent=$zero && |
04509738 JH |
40 | i=0 && |
41 | while test $i -le $cnt | |
bdf25142 | 42 | do |
04509738 JH |
43 | i=$(($i+1)) && |
44 | test_tick && | |
45 | echo "Rebase #$i" >mozart/is/pink && | |
5be60078 JH |
46 | git update-index --add mozart/is/pink && |
47 | tree=$(git write-tree) && | |
48 | commit=$(echo "Rebase #$i" | git commit-tree $tree -p $parent) && | |
49 | git update-ref refs/tags/rebase$i $commit && | |
4d9d62fa | 50 | parent=$commit || return 1 |
bdf25142 | 51 | done && |
5be60078 | 52 | git update-ref HEAD "$commit" && |
bdf25142 | 53 | echo Rebase && |
5be60078 | 54 | git log' |
bdf25142 | 55 | |
04509738 JH |
56 | test_expect_success 'pack the source repository' ' |
57 | git repack -a -d && | |
026aa938 | 58 | git prune |
04509738 JH |
59 | ' |
60 | ||
61 | test_expect_success 'pack the destination repository' ' | |
62 | cd victim && | |
63 | git repack -a -d && | |
026aa938 | 64 | git prune && |
04509738 JH |
65 | cd .. |
66 | ' | |
67 | ||
bdf25142 | 68 | test_expect_success \ |
a6080a0a | 69 | 'pushing rewound head should not barf but require --force' ' |
bdf25142 | 70 | # should not fail but refuse to update. |
3604e7c5 | 71 | if git send-pack ./victim/.git/ master |
ed24928e PB |
72 | then |
73 | # now it should fail with Pasky patch | |
74 | echo >&2 Gaah, it should have failed. | |
75 | false | |
76 | else | |
77 | echo >&2 Thanks, it correctly failed. | |
78 | true | |
79 | fi && | |
bdf25142 LT |
80 | if cmp victim/.git/refs/heads/master .git/refs/heads/master |
81 | then | |
82 | # should have been left as it was! | |
83 | false | |
84 | else | |
85 | true | |
86 | fi && | |
87 | # this should update | |
3604e7c5 | 88 | git send-pack --force ./victim/.git/ master && |
bdf25142 LT |
89 | cmp victim/.git/refs/heads/master .git/refs/heads/master |
90 | ' | |
da7bc9b0 | 91 | |
d4f694ba JH |
92 | test_expect_success \ |
93 | 'push can be used to delete a ref' ' | |
94 | cd victim && | |
95 | git branch extra master && | |
96 | cd .. && | |
97 | test -f victim/.git/refs/heads/extra && | |
3604e7c5 | 98 | git send-pack ./victim/.git/ :extra master && |
d4f694ba JH |
99 | ! test -f victim/.git/refs/heads/extra |
100 | ' | |
101 | ||
199a9218 JS |
102 | unset GIT_CONFIG GIT_CONFIG_LOCAL |
103 | HOME=`pwd`/no-such-directory | |
104 | export HOME ;# this way we force the victim/.git/config to be used. | |
105 | ||
106 | test_expect_success \ | |
107 | 'pushing with --force should be denied with denyNonFastforwards' ' | |
108 | cd victim && | |
5be60078 | 109 | git config receive.denyNonFastforwards true && |
199a9218 | 110 | cd .. && |
5be60078 | 111 | git update-ref refs/heads/master master^ || return 1 |
3604e7c5 | 112 | git send-pack --force ./victim/.git/ master && return 1 |
3af82863 | 113 | ! test_cmp .git/refs/heads/master victim/.git/refs/heads/master |
199a9218 JS |
114 | ' |
115 | ||
5c633a4c JK |
116 | test_expect_success \ |
117 | 'pushing does not include non-head refs' ' | |
118 | mkdir parent && cd parent && | |
3604e7c5 | 119 | git init && touch file && git add file && git commit -m add && |
5c633a4c | 120 | cd .. && |
3604e7c5 | 121 | git clone parent child && cd child && git push --all && |
5c633a4c | 122 | cd ../parent && |
3604e7c5 | 123 | git branch -a >branches && ! grep origin/master branches |
5c633a4c JK |
124 | ' |
125 | ||
5eb73581 JK |
126 | rewound_push_setup() { |
127 | rm -rf parent child && | |
128 | mkdir parent && cd parent && | |
3604e7c5 NS |
129 | git init && echo one >file && git add file && git commit -m one && |
130 | echo two >file && git commit -a -m two && | |
5eb73581 | 131 | cd .. && |
3604e7c5 | 132 | git clone parent child && cd child && git reset --hard HEAD^ |
5eb73581 JK |
133 | } |
134 | ||
135 | rewound_push_succeeded() { | |
136 | cmp ../parent/.git/refs/heads/master .git/refs/heads/master | |
137 | } | |
138 | ||
139 | rewound_push_failed() { | |
140 | if rewound_push_succeeded | |
141 | then | |
142 | false | |
143 | else | |
144 | true | |
145 | fi | |
146 | } | |
147 | ||
148 | test_expect_success \ | |
149 | 'pushing explicit refspecs respects forcing' ' | |
150 | rewound_push_setup && | |
3604e7c5 | 151 | if git send-pack ../parent/.git refs/heads/master:refs/heads/master |
5eb73581 JK |
152 | then |
153 | false | |
154 | else | |
155 | true | |
156 | fi && rewound_push_failed && | |
3604e7c5 | 157 | git send-pack ../parent/.git +refs/heads/master:refs/heads/master && |
5eb73581 JK |
158 | rewound_push_succeeded |
159 | ' | |
160 | ||
161 | test_expect_success \ | |
162 | 'pushing wildcard refspecs respects forcing' ' | |
163 | rewound_push_setup && | |
3604e7c5 | 164 | if git send-pack ../parent/.git refs/heads/*:refs/heads/* |
5eb73581 JK |
165 | then |
166 | false | |
167 | else | |
168 | true | |
169 | fi && rewound_push_failed && | |
3604e7c5 | 170 | git send-pack ../parent/.git +refs/heads/*:refs/heads/* && |
5eb73581 JK |
171 | rewound_push_succeeded |
172 | ' | |
173 | ||
da7bc9b0 | 174 | test_done |