replace: add test for --graft

Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jul 19, 2014 at 17:01 UTC adf8e5423891fa9bd04fcb0489ffb5da7025ec07
1 file changed +44 -1
t/t6050-replace.sh
+44 -1
@@ -8,7 +8,7 @@ exec </dev/null
8
9 . ./test-lib.sh
10
11 -add_and_commit_file()
11 +add_and_commit_file ()
12 {
13 _file="$1"
14 _msg="$2"
@@ -18,6 +18,38 @@ add_and_commit_file()
18 git commit --quiet -m "$_file: $_msg"
19 }
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 +
53 HASH1=
54 HASH2=
55 HASH3=
@@ -351,4 +383,15 @@ test_expect_success 'replace ref cleanup' '
383 test -z "$(git replace)"
384 '
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 +
397 test_done