Skip to content

Commit 4e65b53

Browse files
chriscoolgitster
authored andcommitted
t6050: check pushing something based on a replaced commit
When using something like: $ git push $there 04a8c^2:master we need to parse 04a8c to find its second parent and then start discussing what object to send with the other end. "04a8c^2" is a direct user input and should mean the same commit as git show "04a8c^2" would give the user, so it obviously needs to obey the replace rules (making 04a8c parsed), but the object transfer should not look at replace at all. This patch adds some tests to check that the above is working well. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f3a5bf commit 4e65b53

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

t/t6050-replace.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,74 @@ test_expect_success '"git replace" replacing' '
127127
test "$HASH2" = "$(git replace)"
128128
'
129129

130+
# This creates a side branch where the bug in H2
131+
# does not appear because P2 is created by applying
132+
# H2 and squashing H5 into it.
133+
# P3, P4 and P6 are created by cherry-picking H3, H4
134+
# and H6 respectively.
135+
#
136+
# At this point, we should have the following:
137+
#
138+
# P2--P3--P4--P6
139+
# /
140+
# H1-H2-H3-H4-H5-H6-H7
141+
#
142+
# Then we replace H6 with P6.
143+
#
144+
test_expect_success 'create parallel branch without the bug' '
145+
git replace -d $HASH2 &&
146+
git show $HASH2 | grep "A U Thor" &&
147+
git checkout $HASH1 &&
148+
git cherry-pick $HASH2 &&
149+
git show $HASH5 | git apply &&
150+
git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
151+
PARA2=$(git rev-parse --verify HEAD) &&
152+
git cherry-pick $HASH3 &&
153+
PARA3=$(git rev-parse --verify HEAD) &&
154+
git cherry-pick $HASH4 &&
155+
PARA4=$(git rev-parse --verify HEAD) &&
156+
git cherry-pick $HASH6 &&
157+
PARA6=$(git rev-parse --verify HEAD) &&
158+
git replace $HASH6 $PARA6 &&
159+
git checkout master &&
160+
cur=$(git rev-parse --verify HEAD) &&
161+
test "$cur" = "$HASH7" &&
162+
git log --pretty=oneline | grep $PARA2 &&
163+
git remote add cloned ./clone_dir
164+
'
165+
166+
test_expect_success 'push to cloned repo' '
167+
git push cloned $HASH6^:refs/heads/parallel &&
168+
cd clone_dir &&
169+
git checkout parallel &&
170+
git log --pretty=oneline | grep $PARA2 &&
171+
cd ..
172+
'
173+
174+
test_expect_success 'push branch with replacement' '
175+
git cat-file commit $PARA3 | grep "author A U Thor" &&
176+
S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
177+
git cat-file commit $S | grep "author O Thor" &&
178+
git replace $PARA3 $S &&
179+
git show $HASH6~2 | grep "O Thor" &&
180+
git show $PARA3 | grep "O Thor" &&
181+
git push cloned $HASH6^:refs/heads/parallel2 &&
182+
cd clone_dir &&
183+
git checkout parallel2 &&
184+
git log --pretty=oneline | grep $PARA3 &&
185+
git show $PARA3 | grep "A U Thor" &&
186+
cd ..
187+
'
188+
189+
test_expect_success 'fetch branch with replacement' '
190+
git branch tofetch $HASH6 &&
191+
cd clone_dir &&
192+
git fetch origin refs/heads/tofetch:refs/heads/parallel3
193+
git log --pretty=oneline parallel3 | grep $PARA3
194+
git show $PARA3 | grep "A U Thor"
195+
cd ..
196+
'
197+
130198
#
131199
#
132200
test_done

0 commit comments

Comments
 (0)