Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit adf8e54

Browse files
chriscoolgitster
authored andcommitted
replace: add test for --graft
Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4228e8b commit adf8e54

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

t/t6050-replace.sh

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exec </dev/null
88

99
. ./test-lib.sh
1010

11-
add_and_commit_file()
11+
add_and_commit_file ()
1212
{
1313
_file="$1"
1414
_msg="$2"
@@ -18,6 +18,38 @@ add_and_commit_file()
1818
git commit --quiet -m "$_file: $_msg"
1919
}
2020

21+
commit_buffer_contains_parents ()
22+
{
23+
git cat-file commit "$1" >payload &&
24+
sed -n -e '/^$/q' -e '/^parent /p' <payload >actual &&
25+
shift &&
26+
for _parent
27+
do
28+
echo "parent $_parent"
29+
done >expected &&
30+
test_cmp expected actual
31+
}
32+
33+
commit_peeling_shows_parents ()
34+
{
35+
_parent_number=1
36+
_commit="$1"
37+
shift &&
38+
for _parent
39+
do
40+
_found=$(git rev-parse --verify $_commit^$_parent_number) || return 1
41+
test "$_found" = "$_parent" || return 1
42+
_parent_number=$(( $_parent_number + 1 ))
43+
done &&
44+
test_must_fail git rev-parse --verify $_commit^$_parent_number
45+
}
46+
47+
commit_has_parents ()
48+
{
49+
commit_buffer_contains_parents "$@" &&
50+
commit_peeling_shows_parents "$@"
51+
}
52+
2153
HASH1=
2254
HASH2=
2355
HASH3=
@@ -351,4 +383,15 @@ test_expect_success 'replace ref cleanup' '
351383
test -z "$(git replace)"
352384
'
353385

386+
test_expect_success '--graft with and without already replaced object' '
387+
test $(git log --oneline | wc -l) = 7 &&
388+
git replace --graft $HASH5 &&
389+
test $(git log --oneline | wc -l) = 3 &&
390+
commit_has_parents $HASH5 &&
391+
test_must_fail git replace --graft $HASH5 $HASH4 $HASH3 &&
392+
git replace --force -g $HASH5 $HASH4 $HASH3 &&
393+
commit_has_parents $HASH5 $HASH4 $HASH3 &&
394+
git replace -d $HASH5
395+
'
396+
354397
test_done

0 commit comments

Comments
 (0)