Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 3 | test_description='core.whitespace rules and git apply' |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | prepare_test_file () { |
| 8 | |
| 9 | # A line that has character X is touched iff RULE is in effect: |
| 10 | # X RULE |
| 11 | # ! trailing-space |
| 12 | # @ space-before-tab |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 13 | # # indent-with-non-tab (default tab width 8) |
| 14 | # = indent-with-non-tab,tabwidth=16 |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 15 | # % tab-in-indent |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 16 | sed -e "s/_/ /g" -e "s/>/ /" <<-\EOF |
| 17 | An_SP in an ordinary line>and a HT. |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 18 | >A HT (%). |
| 19 | _>A SP and a HT (@%). |
| 20 | _>_A SP, a HT and a SP (@%). |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 21 | _______Seven SP. |
| 22 | ________Eight SP (#). |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 23 | _______>Seven SP and a HT (@%). |
| 24 | ________>Eight SP and a HT (@#%). |
| 25 | _______>_Seven SP, a HT and a SP (@%). |
| 26 | ________>_Eight SP, a HT and a SP (@#%). |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 27 | _______________Fifteen SP (#). |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 28 | _______________>Fifteen SP and a HT (@#%). |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 29 | ________________Sixteen SP (#=). |
| 30 | ________________>Sixteen SP and a HT (@#%=). |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 31 | _____a__Five SP, a non WS, two SP. |
| 32 | A line with a (!) trailing SP_ |
| 33 | A line with a (!) trailing HT> |
| 34 | EOF |
| 35 | } |
| 36 | |
| 37 | apply_patch () { |
| 38 | >target && |
| 39 | sed -e "s|\([ab]\)/file|\1/target|" <patch | |
| 40 | git apply "$@" |
| 41 | } |
| 42 | |
| 43 | test_fix () { |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 44 | # fix should not barf |
| 45 | apply_patch --whitespace=fix || return 1 |
| 46 | |
| 47 | # find touched lines |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 48 | $DIFF file target | sed -n -e "s/^> //p" >fixed |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 49 | |
Stefano Lattarini | 41ccfdd | 2013-04-12 00:36:10 +0200 | [diff] [blame] | 50 | # the changed lines are all expected to change |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 51 | fixed_cnt=$(wc -l <fixed) |
| 52 | case "$1" in |
| 53 | '') expect_cnt=$fixed_cnt ;; |
| 54 | ?*) expect_cnt=$(grep "[$1]" <fixed | wc -l) ;; |
| 55 | esac |
| 56 | test $fixed_cnt -eq $expect_cnt || return 1 |
| 57 | |
| 58 | # and we are not missing anything |
| 59 | case "$1" in |
| 60 | '') expect_cnt=0 ;; |
| 61 | ?*) expect_cnt=$(grep "[$1]" <file | wc -l) ;; |
| 62 | esac |
| 63 | test $fixed_cnt -eq $expect_cnt || return 1 |
| 64 | |
| 65 | # Get the patch actually applied |
| 66 | git diff-files -p target >fixed-patch |
| 67 | test -s fixed-patch && return 0 |
| 68 | |
| 69 | # Make sure it is complaint-free |
| 70 | >target |
| 71 | git apply --whitespace=error-all <fixed-patch |
| 72 | |
| 73 | } |
| 74 | |
| 75 | test_expect_success setup ' |
| 76 | |
| 77 | >file && |
| 78 | git add file && |
| 79 | prepare_test_file >file && |
| 80 | git diff-files -p >patch && |
| 81 | >target && |
| 82 | git add target |
| 83 | |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'whitespace=nowarn, default rule' ' |
| 87 | |
| 88 | apply_patch --whitespace=nowarn && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 89 | test_cmp file target |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 90 | |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'whitespace=warn, default rule' ' |
| 94 | |
| 95 | apply_patch --whitespace=warn && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 96 | test_cmp file target |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 97 | |
| 98 | ' |
| 99 | |
| 100 | test_expect_success 'whitespace=error-all, default rule' ' |
| 101 | |
Jeff King | 0a5e3c5 | 2015-03-20 06:09:22 -0400 | [diff] [blame] | 102 | test_must_fail apply_patch --whitespace=error-all && |
SZEDER Gábor | ec10b01 | 2018-08-19 23:57:22 +0200 | [diff] [blame] | 103 | test_must_be_empty target |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 104 | |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'whitespace=error-all, no rule' ' |
| 108 | |
| 109 | git config core.whitespace -trailing,-space-before,-indent && |
| 110 | apply_patch --whitespace=error-all && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 111 | test_cmp file target |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 112 | |
| 113 | ' |
| 114 | |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 115 | test_expect_success 'whitespace=error-all, no rule (attribute)' ' |
| 116 | |
| 117 | git config --unset core.whitespace && |
| 118 | echo "target -whitespace" >.gitattributes && |
| 119 | apply_patch --whitespace=error-all && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 120 | test_cmp file target |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 121 | |
| 122 | ' |
| 123 | |
Johannes Sixt | d35711a | 2010-11-30 09:22:04 +0100 | [diff] [blame] | 124 | test_expect_success 'spaces inserted by tab-in-indent' ' |
| 125 | |
| 126 | git config core.whitespace -trailing,-space,-indent,tab && |
| 127 | rm -f .gitattributes && |
| 128 | test_fix % && |
| 129 | sed -e "s/_/ /g" -e "s/>/ /" <<-\EOF >expect && |
| 130 | An_SP in an ordinary line>and a HT. |
| 131 | ________A HT (%). |
| 132 | ________A SP and a HT (@%). |
| 133 | _________A SP, a HT and a SP (@%). |
| 134 | _______Seven SP. |
| 135 | ________Eight SP (#). |
| 136 | ________Seven SP and a HT (@%). |
| 137 | ________________Eight SP and a HT (@#%). |
| 138 | _________Seven SP, a HT and a SP (@%). |
| 139 | _________________Eight SP, a HT and a SP (@#%). |
| 140 | _______________Fifteen SP (#). |
| 141 | ________________Fifteen SP and a HT (@#%). |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 142 | ________________Sixteen SP (#=). |
| 143 | ________________________Sixteen SP and a HT (@#%=). |
Johannes Sixt | d35711a | 2010-11-30 09:22:04 +0100 | [diff] [blame] | 144 | _____a__Five SP, a non WS, two SP. |
| 145 | A line with a (!) trailing SP_ |
| 146 | A line with a (!) trailing HT> |
| 147 | EOF |
| 148 | test_cmp expect target |
| 149 | |
| 150 | ' |
| 151 | |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 152 | for t in - '' |
| 153 | do |
| 154 | case "$t" in '') tt='!' ;; *) tt= ;; esac |
| 155 | for s in - '' |
| 156 | do |
| 157 | case "$s" in '') ts='@' ;; *) ts= ;; esac |
| 158 | for i in - '' |
| 159 | do |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 160 | case "$i" in '') ti='#' ti16='=';; *) ti= ti16= ;; esac |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 161 | for h in - '' |
| 162 | do |
| 163 | [ -z "$h$i" ] && continue |
| 164 | case "$h" in '') th='%' ;; *) th= ;; esac |
| 165 | rule=${t}trailing,${s}space,${i}indent,${h}tab |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 166 | |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 167 | rm -f .gitattributes |
| 168 | test_expect_success "rule=$rule" ' |
| 169 | git config core.whitespace "$rule" && |
| 170 | test_fix "$tt$ts$ti$th" |
| 171 | ' |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 172 | |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 173 | test_expect_success "rule=$rule,tabwidth=16" ' |
| 174 | git config core.whitespace "$rule,tabwidth=16" && |
| 175 | test_fix "$tt$ts$ti16$th" |
| 176 | ' |
| 177 | |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 178 | test_expect_success "rule=$rule (attributes)" ' |
| 179 | git config --unset core.whitespace && |
| 180 | echo "target whitespace=$rule" >.gitattributes && |
| 181 | test_fix "$tt$ts$ti$th" |
| 182 | ' |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 183 | |
Johannes Sixt | f4b05a4 | 2010-11-30 09:29:11 +0100 | [diff] [blame] | 184 | test_expect_success "rule=$rule,tabwidth=16 (attributes)" ' |
| 185 | echo "target whitespace=$rule,tabwidth=16" >.gitattributes && |
| 186 | test_fix "$tt$ts$ti16$th" |
| 187 | ' |
| 188 | |
Chris Webb | a347b17 | 2010-04-03 00:37:37 +0100 | [diff] [blame] | 189 | done |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 190 | done |
| 191 | done |
| 192 | done |
| 193 | |
SZEDER Gábor | 735c674 | 2009-07-22 19:24:38 -0500 | [diff] [blame] | 194 | create_patch () { |
| 195 | sed -e "s/_/ /" <<-\EOF |
| 196 | diff --git a/target b/target |
| 197 | index e69de29..8bd6648 100644 |
| 198 | --- a/target |
| 199 | +++ b/target |
Junio C Hamano | 422a82f | 2009-07-25 01:29:20 -0700 | [diff] [blame] | 200 | @@ -0,0 +1,3 @@ |
| 201 | +An empty line follows |
| 202 | + |
SZEDER Gábor | 735c674 | 2009-07-22 19:24:38 -0500 | [diff] [blame] | 203 | +A line with trailing whitespace and no newline_ |
| 204 | \ No newline at end of file |
| 205 | EOF |
| 206 | } |
| 207 | |
| 208 | test_expect_success 'trailing whitespace & no newline at the end of file' ' |
| 209 | >target && |
Junio C Hamano | 422a82f | 2009-07-25 01:29:20 -0700 | [diff] [blame] | 210 | create_patch >patch-file && |
| 211 | git apply --whitespace=fix patch-file && |
| 212 | grep "newline$" target && |
| 213 | grep "^$" target |
SZEDER Gábor | 735c674 | 2009-07-22 19:24:38 -0500 | [diff] [blame] | 214 | ' |
| 215 | |
Junio C Hamano | ef2035c | 2009-09-04 01:41:47 -0700 | [diff] [blame] | 216 | test_expect_success 'blank at EOF with --whitespace=fix (1)' ' |
Jonathan Nieder | 33fc521 | 2010-10-31 02:41:08 -0500 | [diff] [blame] | 217 | test_might_fail git config --unset core.whitespace && |
| 218 | rm -f .gitattributes && |
Junio C Hamano | ef2035c | 2009-09-04 01:41:47 -0700 | [diff] [blame] | 219 | |
| 220 | { echo a; echo b; echo c; } >one && |
| 221 | git add one && |
| 222 | { echo a; echo b; echo c; } >expect && |
| 223 | { cat expect; echo; } >one && |
| 224 | git diff -- one >patch && |
| 225 | |
| 226 | git checkout one && |
| 227 | git apply --whitespace=fix patch && |
| 228 | test_cmp expect one |
| 229 | ' |
| 230 | |
| 231 | test_expect_success 'blank at EOF with --whitespace=fix (2)' ' |
| 232 | { echo a; echo b; echo c; } >one && |
| 233 | git add one && |
| 234 | { echo a; echo c; } >expect && |
| 235 | { cat expect; echo; echo; } >one && |
| 236 | git diff -- one >patch && |
| 237 | |
| 238 | git checkout one && |
| 239 | git apply --whitespace=fix patch && |
| 240 | test_cmp expect one |
| 241 | ' |
| 242 | |
Junio C Hamano | efa5744 | 2009-09-03 14:08:20 -0700 | [diff] [blame] | 243 | test_expect_success 'blank at EOF with --whitespace=fix (3)' ' |
| 244 | { echo a; echo b; echo; } >one && |
| 245 | git add one && |
| 246 | { echo a; echo c; echo; } >expect && |
| 247 | { cat expect; echo; echo; } >one && |
| 248 | git diff -- one >patch && |
| 249 | |
| 250 | git checkout one && |
| 251 | git apply --whitespace=fix patch && |
| 252 | test_cmp expect one |
| 253 | ' |
| 254 | |
| 255 | test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' ' |
| 256 | { echo a; echo b; echo; echo; echo; echo; echo; echo d; } >one && |
| 257 | git add one && |
| 258 | { echo a; echo c; echo; echo; echo; echo; echo; echo; echo d; } >expect && |
| 259 | cp expect one && |
| 260 | git diff -- one >patch && |
| 261 | |
| 262 | git checkout one && |
| 263 | git apply --whitespace=fix patch && |
| 264 | test_cmp expect one |
| 265 | ' |
| 266 | |
Junio C Hamano | 77b15bb | 2009-09-03 16:02:32 -0700 | [diff] [blame] | 267 | test_expect_success 'blank at EOF with --whitespace=warn' ' |
| 268 | { echo a; echo b; echo c; } >one && |
| 269 | git add one && |
| 270 | echo >>one && |
| 271 | cat one >expect && |
| 272 | git diff -- one >patch && |
| 273 | |
| 274 | git checkout one && |
| 275 | git apply --whitespace=warn patch 2>error && |
| 276 | test_cmp expect one && |
| 277 | grep "new blank line at EOF" error |
| 278 | ' |
| 279 | |
| 280 | test_expect_success 'blank at EOF with --whitespace=error' ' |
| 281 | { echo a; echo b; echo c; } >one && |
| 282 | git add one && |
| 283 | cat one >expect && |
| 284 | echo >>one && |
| 285 | git diff -- one >patch && |
| 286 | |
| 287 | git checkout one && |
| 288 | test_must_fail git apply --whitespace=error patch 2>error && |
| 289 | test_cmp expect one && |
| 290 | grep "new blank line at EOF" error |
| 291 | ' |
| 292 | |
Junio C Hamano | 94ea026 | 2009-09-04 02:25:57 -0700 | [diff] [blame] | 293 | test_expect_success 'blank but not empty at EOF' ' |
| 294 | { echo a; echo b; echo c; } >one && |
| 295 | git add one && |
| 296 | echo " " >>one && |
| 297 | cat one >expect && |
| 298 | git diff -- one >patch && |
| 299 | |
| 300 | git checkout one && |
| 301 | git apply --whitespace=warn patch 2>error && |
| 302 | test_cmp expect one && |
| 303 | grep "new blank line at EOF" error |
| 304 | ' |
| 305 | |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 306 | test_expect_success 'applying beyond EOF requires one non-blank context line' ' |
| 307 | { echo; echo; echo; echo; } >one && |
| 308 | git add one && |
| 309 | { echo b; } >>one && |
| 310 | git diff -- one >patch && |
| 311 | |
| 312 | git checkout one && |
| 313 | { echo a; echo; } >one && |
| 314 | cp one expect && |
| 315 | test_must_fail git apply --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 316 | test_cmp expect one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 317 | test_must_fail git apply --ignore-space-change --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 318 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 319 | ' |
| 320 | |
| 321 | test_expect_success 'tons of blanks at EOF should not apply' ' |
| 322 | for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do |
| 323 | echo; echo; echo; echo; |
| 324 | done >one && |
| 325 | git add one && |
| 326 | echo a >>one && |
| 327 | git diff -- one >patch && |
| 328 | |
| 329 | >one && |
| 330 | test_must_fail git apply --whitespace=fix patch && |
| 331 | test_must_fail git apply --ignore-space-change --whitespace=fix patch |
| 332 | ' |
| 333 | |
| 334 | test_expect_success 'missing blank line at end with --whitespace=fix' ' |
| 335 | echo a >one && |
| 336 | echo >>one && |
| 337 | git add one && |
| 338 | echo b >>one && |
| 339 | cp one expect && |
| 340 | git diff -- one >patch && |
| 341 | echo a >one && |
| 342 | cp one saved-one && |
| 343 | test_must_fail git apply patch && |
| 344 | git apply --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 345 | test_cmp expect one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 346 | mv saved-one one && |
| 347 | git apply --ignore-space-change --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 348 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 349 | ' |
| 350 | |
| 351 | test_expect_success 'two missing blank lines at end with --whitespace=fix' ' |
| 352 | { echo a; echo; echo b; echo c; } >one && |
| 353 | cp one no-blank-lines && |
| 354 | { echo; echo; } >>one && |
| 355 | git add one && |
| 356 | echo d >>one && |
| 357 | cp one expect && |
| 358 | echo >>one && |
| 359 | git diff -- one >patch && |
| 360 | cp no-blank-lines one && |
| 361 | test_must_fail git apply patch && |
| 362 | git apply --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 363 | test_cmp expect one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 364 | mv no-blank-lines one && |
| 365 | test_must_fail git apply patch && |
| 366 | git apply --ignore-space-change --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 367 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 368 | ' |
| 369 | |
Björn Gustavsson | 0c3ef98 | 2010-04-08 06:14:31 +0200 | [diff] [blame] | 370 | test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' ' |
| 371 | { echo a; echo; } >one && |
| 372 | git add one && |
| 373 | { echo b; echo a; echo; } >one && |
| 374 | cp one expect && |
| 375 | git diff -- one >patch && |
| 376 | echo a >one && |
| 377 | test_must_fail git apply patch && |
| 378 | git apply --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 379 | test_cmp expect one |
Björn Gustavsson | 0c3ef98 | 2010-04-08 06:14:31 +0200 | [diff] [blame] | 380 | ' |
| 381 | |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 382 | test_expect_success 'shrink file with tons of missing blanks at end of file' ' |
| 383 | { echo a; echo b; echo c; } >one && |
| 384 | cp one no-blank-lines && |
| 385 | for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do |
| 386 | echo; echo; echo; echo; |
| 387 | done >>one && |
| 388 | git add one && |
| 389 | echo a >one && |
| 390 | cp one expect && |
| 391 | git diff -- one >patch && |
| 392 | cp no-blank-lines one && |
| 393 | test_must_fail git apply patch && |
| 394 | git apply --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 395 | test_cmp expect one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 396 | mv no-blank-lines one && |
| 397 | git apply --ignore-space-change --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 398 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 399 | ' |
| 400 | |
| 401 | test_expect_success 'missing blanks at EOF must only match blank lines' ' |
| 402 | { echo a; echo b; } >one && |
| 403 | git add one && |
| 404 | { echo c; echo d; } >>one && |
| 405 | git diff -- one >patch && |
| 406 | |
| 407 | echo a >one && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 408 | test_must_fail git apply patch && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 409 | test_must_fail git apply --whitespace=fix patch && |
| 410 | test_must_fail git apply --ignore-space-change --whitespace=fix patch |
| 411 | ' |
| 412 | |
| 413 | sed -e's/Z//' >one <<EOF |
| 414 | a |
| 415 | b |
| 416 | c |
| 417 | Z |
| 418 | EOF |
| 419 | |
| 420 | test_expect_success 'missing blank line should match context line with spaces' ' |
| 421 | git add one && |
| 422 | echo d >>one && |
| 423 | git diff -- one >patch && |
| 424 | { echo a; echo b; echo c; } >one && |
| 425 | cp one expect && |
| 426 | { echo; echo d; } >>expect && |
| 427 | git add one && |
| 428 | |
| 429 | git apply --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 430 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 431 | ' |
| 432 | |
| 433 | sed -e's/Z//' >one <<EOF |
| 434 | a |
| 435 | b |
| 436 | c |
| 437 | Z |
| 438 | EOF |
| 439 | |
| 440 | test_expect_success 'same, but with the --ignore-space-option' ' |
| 441 | git add one && |
| 442 | echo d >>one && |
| 443 | cp one expect && |
| 444 | git diff -- one >patch && |
| 445 | { echo a; echo b; echo c; } >one && |
| 446 | git add one && |
| 447 | |
| 448 | git checkout-index -f one && |
| 449 | git apply --ignore-space-change --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 450 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 451 | ' |
| 452 | |
| 453 | test_expect_success 'same, but with CR-LF line endings && cr-at-eol set' ' |
| 454 | git config core.whitespace cr-at-eol && |
| 455 | printf "a\r\n" >one && |
| 456 | printf "b\r\n" >>one && |
| 457 | printf "c\r\n" >>one && |
| 458 | cp one save-one && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 459 | printf " \r\n" >>one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 460 | git add one && |
| 461 | printf "d\r\n" >>one && |
| 462 | cp one expect && |
| 463 | git diff -- one >patch && |
| 464 | mv save-one one && |
| 465 | |
| 466 | git apply --ignore-space-change --whitespace=fix patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 467 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 468 | ' |
| 469 | |
Torsten Bögershausen | c24f3ab | 2017-08-19 13:28:01 +0200 | [diff] [blame] | 470 | test_expect_success 'CR-LF line endings && add line && text=auto' ' |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 471 | git config --unset core.whitespace && |
| 472 | printf "a\r\n" >one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 473 | cp one save-one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 474 | git add one && |
Torsten Bögershausen | c24f3ab | 2017-08-19 13:28:01 +0200 | [diff] [blame] | 475 | printf "b\r\n" >>one && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 476 | cp one expect && |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 477 | git diff -- one >patch && |
| 478 | mv save-one one && |
Torsten Bögershausen | c24f3ab | 2017-08-19 13:28:01 +0200 | [diff] [blame] | 479 | echo "one text=auto" >.gitattributes && |
| 480 | git apply patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 481 | test_cmp expect one |
Torsten Bögershausen | c24f3ab | 2017-08-19 13:28:01 +0200 | [diff] [blame] | 482 | ' |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 483 | |
Torsten Bögershausen | c24f3ab | 2017-08-19 13:28:01 +0200 | [diff] [blame] | 484 | test_expect_success 'CR-LF line endings && change line && text=auto' ' |
| 485 | printf "a\r\n" >one && |
| 486 | cp one save-one && |
| 487 | git add one && |
| 488 | printf "b\r\n" >one && |
| 489 | cp one expect && |
| 490 | git diff -- one >patch && |
| 491 | mv save-one one && |
| 492 | echo "one text=auto" >.gitattributes && |
| 493 | git apply patch && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 494 | test_cmp expect one |
Torsten Bögershausen | c24f3ab | 2017-08-19 13:28:01 +0200 | [diff] [blame] | 495 | ' |
| 496 | |
| 497 | test_expect_success 'LF in repo, CRLF in worktree && change line && text=auto' ' |
| 498 | printf "a\n" >one && |
| 499 | git add one && |
| 500 | printf "b\r\n" >one && |
| 501 | git diff -- one >patch && |
| 502 | printf "a\r\n" >one && |
| 503 | echo "one text=auto" >.gitattributes && |
| 504 | git -c core.eol=CRLF apply patch && |
| 505 | printf "b\r\n" >expect && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 506 | test_cmp expect one |
Björn Gustavsson | c1376c1 | 2010-03-06 15:31:04 +0100 | [diff] [blame] | 507 | ' |
| 508 | |
Junio C Hamano | 250b3c6 | 2013-03-22 11:10:03 -0700 | [diff] [blame] | 509 | test_expect_success 'whitespace=fix to expand' ' |
| 510 | qz_to_tab_space >preimage <<-\EOF && |
| 511 | QQa |
| 512 | QQb |
| 513 | QQc |
| 514 | ZZZZZZZZZZZZZZZZd |
| 515 | QQe |
| 516 | QQf |
| 517 | QQg |
| 518 | EOF |
| 519 | qz_to_tab_space >patch <<-\EOF && |
| 520 | diff --git a/preimage b/preimage |
| 521 | --- a/preimage |
| 522 | +++ b/preimage |
| 523 | @@ -1,7 +1,6 @@ |
| 524 | QQa |
| 525 | QQb |
| 526 | QQc |
| 527 | -QQd |
| 528 | QQe |
| 529 | QQf |
| 530 | QQg |
| 531 | EOF |
| 532 | git -c core.whitespace=tab-in-indent apply --whitespace=fix patch |
| 533 | ' |
| 534 | |
Junio C Hamano | 477a08a | 2014-08-06 13:09:05 -0700 | [diff] [blame] | 535 | test_expect_success 'whitespace check skipped for excluded paths' ' |
| 536 | git config core.whitespace blank-at-eol && |
| 537 | >used && |
| 538 | >unused && |
| 539 | git add used unused && |
| 540 | echo "used" >used && |
| 541 | echo "unused " >unused && |
| 542 | git diff-files -p used unused >patch && |
| 543 | git apply --include=used --stat --whitespace=error <patch |
| 544 | ' |
| 545 | |
Junio C Hamano | d5a4164 | 2007-11-23 20:14:20 -0800 | [diff] [blame] | 546 | test_done |