Win32: support long paths
[git/mingw/4msysgit.git] / t / t6050-replace.sh
blob719a11673bfc93463870d7d601eb3a0634b59b48
1 #!/bin/sh
3 # Copyright (c) 2008 Christian Couder
5 test_description='Tests replace refs functionality'
7 exec </dev/null
9 . ./test-lib.sh
11 add_and_commit_file()
13 _file="$1"
14 _msg="$2"
16 git add $_file || return $?
17 test_tick || return $?
18 git commit --quiet -m "$_file: $_msg"
21 HASH1=
22 HASH2=
23 HASH3=
24 HASH4=
25 HASH5=
26 HASH6=
27 HASH7=
29 test_expect_success 'set up buggy branch' '
30 echo "line 1" >> hello &&
31 echo "line 2" >> hello &&
32 echo "line 3" >> hello &&
33 echo "line 4" >> hello &&
34 add_and_commit_file hello "4 lines" &&
35 HASH1=$(git rev-parse --verify HEAD) &&
36 echo "line BUG" >> hello &&
37 echo "line 6" >> hello &&
38 echo "line 7" >> hello &&
39 echo "line 8" >> hello &&
40 add_and_commit_file hello "4 more lines with a BUG" &&
41 HASH2=$(git rev-parse --verify HEAD) &&
42 echo "line 9" >> hello &&
43 echo "line 10" >> hello &&
44 add_and_commit_file hello "2 more lines" &&
45 HASH3=$(git rev-parse --verify HEAD) &&
46 echo "line 11" >> hello &&
47 add_and_commit_file hello "1 more line" &&
48 HASH4=$(git rev-parse --verify HEAD) &&
49 sed -e "s/BUG/5/" hello > hello.new &&
50 mv hello.new hello &&
51 add_and_commit_file hello "BUG fixed" &&
52 HASH5=$(git rev-parse --verify HEAD) &&
53 echo "line 12" >> hello &&
54 echo "line 13" >> hello &&
55 add_and_commit_file hello "2 more lines" &&
56 HASH6=$(git rev-parse --verify HEAD) &&
57 echo "line 14" >> hello &&
58 echo "line 15" >> hello &&
59 echo "line 16" >> hello &&
60 add_and_commit_file hello "again 3 more lines" &&
61 HASH7=$(git rev-parse --verify HEAD)
64 test_expect_success 'replace the author' '
65 git cat-file commit $HASH2 | grep "author A U Thor" &&
66 R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
67 git cat-file commit $R | grep "author O Thor" &&
68 git update-ref refs/replace/$HASH2 $R &&
69 git show HEAD~5 | grep "O Thor" &&
70 git show $HASH2 | grep "O Thor"
73 test_expect_success 'test --no-replace-objects option' '
74 git cat-file commit $HASH2 | grep "author O Thor" &&
75 git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" &&
76 git show $HASH2 | grep "O Thor" &&
77 git --no-replace-objects show $HASH2 | grep "A U Thor"
80 test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
81 GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" &&
82 GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
85 cat >tag.sig <<EOF
86 object $HASH2
87 type commit
88 tag mytag
89 tagger T A Gger <> 0 +0000
91 EOF
93 test_expect_success 'tag replaced commit' '
94 git mktag <tag.sig >.git/refs/tags/mytag 2>message
97 test_expect_success '"git fsck" works' '
98 git fsck master > fsck_master.out &&
99 grep "dangling commit $R" fsck_master.out &&
100 grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
101 test -z "$(git fsck)"
104 test_expect_success 'repack, clone and fetch work' '
105 git repack -a -d &&
106 git clone --no-hardlinks . clone_dir &&
108 cd clone_dir &&
109 git show HEAD~5 | grep "A U Thor" &&
110 git show $HASH2 | grep "A U Thor" &&
111 git cat-file commit $R &&
112 git repack -a -d &&
113 test_must_fail git cat-file commit $R &&
114 git fetch ../ "refs/replace/*:refs/replace/*" &&
115 git show HEAD~5 | grep "O Thor" &&
116 git show $HASH2 | grep "O Thor" &&
117 git cat-file commit $R
121 test_expect_success '"git replace" listing and deleting' '
122 test "$HASH2" = "$(git replace -l)" &&
123 test "$HASH2" = "$(git replace)" &&
124 aa=${HASH2%??????????????????????????????????????} &&
125 test "$HASH2" = "$(git replace --list "$aa*")" &&
126 test_must_fail git replace -d $R &&
127 test_must_fail git replace --delete &&
128 test_must_fail git replace -l -d $HASH2 &&
129 git replace -d $HASH2 &&
130 git show $HASH2 | grep "A U Thor" &&
131 test -z "$(git replace -l)"
134 test_expect_success '"git replace" replacing' '
135 git replace $HASH2 $R &&
136 git show $HASH2 | grep "O Thor" &&
137 test_must_fail git replace $HASH2 $R &&
138 git replace -f $HASH2 $R &&
139 test_must_fail git replace -f &&
140 test "$HASH2" = "$(git replace)"
143 test_expect_success '"git replace" resolves sha1' '
144 SHORTHASH2=$(git rev-parse --short=8 $HASH2) &&
145 git replace -d $SHORTHASH2 &&
146 git replace $SHORTHASH2 $R &&
147 git show $HASH2 | grep "O Thor" &&
148 test_must_fail git replace $HASH2 $R &&
149 git replace -f $HASH2 $R &&
150 test_must_fail git replace --force &&
151 test "$HASH2" = "$(git replace)"
154 # This creates a side branch where the bug in H2
155 # does not appear because P2 is created by applying
156 # H2 and squashing H5 into it.
157 # P3, P4 and P6 are created by cherry-picking H3, H4
158 # and H6 respectively.
160 # At this point, we should have the following:
162 # P2--P3--P4--P6
164 # H1-H2-H3-H4-H5-H6-H7
166 # Then we replace H6 with P6.
168 test_expect_success 'create parallel branch without the bug' '
169 git replace -d $HASH2 &&
170 git show $HASH2 | grep "A U Thor" &&
171 git checkout $HASH1 &&
172 git cherry-pick $HASH2 &&
173 git show $HASH5 | git apply &&
174 git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
175 PARA2=$(git rev-parse --verify HEAD) &&
176 git cherry-pick $HASH3 &&
177 PARA3=$(git rev-parse --verify HEAD) &&
178 git cherry-pick $HASH4 &&
179 PARA4=$(git rev-parse --verify HEAD) &&
180 git cherry-pick $HASH6 &&
181 PARA6=$(git rev-parse --verify HEAD) &&
182 git replace $HASH6 $PARA6 &&
183 git checkout master &&
184 cur=$(git rev-parse --verify HEAD) &&
185 test "$cur" = "$HASH7" &&
186 git log --pretty=oneline | grep $PARA2 &&
187 git remote add cloned ./clone_dir
190 test_expect_success 'push to cloned repo' '
191 git push cloned $HASH6^:refs/heads/parallel &&
193 cd clone_dir &&
194 git checkout parallel &&
195 git log --pretty=oneline | grep $PARA2
199 test_expect_success 'push branch with replacement' '
200 git cat-file commit $PARA3 | grep "author A U Thor" &&
201 S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
202 git cat-file commit $S | grep "author O Thor" &&
203 git replace $PARA3 $S &&
204 git show $HASH6~2 | grep "O Thor" &&
205 git show $PARA3 | grep "O Thor" &&
206 git push cloned $HASH6^:refs/heads/parallel2 &&
208 cd clone_dir &&
209 git checkout parallel2 &&
210 git log --pretty=oneline | grep $PARA3 &&
211 git show $PARA3 | grep "A U Thor"
215 test_expect_success 'fetch branch with replacement' '
216 git branch tofetch $HASH6 &&
218 cd clone_dir &&
219 git fetch origin refs/heads/tofetch:refs/heads/parallel3 &&
220 git log --pretty=oneline parallel3 > output.txt &&
221 ! grep $PARA3 output.txt &&
222 git show $PARA3 > para3.txt &&
223 grep "A U Thor" para3.txt &&
224 git fetch origin "refs/replace/*:refs/replace/*" &&
225 git log --pretty=oneline parallel3 > output.txt &&
226 grep $PARA3 output.txt &&
227 git show $PARA3 > para3.txt &&
228 grep "O Thor" para3.txt
232 test_expect_success 'bisect and replacements' '
233 git bisect start $HASH7 $HASH1 &&
234 test "$PARA3" = "$(git rev-parse --verify HEAD)" &&
235 git bisect reset &&
236 GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
237 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
238 git bisect reset &&
239 git --no-replace-objects bisect start $HASH7 $HASH1 &&
240 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
241 git bisect reset
244 test_expect_success 'index-pack and replacements' '
245 git --no-replace-objects rev-list --objects HEAD |
246 git --no-replace-objects pack-objects test- &&
247 git index-pack test-*.pack
250 test_expect_success 'not just commits' '
251 echo replaced >file &&
252 git add file &&
253 REPLACED=$(git rev-parse :file) &&
254 mv file file.replaced &&
256 echo original >file &&
257 git add file &&
258 ORIGINAL=$(git rev-parse :file) &&
259 git update-ref refs/replace/$ORIGINAL $REPLACED &&
260 mv file file.original &&
262 git checkout file &&
263 test_cmp file.replaced file
266 test_expect_success 'replaced and replacement objects must be of the same type' '
267 test_must_fail git replace mytag $HASH1 &&
268 test_must_fail git replace HEAD^{tree} HEAD~1 &&
269 BLOB=$(git rev-parse :file) &&
270 test_must_fail git replace HEAD^ $BLOB
273 test_expect_success '-f option bypasses the type check' '
274 git replace -f mytag $HASH1 &&
275 git replace --force HEAD^{tree} HEAD~1 &&
276 git replace -f HEAD^ $BLOB
279 test_expect_success 'git cat-file --batch works on replace objects' '
280 git replace | grep $PARA3 &&
281 echo $PARA3 | git cat-file --batch
284 test_expect_success 'test --format bogus' '
285 test_must_fail git replace --format bogus >/dev/null 2>&1
288 test_expect_success 'test --format short' '
289 git replace --format=short >actual &&
290 git replace >expected &&
291 test_cmp expected actual
294 test_expect_success 'test --format medium' '
295 H1=$(git --no-replace-objects rev-parse HEAD~1) &&
296 HT=$(git --no-replace-objects rev-parse HEAD^{tree}) &&
297 MYTAG=$(git --no-replace-objects rev-parse mytag) &&
299 echo "$H1 -> $BLOB" &&
300 echo "$BLOB -> $REPLACED" &&
301 echo "$HT -> $H1" &&
302 echo "$PARA3 -> $S" &&
303 echo "$MYTAG -> $HASH1"
304 } | sort >expected &&
305 git replace -l --format medium | sort > actual &&
306 test_cmp expected actual
309 test_expect_success 'test --format long' '
311 echo "$H1 (commit) -> $BLOB (blob)" &&
312 echo "$BLOB (blob) -> $REPLACED (blob)" &&
313 echo "$HT (tree) -> $H1 (commit)" &&
314 echo "$PARA3 (commit) -> $S (commit)" &&
315 echo "$MYTAG (tag) -> $HASH1 (commit)"
316 } | sort >expected &&
317 git replace --format=long | sort > actual &&
318 test_cmp expected actual
321 test_expect_success 'replace ref cleanup' '
322 test -n "$(git replace)" &&
323 git replace -d $(git replace) &&
324 test -z "$(git replace)"
327 test_done