Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git apply with rejects |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 7 | |
| 8 | ' |
| 9 | |
| 10 | . ./test-lib.sh |
| 11 | |
| 12 | test_expect_success setup ' |
| 13 | for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
| 14 | do |
| 15 | echo $i |
| 16 | done >file1 && |
| 17 | cat file1 >saved.file1 && |
| 18 | git update-index --add file1 && |
| 19 | git commit -m initial && |
| 20 | |
| 21 | for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 |
| 22 | do |
| 23 | echo $i |
| 24 | done >file1 && |
| 25 | git diff >patch.1 && |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 26 | cat file1 >clean && |
| 27 | |
| 28 | for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 |
| 29 | do |
| 30 | echo $i |
| 31 | done >expected && |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 32 | |
| 33 | mv file1 file2 && |
| 34 | git update-index --add --remove file1 file2 && |
| 35 | git diff -M HEAD >patch.2 && |
| 36 | |
| 37 | rm -f file1 file2 && |
| 38 | mv saved.file1 file1 && |
| 39 | git update-index --add --remove file1 file2 && |
| 40 | |
| 41 | for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 |
| 42 | do |
| 43 | echo $i |
| 44 | done >file1 && |
| 45 | |
| 46 | cat file1 >saved.file1 |
| 47 | ' |
| 48 | |
Junio C Hamano | cfb6f9a | 2012-05-08 13:21:53 -0700 | [diff] [blame] | 49 | test_expect_success 'apply --reject is incompatible with --3way' ' |
| 50 | test_when_finished "cat saved.file1 >file1" && |
| 51 | git diff >patch.0 && |
| 52 | git checkout file1 && |
| 53 | test_must_fail git apply --reject --3way patch.0 && |
| 54 | git diff --exit-code |
| 55 | ' |
| 56 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 57 | test_expect_success 'apply without --reject should fail' ' |
| 58 | |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 59 | test_must_fail git apply patch.1 && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 60 | test_cmp file1 saved.file1 |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 61 | ' |
| 62 | |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 63 | test_expect_success 'apply without --reject should fail' ' |
| 64 | |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 65 | test_must_fail git apply --verbose patch.1 && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 66 | test_cmp file1 saved.file1 |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 67 | ' |
| 68 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 69 | test_expect_success 'apply with --reject should fail but update the file' ' |
| 70 | |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 71 | cat saved.file1 >file1 && |
| 72 | rm -f file1.rej file2.rej && |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 73 | |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 74 | test_must_fail git apply --reject patch.1 && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 75 | test_cmp file1 expected && |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 76 | |
| 77 | cat file1.rej && |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 78 | test_path_is_missing file2.rej |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 79 | ' |
| 80 | |
| 81 | test_expect_success 'apply with --reject should fail but update the file' ' |
| 82 | |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 83 | cat saved.file1 >file1 && |
| 84 | rm -f file1.rej file2.rej file2 && |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 85 | |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 86 | test_must_fail git apply --reject patch.2 >rejects && |
| 87 | test_path_is_missing file1 && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 88 | test_cmp file2 expected && |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 89 | |
| 90 | cat file2.rej && |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 91 | test_path_is_missing file1.rej |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 92 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 93 | ' |
| 94 | |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 95 | test_expect_success 'the same test with --verbose' ' |
| 96 | |
| 97 | cat saved.file1 >file1 && |
| 98 | rm -f file1.rej file2.rej file2 && |
| 99 | |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 100 | test_must_fail git apply --reject --verbose patch.2 >rejects && |
| 101 | test_path_is_missing file1 && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 102 | test_cmp file2 expected && |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 103 | |
| 104 | cat file2.rej && |
Jeff King | e7d053d | 2015-03-20 06:13:18 -0400 | [diff] [blame] | 105 | test_path_is_missing file1.rej |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 106 | |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'apply cleanly with --verbose' ' |
| 110 | |
| 111 | git cat-file -p HEAD:file1 >file1 && |
| 112 | rm -f file?.rej file2 && |
| 113 | |
| 114 | git apply --verbose patch.1 && |
| 115 | |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 116 | test_cmp file1 clean |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 117 | ' |
| 118 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 119 | test_done |