interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4119-apply-config.sh

180 lines · 3472 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2007 Junio C Hamano
4#
5
6test_description='git apply --whitespace=strip and configuration file.
7
8'
9
10
11. ./test-lib.sh
12
13test_expect_success setup '
14 mkdir sub &&
15 echo A >sub/file1 &&
16 cp sub/file1 saved &&
17 git add sub/file1 &&
18 echo "B " >sub/file1 &&
19 git diff >patch.file
20'
21
22# Also handcraft GNU diff output; note this has trailing whitespace.
23tr '_' ' ' >gpatch.file <<\EOF &&
24--- file1 2007-02-21 01:04:24.000000000 -0800
25+++ file1+ 2007-02-21 01:07:44.000000000 -0800
26@@ -1 +1 @@
27-A
28+B_
29EOF
30
31sed -e 's|file1|sub/&|' gpatch.file >gpatch-sub.file &&
32sed -e '
33 /^--- /s|file1|a/sub/&|
34 /^+++ /s|file1|b/sub/&|
35' gpatch.file >gpatch-ab-sub.file &&
36
37check_result () {
38 if grep " " "$1"
39 then
40 echo "Eh?"
41 false
42 elif grep B "$1"
43 then
44 echo Happy
45 else
46 echo "Huh?"
47 false
48 fi
49}
50
51test_expect_success 'apply --whitespace=strip' '
52
53 rm -f sub/file1 &&
54 cp saved sub/file1 &&
55 git update-index --refresh &&
56
57 git apply --whitespace=strip patch.file &&
58 check_result sub/file1
59'
60
61test_expect_success 'apply --whitespace=strip from config' '
62
63 rm -f sub/file1 &&
64 cp saved sub/file1 &&
65 git update-index --refresh &&
66
67 git config apply.whitespace strip &&
68 git apply patch.file &&
69 check_result sub/file1
70'
71
72D=$(pwd)
73
74test_expect_success 'apply --whitespace=strip in subdir' '
75
76 cd "$D" &&
77 git config --unset-all apply.whitespace &&
78 rm -f sub/file1 &&
79 cp saved sub/file1 &&
80 git update-index --refresh &&
81
82 cd sub &&
83 git apply --whitespace=strip ../patch.file &&
84 check_result file1
85'
86
87test_expect_success 'apply --whitespace=strip from config in subdir' '
88
89 cd "$D" &&
90 git config apply.whitespace strip &&
91 rm -f sub/file1 &&
92 cp saved sub/file1 &&
93 git update-index --refresh &&
94
95 cd sub &&
96 git apply ../patch.file &&
97 check_result file1
98'
99
100test_expect_success 'same in subdir but with traditional patch input' '
101
102 cd "$D" &&
103 git config apply.whitespace strip &&
104 rm -f sub/file1 &&
105 cp saved sub/file1 &&
106 git update-index --refresh &&
107
108 cd sub &&
109 git apply ../gpatch.file &&
110 check_result file1
111'
112
113test_expect_success 'same but with traditional patch input of depth 1' '
114
115 cd "$D" &&
116 git config apply.whitespace strip &&
117 rm -f sub/file1 &&
118 cp saved sub/file1 &&
119 git update-index --refresh &&
120
121 cd sub &&
122 git apply ../gpatch-sub.file &&
123 check_result file1
124'
125
126test_expect_success 'same but with traditional patch input of depth 2' '
127
128 cd "$D" &&
129 git config apply.whitespace strip &&
130 rm -f sub/file1 &&
131 cp saved sub/file1 &&
132 git update-index --refresh &&
133
134 cd sub &&
135 git apply ../gpatch-ab-sub.file &&
136 check_result file1
137'
138
139test_expect_success 'same but with traditional patch input of depth 1' '
140
141 cd "$D" &&
142 git config apply.whitespace strip &&
143 rm -f sub/file1 &&
144 cp saved sub/file1 &&
145 git update-index --refresh &&
146
147 git apply -p0 gpatch-sub.file &&
148 check_result sub/file1
149'
150
151test_expect_success 'same but with traditional patch input of depth 2' '
152
153 cd "$D" &&
154 git config apply.whitespace strip &&
155 rm -f sub/file1 &&
156 cp saved sub/file1 &&
157 git update-index --refresh &&
158
159 git apply gpatch-ab-sub.file &&
160 check_result sub/file1
161'
162
163test_expect_success 'in subdir with traditional patch input' '
164 cd "$D" &&
165 git config apply.whitespace strip &&
166 cat >.gitattributes <<-EOF &&
167 /* whitespace=blank-at-eol
168 sub/* whitespace=-blank-at-eol
169 EOF
170 rm -f sub/file1 &&
171 cp saved sub/file1 &&
172 git update-index --refresh &&
173
174 cd sub &&
175 git apply ../gpatch.file &&
176 echo "B " >expect &&
177 test_cmp expect file1
178'
179
180test_done