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