]>
Commit | Line | Data |
---|---|---|
6d0e674a RS |
1 | #!/bin/sh |
2 | ||
3 | test_description='diff hunk fusing' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | f() { | |
8 | echo $1 | |
9 | i=1 | |
10 | while test $i -le $2 | |
11 | do | |
12 | echo $i | |
13 | i=$(expr $i + 1) | |
14 | done | |
15 | echo $3 | |
16 | } | |
17 | ||
18 | t() { | |
c4888677 VN |
19 | use_config= |
20 | git config --unset diff.interHunkContext | |
21 | ||
6d0e674a RS |
22 | case $# in |
23 | 4) hunks=$4; cmd="diff -U$3";; | |
24 | 5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";; | |
c4888677 | 25 | 6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";; |
6d0e674a | 26 | esac |
c4888677 | 27 | label="$use_config$cmd, $1 common $2" |
6d0e674a RS |
28 | file=f$1 |
29 | expected=expected.$file.$3.$hunks | |
30 | ||
31 | if ! test -f $file | |
32 | then | |
33 | f A $1 B >$file | |
34 | git add $file | |
35 | git commit -q -m. $file | |
36 | f X $1 Y >$file | |
37 | fi | |
38 | ||
39 | test_expect_success "$label: count hunks ($hunks)" " | |
40 | test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks | |
41 | " | |
42 | ||
43 | test -f $expected && | |
44 | test_expect_success "$label: check output" " | |
45 | git $cmd $file | grep -v '^index ' >actual && | |
46 | test_cmp $expected actual | |
47 | " | |
48 | } | |
49 | ||
50 | cat <<EOF >expected.f1.0.1 || exit 1 | |
51 | diff --git a/f1 b/f1 | |
52 | --- a/f1 | |
53 | +++ b/f1 | |
54 | @@ -1,3 +1,3 @@ | |
55 | -A | |
56 | +X | |
57 | 1 | |
58 | -B | |
59 | +Y | |
60 | EOF | |
61 | ||
62 | cat <<EOF >expected.f1.0.2 || exit 1 | |
63 | diff --git a/f1 b/f1 | |
64 | --- a/f1 | |
65 | +++ b/f1 | |
66 | @@ -1 +1 @@ | |
67 | -A | |
68 | +X | |
69 | @@ -3 +3 @@ A | |
70 | -B | |
71 | +Y | |
72 | EOF | |
73 | ||
74 | # common lines ctx intrctx hunks | |
75 | t 1 line 0 2 | |
76 | t 1 line 0 0 2 | |
77 | t 1 line 0 1 1 | |
78 | t 1 line 0 2 1 | |
79 | t 1 line 1 1 | |
80 | ||
81 | t 2 lines 0 2 | |
82 | t 2 lines 0 0 2 | |
83 | t 2 lines 0 1 2 | |
84 | t 2 lines 0 2 1 | |
85 | t 2 lines 1 1 | |
86 | ||
87 | t 3 lines 1 2 | |
88 | t 3 lines 1 0 2 | |
89 | t 3 lines 1 1 1 | |
90 | t 3 lines 1 2 1 | |
91 | ||
92 | t 9 lines 3 2 | |
93 | t 9 lines 3 2 2 | |
94 | t 9 lines 3 3 1 | |
95 | ||
c4888677 VN |
96 | # use diff.interHunkContext? |
97 | t 1 line 0 0 2 config | |
98 | t 1 line 0 1 1 config | |
99 | t 1 line 0 2 1 config | |
100 | t 9 lines 3 3 1 config | |
101 | t 2 lines 0 0 2 config | |
102 | t 2 lines 0 1 2 config | |
103 | t 2 lines 0 2 1 config | |
104 | t 3 lines 1 0 2 config | |
105 | t 3 lines 1 1 1 config | |
106 | t 3 lines 1 2 1 config | |
107 | t 9 lines 3 2 2 config | |
108 | t 9 lines 3 3 1 config | |
109 | ||
110 | test_expect_success 'diff.interHunkContext invalid' ' | |
111 | git config diff.interHunkContext asdf && | |
112 | test_must_fail git diff && | |
113 | git config diff.interHunkContext -1 && | |
114 | test_must_fail git diff | |
115 | ' | |
116 | ||
6d0e674a | 117 | test_done |