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