| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git apply should exit non-zero with unrecognized input.' |
| 4 | |
| 5 | |
| 6 | . ./test-lib.sh |
| 7 | |
| 8 | test_expect_success 'setup' ' |
| 9 | test_commit 1 |
| 10 | ' |
| 11 | |
| 12 | test_expect_success 'apply --check exits non-zero with unrecognized input' ' |
| 13 | test_must_fail git apply --check - <<-\EOF |
| 14 | I am not a patch |
| 15 | I look nothing like a patch |
| 16 | git apply must fail |
| 17 | EOF |
| 18 | ' |
| 19 | |
| 20 | test_expect_success 'apply exits non-zero with no-op patch' ' |
| 21 | cat >input <<-\EOF && |
| 22 | diff --get a/1 b/1 |
| 23 | index 6696ea4..606eddd 100644 |
| 24 | --- a/1 |
| 25 | +++ b/1 |
| 26 | @@ -1,1 +1,1 @@ |
| 27 | 1 |
| 28 | EOF |
| 29 | test_must_fail git apply --stat input && |
| 30 | test_must_fail git apply --check input |
| 31 | ' |
| 32 | |
| 33 | test_expect_success '`apply --recount` allows no-op patch' ' |
| 34 | echo 1 >1 && |
| 35 | git apply --recount --check <<-\EOF |
| 36 | diff --get a/1 b/1 |
| 37 | index 6696ea4..606eddd 100644 |
| 38 | --- a/1 |
| 39 | +++ b/1 |
| 40 | @@ -1,1 +1,1 @@ |
| 41 | 1 |
| 42 | EOF |
| 43 | ' |
| 44 | |
| 45 | test_expect_success 'invalid combination: create and copy' ' |
| 46 | test_must_fail git apply --check - <<-\EOF |
| 47 | diff --git a/1 b/2 |
| 48 | new file mode 100644 |
| 49 | copy from 1 |
| 50 | copy to 2 |
| 51 | EOF |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'invalid combination: create and rename' ' |
| 55 | test_must_fail git apply --check - <<-\EOF |
| 56 | diff --git a/1 b/2 |
| 57 | new file mode 100644 |
| 58 | rename from 1 |
| 59 | rename to 2 |
| 60 | EOF |
| 61 | ' |
| 62 | |
| 63 | test_done |