Code

f9b94251530fb2b7913af7a1aaf9b5fbbeb78cd3
[git.git] / t / t4119-apply-config.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Junio C Hamano
4 #
6 test_description='git-apply --whitespace=strip and configuration file.
8 '
10 . ./test-lib.sh
12 test_expect_success setup '
13         mkdir sub &&
14         echo A >sub/file1 &&
15         cp sub/file1 saved &&
16         git add sub/file1 &&
17         echo "B " >sub/file1 &&
18         git diff >patch.file
19 '
21 # Also handcraft GNU diff output; note this has trailing whitespace.
22 cat >gpatch.file <<\EOF
23 --- file1       2007-02-21 01:04:24.000000000 -0800
24 +++ file1+      2007-02-21 01:07:44.000000000 -0800
25 @@ -1 +1 @@
26 -A
27 +B 
28 EOF
30 test_expect_success 'apply --whitespace=strip' '
32         rm -f sub/file1 &&
33         cp saved sub/file1 &&
34         git update-index --refresh &&
36         git apply --whitespace=strip patch.file &&
37         if grep " " sub/file1
38         then
39                 echo "Eh?"
40                 false
41         elif grep B sub/file1
42         then
43                 echo Happy
44         else
45                 echo "Huh?"
46                 false
47         fi
48 '
50 test_expect_success 'apply --whitespace=strip from config' '
52         rm -f sub/file1 &&
53         cp saved sub/file1 &&
54         git update-index --refresh &&
56         git config apply.whitespace strip &&
57         git apply patch.file &&
58         if grep " " sub/file1
59         then
60                 echo "Eh?"
61                 false
62         elif grep B sub/file1
63         then
64                 echo Happy
65         else
66                 echo Happy
67         fi
68 '
70 D=`pwd`
72 test_expect_success 'apply --whitespace=strip in subdir' '
74         cd "$D" &&
75         git config --unset-all apply.whitespace
76         rm -f sub/file1 &&
77         cp saved sub/file1 &&
78         git update-index --refresh &&
80         cd sub &&
81         git apply --whitespace=strip -p2 ../patch.file &&
82         if grep " " file1
83         then
84                 echo "Eh?"
85                 false
86         elif grep B file1
87         then
88                 echo Happy
89         else
90                 echo "Huh?"
91                 false
92         fi
93 '
95 test_expect_success 'apply --whitespace=strip from config in subdir' '
97         cd "$D" &&
98         git config apply.whitespace strip &&
99         rm -f sub/file1 &&
100         cp saved sub/file1 &&
101         git update-index --refresh &&
103         cd sub &&
104         git apply -p2 ../patch.file &&
105         if grep " " file1
106         then
107                 echo "Eh?"
108                 false
109         elif grep B file1
110         then
111                 echo Happy
112         else
113                 echo "Huh?"
114                 false
115         fi
118 test_expect_success 'same in subdir but with traditional patch input' '
120         cd "$D" &&
121         git config apply.whitespace strip &&
122         rm -f sub/file1 &&
123         cp saved sub/file1 &&
124         git update-index --refresh &&
126         cd sub &&
127         git apply -p0 ../gpatch.file &&
128         if grep " " file1
129         then
130                 echo "Eh?"
131                 false
132         elif grep B file1
133         then
134                 echo Happy
135         else
136                 echo "Huh?"
137                 false
138         fi
141 test_done