3 # Copyright (c) 2008 Christian Couder
5 test_description='Tests replace refs functionality'
16 git add $_file || return $?
17 test_tick || return $?
18 git commit --quiet -m "$_file: $_msg"
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 &&
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"
84 tagger T A Gger <> 0 +0000
88 test_expect_success 'tag replaced commit' '
89 git mktag <tag.sig >.git/refs/tags/mytag 2>message
92 test_expect_success '"git fsck" works' '
93 git fsck master > fsck_master.out &&
94 grep "dangling commit $R" fsck_master.out &&
95 grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
99 test_expect_success 'repack, clone and fetch work' '
101 git clone --no-hardlinks . clone_dir &&
103 git show HEAD~5 | grep "A U Thor" &&
104 git show $HASH2 | grep "A U Thor" &&
105 git cat-file commit $R &&
107 test_must_fail git cat-file commit $R &&
108 git fetch ../ "refs/replace/*:refs/replace/*" &&
109 git show HEAD~5 | grep "O Thor" &&
110 git show $HASH2 | grep "O Thor" &&
111 git cat-file commit $R &&
115 test_expect_success '"git replace" listing and deleting' '
116 test "$HASH2" = "$(git replace -l)" &&
117 test "$HASH2" = "$(git replace)" &&
118 aa=${HASH2%??????????????????????????????????????} &&
119 test "$HASH2" = "$(git replace -l "$aa*")" &&
120 test_must_fail git replace -d $R &&
121 test_must_fail git replace -d &&
122 test_must_fail git replace -l -d $HASH2 &&
123 git replace -d $HASH2 &&
124 git show $HASH2 | grep "A U Thor" &&
125 test -z "$(git replace -l)"
128 test_expect_success '"git replace" replacing' '
129 git replace $HASH2 $R &&
130 git show $HASH2 | grep "O Thor" &&
131 test_must_fail git replace $HASH2 $R &&
132 git replace -f $HASH2 $R &&
133 test_must_fail git replace -f &&
134 test "$HASH2" = "$(git replace)"
137 # This creates a side branch where the bug in H2
138 # does not appear because P2 is created by applying
139 # H2 and squashing H5 into it.
140 # P3, P4 and P6 are created by cherry-picking H3, H4
141 # and H6 respectively.
143 # At this point, we should have the following:
147 # H1-H2-H3-H4-H5-H6-H7
149 # Then we replace H6 with P6.
151 test_expect_success 'create parallel branch without the bug' '
152 git replace -d $HASH2 &&
153 git show $HASH2 | grep "A U Thor" &&
154 git checkout $HASH1 &&
155 git cherry-pick $HASH2 &&
156 git show $HASH5 | git apply &&
157 git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
158 PARA2=$(git rev-parse --verify HEAD) &&
159 git cherry-pick $HASH3 &&
160 PARA3=$(git rev-parse --verify HEAD) &&
161 git cherry-pick $HASH4 &&
162 PARA4=$(git rev-parse --verify HEAD) &&
163 git cherry-pick $HASH6 &&
164 PARA6=$(git rev-parse --verify HEAD) &&
165 git replace $HASH6 $PARA6 &&
166 git checkout master &&
167 cur=$(git rev-parse --verify HEAD) &&
168 test "$cur" = "$HASH7" &&
169 git log --pretty=oneline | grep $PARA2 &&
170 git remote add cloned ./clone_dir
173 test_expect_success 'push to cloned repo' '
174 git push cloned $HASH6^:refs/heads/parallel &&
176 git checkout parallel &&
177 git log --pretty=oneline | grep $PARA2 &&
181 test_expect_success 'push branch with replacement' '
182 git cat-file commit $PARA3 | grep "author A U Thor" &&
183 S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
184 git cat-file commit $S | grep "author O Thor" &&
185 git replace $PARA3 $S &&
186 git show $HASH6~2 | grep "O Thor" &&
187 git show $PARA3 | grep "O Thor" &&
188 git push cloned $HASH6^:refs/heads/parallel2 &&
190 git checkout parallel2 &&
191 git log --pretty=oneline | grep $PARA3 &&
192 git show $PARA3 | grep "A U Thor" &&
196 test_expect_success 'fetch branch with replacement' '
197 git branch tofetch $HASH6 &&
199 git fetch origin refs/heads/tofetch:refs/heads/parallel3
200 git log --pretty=oneline parallel3 | grep $PARA3
201 git show $PARA3 | grep "A U Thor"