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 | |
| 49 | test_expect_success 'apply without --reject should fail' ' |
| 50 | |
| 51 | if git apply patch.1 |
| 52 | then |
| 53 | echo "Eh? Why?" |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 57 | test_cmp file1 saved.file1 |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 58 | ' |
| 59 | |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 60 | test_expect_success 'apply without --reject should fail' ' |
| 61 | |
| 62 | if git apply --verbose patch.1 |
| 63 | then |
| 64 | echo "Eh? Why?" |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 68 | test_cmp file1 saved.file1 |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 69 | ' |
| 70 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 71 | test_expect_success 'apply with --reject should fail but update the file' ' |
| 72 | |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 73 | cat saved.file1 >file1 && |
| 74 | rm -f file1.rej file2.rej && |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 75 | |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 76 | if git apply --reject patch.1 |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 77 | then |
| 78 | echo "succeeds with --reject?" |
| 79 | exit 1 |
| 80 | fi |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 81 | |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 82 | test_cmp file1 expected && |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 83 | |
| 84 | cat file1.rej && |
| 85 | |
| 86 | if test -f file2.rej |
| 87 | then |
| 88 | echo "file2 should not have been touched" |
| 89 | exit 1 |
| 90 | fi |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 91 | ' |
| 92 | |
| 93 | test_expect_success 'apply with --reject should fail but update the file' ' |
| 94 | |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 95 | cat saved.file1 >file1 && |
| 96 | rm -f file1.rej file2.rej file2 && |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 97 | |
| 98 | if git apply --reject patch.2 >rejects |
| 99 | then |
| 100 | echo "succeeds with --reject?" |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 104 | test -f file1 && { |
| 105 | echo "file1 still exists?" |
| 106 | exit 1 |
| 107 | } |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 108 | test_cmp file2 expected && |
Junio C Hamano | 82e2765 | 2006-08-18 03:10:19 -0700 | [diff] [blame] | 109 | |
| 110 | cat file2.rej && |
| 111 | |
| 112 | if test -f file1.rej |
| 113 | then |
| 114 | echo "file2 should not have been touched" |
| 115 | exit 1 |
| 116 | fi |
| 117 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 118 | ' |
| 119 | |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 120 | test_expect_success 'the same test with --verbose' ' |
| 121 | |
| 122 | cat saved.file1 >file1 && |
| 123 | rm -f file1.rej file2.rej file2 && |
| 124 | |
| 125 | if git apply --reject --verbose patch.2 >rejects |
| 126 | then |
| 127 | echo "succeeds with --reject?" |
| 128 | exit 1 |
| 129 | fi |
| 130 | |
| 131 | test -f file1 && { |
| 132 | echo "file1 still exists?" |
| 133 | exit 1 |
| 134 | } |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 135 | test_cmp file2 expected && |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 136 | |
| 137 | cat file2.rej && |
| 138 | |
| 139 | if test -f file1.rej |
| 140 | then |
| 141 | echo "file2 should not have been touched" |
| 142 | exit 1 |
| 143 | fi |
| 144 | |
| 145 | ' |
| 146 | |
| 147 | test_expect_success 'apply cleanly with --verbose' ' |
| 148 | |
| 149 | git cat-file -p HEAD:file1 >file1 && |
| 150 | rm -f file?.rej file2 && |
| 151 | |
| 152 | git apply --verbose patch.1 && |
| 153 | |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 154 | test_cmp file1 clean |
Junio C Hamano | a2bf404 | 2006-08-18 03:14:48 -0700 | [diff] [blame] | 155 | ' |
| 156 | |
Junio C Hamano | 57dc397 | 2006-08-16 17:55:29 -0700 | [diff] [blame] | 157 | test_done |