@@ -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+
2153HASH1=
2254HASH2=
2355HASH3=
@@ -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+
354397test_done
0 commit comments