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