]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4018-diff-funcname.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t4018-diff-funcname.sh
CommitLineData
f258475a
JH
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test custom diff function name patterns'
7
8. ./test-lib.sh
9
f1b75fba
JS
10test_expect_success 'setup' '
11 # a non-trivial custom pattern
12 git config diff.custom1.funcname "!static
13!String
14[^ ].*s.*" &&
15
16 # a custom pattern which matches to end of line
17 git config diff.custom2.funcname "......Beer\$" &&
18
19 # alternation in pattern
20 git config diff.custom3.funcname "Beer$" &&
ad5070fb
JS
21 git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" &&
22
23 # for regexp compilation tests
24 echo A >A.java &&
25 echo B >B.java
f1b75fba 26'
d64d6cdc 27
28e8f0d5
ÆAB
28test_expect_success 'setup: test-tool userdiff' '
29 # Make sure additions to builtin_drivers are sorted
30 test_when_finished "rm builtin-drivers.sorted" &&
31 test-tool userdiff list-builtin-drivers >builtin-drivers &&
32 test_file_not_empty builtin-drivers &&
33 sort <builtin-drivers >builtin-drivers.sorted &&
34 test_cmp builtin-drivers.sorted builtin-drivers &&
35
36 # Ditto, but "custom" requires the .git directory and config
37 # to be setup and read.
38 test_when_finished "rm custom-drivers.sorted" &&
39 test-tool userdiff list-custom-drivers >custom-drivers &&
40 test_file_not_empty custom-drivers &&
41 sort <custom-drivers >custom-drivers.sorted &&
42 test_cmp custom-drivers.sorted custom-drivers
43'
44
bfa7d014 45diffpatterns="
28e8f0d5
ÆAB
46 $(cat builtin-drivers)
47 $(cat custom-drivers)
bfa7d014
JS
48"
49
50for p in $diffpatterns
e3bf5e43
BC
51do
52 test_expect_success "builtin $p pattern compiles" '
5b5e4594 53 echo "*.java diff=$p" >.gitattributes &&
d64d6cdc 54 test_expect_code 1 git diff --no-index \
ad5070fb 55 A.java B.java 2>msg &&
6789275d
JH
56 test_grep ! fatal msg &&
57 test_grep ! error msg
e3bf5e43 58 '
bff42061 59 test_expect_success "builtin $p wordRegex pattern compiles" '
5b5e4594 60 echo "*.java diff=$p" >.gitattributes &&
d64d6cdc 61 test_expect_code 1 git diff --no-index --word-diff \
ad5070fb 62 A.java B.java 2>msg &&
6789275d
JH
63 test_grep ! fatal msg &&
64 test_grep ! error msg
bff42061 65 '
44451a2e
JC
66
67 test_expect_success "builtin $p pattern compiles on bare repo with --attr-source" '
68 test_when_finished "rm -rf bare.git" &&
69 git checkout -B master &&
70 git add . &&
71 echo "*.java diff=notexist" >.gitattributes &&
72 git add .gitattributes &&
73 git commit -am "changing gitattributes" &&
74 git checkout -B branchA &&
75 echo "*.java diff=$p" >.gitattributes &&
76 git add .gitattributes &&
77 git commit -am "changing gitattributes" &&
78 git clone --bare --no-local . bare.git &&
79 git -C bare.git symbolic-ref HEAD refs/heads/master &&
80 test_expect_code 1 git -C bare.git --attr-source=branchA \
81 diff --exit-code HEAD:A.java HEAD:B.java 2>msg &&
6789275d
JH
82 test_grep ! fatal msg &&
83 test_grep ! error msg
44451a2e 84 '
e3bf5e43
BC
85done
86
f258475a 87test_expect_success 'last regexp must not be negated' '
ad5070fb 88 echo "*.java diff=java" >.gitattributes &&
f792a0b8 89 test_config diff.java.funcname "!static" &&
ad5070fb 90 test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
6789275d 91 test_grep ": Last expression must not be negated:" msg
f258475a
JH
92'
93
bfa7d014
JS
94test_expect_success 'setup hunk header tests' '
95 for i in $diffpatterns
96 do
cbe1d9d6 97 echo "$i-* diff=$i" || return 1
bfa7d014
JS
98 done > .gitattributes &&
99
100 # add all test files to the index
101 (
102 cd "$TEST_DIRECTORY"/t4018 &&
103 git --git-dir="$TRASH_DIRECTORY/.git" add .
104 ) &&
105
106 # place modified files in the worktree
107 for i in $(git ls-files)
108 do
109 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
110 done
111'
112
113# check each individual file
114for i in $(git ls-files)
115do
6cb77966 116 test_expect_success "hunk header: $i" "
bfa7d014
JS
117 git diff -U1 $i >actual &&
118 grep '@@ .* @@.*RIGHT' actual
119 "
120done
121
f258475a 122test_done