combine-diff.c: Fix output when changes are exactly 3 lines apart
[git/mingw.git] / t / t4038-diff-combined.sh
blob2ffc692bdeb39cd9c3b592d139dece4740cc3e71
1 #!/bin/sh
3 test_description='combined diff'
5 . ./test-lib.sh
7 setup_helper () {
8 one=$1 branch=$2 side=$3 &&
10 git branch $side $branch &&
11 for l in $one two three fyra
13 echo $l
14 done >file &&
15 git add file &&
16 test_tick &&
17 git commit -m $branch &&
18 git checkout $side &&
19 for l in $one two three quatro
21 echo $l
22 done >file &&
23 git add file &&
24 test_tick &&
25 git commit -m $side &&
26 test_must_fail git merge $branch &&
27 for l in $one three four
29 echo $l
30 done >file &&
31 git add file &&
32 test_tick &&
33 git commit -m "merge $branch into $side"
36 verify_helper () {
37 it=$1 &&
39 # Ignore lines that were removed only from the other parent
40 sed -e '
41 1,/^@@@/d
42 /^ -/d
43 s/^\(.\)./\1/
44 ' "$it" >"$it.actual.1" &&
45 sed -e '
46 1,/^@@@/d
47 /^- /d
48 s/^.\(.\)/\1/
49 ' "$it" >"$it.actual.2" &&
51 git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
52 test_cmp "$it.expect.1" "$it.actual.1" &&
54 git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
55 test_cmp "$it.expect.2" "$it.actual.2"
58 test_expect_success setup '
59 >file &&
60 git add file &&
61 test_tick &&
62 git commit -m initial &&
64 git branch withone &&
65 git branch sansone &&
67 git checkout withone &&
68 setup_helper one withone sidewithone &&
70 git checkout sansone &&
71 setup_helper "" sansone sidesansone
74 test_expect_success 'check combined output (1)' '
75 git show sidewithone -- >sidewithone &&
76 verify_helper sidewithone
79 test_expect_success 'check combined output (2)' '
80 git show sidesansone -- >sidesansone &&
81 verify_helper sidesansone
84 test_expect_success 'diagnose truncated file' '
85 >file &&
86 git add file &&
87 git commit --amend -C HEAD &&
88 git show >out &&
89 grep "diff --cc file" out
92 # Test for a bug reported at
93 # http://thread.gmane.org/gmane.comp.version-control.git/224410
94 # where a delete lines were missing from combined diff output when they
95 # occurred exactly before the context lines of a later change.
96 test_expect_success 'combine diff missing delete bug' '
97 git commit -m initial --allow-empty &&
98 cat <<-\EOF >test &&
104 git add test &&
105 git commit -a -m side1 &&
106 git checkout -B side1 &&
107 git checkout HEAD^ &&
108 cat <<-\EOF >test &&
113 4modified
115 git add test &&
116 git commit -m side2 &&
117 git branch -f side2 &&
118 test_must_fail git merge --no-commit side1 &&
119 cat <<-\EOF >test &&
123 4modified
125 git add test &&
126 git commit -a -m merge &&
127 git diff-tree -c -p HEAD >actual.tmp &&
128 sed -e "1,/^@@@/d" < actual.tmp >actual &&
129 tr -d Q <<-\EOF >expected &&
135 +4modified
137 test_cmp expected actual
140 test_done