blob: 7db92d0d9f461aca48fb4ebf014cd03cb1401a1c [file] [log] [blame]
René Scharfe6d0e6742008-12-28 19:45:32 +01001#!/bin/sh
2
3test_description='diff hunk fusing'
4
Ævar Arnfjörð Bjarmason16d4bd42021-10-31 00:24:19 +02005TEST_PASSES_SANITIZE_LEAK=true
René Scharfe6d0e6742008-12-28 19:45:32 +01006. ./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() {
Vegard Nossumc4888672017-01-12 13:21:11 +010020 use_config=
21 git config --unset diff.interHunkContext
22
René Scharfe6d0e6742008-12-28 19:45:32 +010023 case $# in
24 4) hunks=$4; cmd="diff -U$3";;
25 5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
Vegard Nossumc4888672017-01-12 13:21:11 +010026 6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";;
René Scharfe6d0e6742008-12-28 19:45:32 +010027 esac
Vegard Nossumc4888672017-01-12 13:21:11 +010028 label="$use_config$cmd, $1 common $2"
René Scharfe6d0e6742008-12-28 19:45:32 +010029 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
Vegard Nossumc4888672017-01-12 13:21:11 +010097# 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
René Scharfe6d0e6742008-12-28 19:45:32 +0100118test_done