Shawn O. Pearce | 79ee194 | 2007-04-04 11:19:14 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Shawn O. Pearce |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git apply -p handling.' |
Shawn O. Pearce | 79ee194 | 2007-04-04 11:19:14 -0400 | [diff] [blame] | 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success setup ' |
| 11 | mkdir sub && |
| 12 | echo A >sub/file1 && |
Jonathan Nieder | bb7306b | 2010-08-18 20:46:46 -0500 | [diff] [blame] | 13 | cp sub/file1 file1.saved && |
Shawn O. Pearce | 79ee194 | 2007-04-04 11:19:14 -0400 | [diff] [blame] | 14 | git add sub/file1 && |
| 15 | echo B >sub/file1 && |
| 16 | git diff >patch.file && |
Jonathan Nieder | bb7306b | 2010-08-18 20:46:46 -0500 | [diff] [blame] | 17 | git checkout -- sub/file1 && |
| 18 | git mv sub süb && |
| 19 | echo B >süb/file1 && |
| 20 | git diff >patch.escaped && |
| 21 | grep "[\]" patch.escaped && |
| 22 | rm süb/file1 && |
| 23 | rmdir süb |
Shawn O. Pearce | 79ee194 | 2007-04-04 11:19:14 -0400 | [diff] [blame] | 24 | ' |
| 25 | |
| 26 | test_expect_success 'apply git diff with -p2' ' |
Jonathan Nieder | bb7306b | 2010-08-18 20:46:46 -0500 | [diff] [blame] | 27 | cp file1.saved file1 && |
Shawn O. Pearce | 79ee194 | 2007-04-04 11:19:14 -0400 | [diff] [blame] | 28 | git apply -p2 patch.file |
| 29 | ' |
| 30 | |
Andreas Gruenbacher | 15862087 | 2010-01-17 03:05:10 +0100 | [diff] [blame] | 31 | test_expect_success 'apply with too large -p' ' |
Jonathan Nieder | bb7306b | 2010-08-18 20:46:46 -0500 | [diff] [blame] | 32 | cp file1.saved file1 && |
Andreas Gruenbacher | 15862087 | 2010-01-17 03:05:10 +0100 | [diff] [blame] | 33 | test_must_fail git apply --stat -p3 patch.file 2>err && |
Jiang Xin | 76638d9 | 2012-08-27 13:36:52 +0800 | [diff] [blame] | 34 | test_i18ngrep "removing 3 leading" err |
Andreas Gruenbacher | 15862087 | 2010-01-17 03:05:10 +0100 | [diff] [blame] | 35 | ' |
| 36 | |
Jonathan Nieder | bb7306b | 2010-08-18 20:46:46 -0500 | [diff] [blame] | 37 | test_expect_success 'apply (-p2) traditional diff with funny filenames' ' |
| 38 | cat >patch.quotes <<-\EOF && |
| 39 | diff -u "a/"sub/file1 "b/"sub/file1 |
| 40 | --- "a/"sub/file1 |
| 41 | +++ "b/"sub/file1 |
| 42 | @@ -1 +1 @@ |
| 43 | -A |
| 44 | +B |
| 45 | EOF |
| 46 | echo B >expected && |
| 47 | |
| 48 | cp file1.saved file1 && |
| 49 | git apply -p2 patch.quotes && |
| 50 | test_cmp expected file1 |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'apply with too large -p and fancy filename' ' |
| 54 | cp file1.saved file1 && |
| 55 | test_must_fail git apply --stat -p3 patch.escaped 2>err && |
Jiang Xin | 76638d9 | 2012-08-27 13:36:52 +0800 | [diff] [blame] | 56 | test_i18ngrep "removing 3 leading" err |
Jonathan Nieder | bb7306b | 2010-08-18 20:46:46 -0500 | [diff] [blame] | 57 | ' |
| 58 | |
Junio C Hamano | aae1f6a | 2010-10-21 22:09:40 -0700 | [diff] [blame] | 59 | test_expect_success 'apply (-p2) diff, mode change only' ' |
| 60 | cat >patch.chmod <<-\EOF && |
| 61 | diff --git a/sub/file1 b/sub/file1 |
| 62 | old mode 100644 |
| 63 | new mode 100755 |
| 64 | EOF |
Johannes Sixt | 97a853d | 2011-02-03 15:31:43 +0000 | [diff] [blame] | 65 | test_chmod -x file1 && |
| 66 | git apply --index -p2 patch.chmod && |
| 67 | case $(git ls-files -s file1) in 100755*) : good;; *) false;; esac |
| 68 | ' |
| 69 | |
| 70 | test_expect_success FILEMODE 'file mode was changed' ' |
Junio C Hamano | aae1f6a | 2010-10-21 22:09:40 -0700 | [diff] [blame] | 71 | test -x file1 |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'apply (-p2) diff, rename' ' |
| 75 | cat >patch.rename <<-\EOF && |
| 76 | diff --git a/sub/file1 b/sub/file2 |
| 77 | similarity index 100% |
| 78 | rename from sub/file1 |
| 79 | rename to sub/file2 |
| 80 | EOF |
| 81 | echo A >expected && |
| 82 | |
| 83 | cp file1.saved file1 && |
| 84 | rm -f file2 && |
| 85 | git apply -p2 patch.rename && |
| 86 | test_cmp expected file2 |
| 87 | ' |
| 88 | |
Shawn O. Pearce | 79ee194 | 2007-04-04 11:19:14 -0400 | [diff] [blame] | 89 | test_done |