1#!/bin/sh
2
3test_description='combined diff'
4
5. ./test-lib.sh
6
7setup_helper () {
8 one=$1 branch=$2 side=$3 &&
9
10 git branch $side $branch &&
11 for l in $one two three fyra
12 do
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
20 do
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
28 do
29 echo $l
30 done >file &&
31 git add file &&
32 test_tick &&
33 git commit -m "merge $branch into $side"
34}
35
36verify_helper () {
37 it=$1 &&
38
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" &&
50
51 git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
52 test_cmp "$it.expect.1" "$it.actual.1" &&
53
54 git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
55 test_cmp "$it.expect.2" "$it.actual.2"
56}
57
58test_expect_success setup '
59 >file &&
60 git add file &&
61 test_tick &&
62 git commit -m initial &&
63
64 git branch withone &&
65 git branch sansone &&
66
67 git checkout withone &&
68 setup_helper one withone sidewithone &&
69
70 git checkout sansone &&
71 setup_helper "" sansone sidesansone
72'
73
74test_expect_success 'check combined output (1)' '
75 git show sidewithone -- >sidewithone &&
76 verify_helper sidewithone
77'
78
79test_expect_success 'check combined output (2)' '
80 git show sidesansone -- >sidesansone &&
81 verify_helper sidesansone
82'
83
84test_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
90'
91
92test_expect_success 'setup for --cc --raw' '
93 blob=$(echo file | git hash-object --stdin -w) &&
94 base_tree=$(echo "100644 blob $blob file" | git mktree) &&
95 trees= &&
96 for i in `test_seq 1 40`
97 do
98 blob=$(echo file$i | git hash-object --stdin -w) &&
99 trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF"
100 done
101'
102
103test_expect_success 'check --cc --raw with four trees' '
104 four_trees=$(echo "$trees" | sed -e 4q) &&
105 git diff --cc --raw $four_trees $base_tree >out &&
106 # Check for four leading colons in the output:
107 grep "^::::[^:]" out
108'
109
110test_expect_success 'check --cc --raw with forty trees' '
111 git diff --cc --raw $trees $base_tree >out &&
112 # Check for forty leading colons in the output:
113 grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
114'
115
116test_done