Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t4032-diff-inter-hunk-context.sh
blobbada0cbd32f76418a76702fbbd5143004876d074
1 #!/bin/sh
3 test_description='diff hunk fusing'
5 . ./test-lib.sh
7 f() {
8 echo $1
9 i=1
10 while test $i -le $2
12 echo $i
13 i=$(expr $i + 1)
14 done
15 echo $3
18 t() {
19 use_config=
20 git config --unset diff.interHunkContext
22 case $# in
23 4) hunks=$4; cmd="diff -U$3";;
24 5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
25 6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";;
26 esac
27 label="$use_config$cmd, $1 common $2"
28 file=f$1
29 expected=expected.$file.$3.$hunks
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
39 test_expect_success "$label: count hunks ($hunks)" "
40 test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
43 test -f $expected &&
44 test_expect_success "$label: check output" "
45 git $cmd $file | grep -v '^index ' >actual &&
46 test_cmp $expected actual
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 @@
60 EOF
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 @@
69 @@ -3 +3 @@ A
72 EOF
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
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
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
92 t 9 lines 3 2
93 t 9 lines 3 2 2
94 t 9 lines 3 3 1
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
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
117 test_done