@@ -8,7 +8,7 @@ exec </dev/null
8
8
9
9
. ./test-lib.sh
10
10
11
- add_and_commit_file ()
11
+ add_and_commit_file ()
12
12
{
13
13
_file=" $1 "
14
14
_msg=" $2 "
@@ -18,6 +18,38 @@ add_and_commit_file()
18
18
git commit --quiet -m " $_file : $_msg "
19
19
}
20
20
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
+
21
53
HASH1=
22
54
HASH2=
23
55
HASH3=
@@ -351,4 +383,15 @@ test_expect_success 'replace ref cleanup' '
351
383
test -z "$(git replace)"
352
384
'
353
385
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
+
354
397
test_done
0 commit comments