blob: dfec1c5f0f63fca3b0f0f47d2296be93c0e4f1ed [file] [log] [blame]
Brandon Caseycc64b312011-12-03 14:35:50 -06001#!/bin/sh
2
3test_description='git apply should exit non-zero with unrecognized input.'
4
Ævar Arnfjörð Bjarmasonf54f48f2021-10-31 00:24:18 +02005
6TEST_PASSES_SANITIZE_LEAK=true
Brandon Caseycc64b312011-12-03 14:35:50 -06007. ./test-lib.sh
8
9test_expect_success 'setup' '
10 test_commit 1
11'
12
13test_expect_success 'apply --check exits non-zero with unrecognized input' '
14 test_must_fail git apply --check - <<-\EOF
15 I am not a patch
16 I look nothing like a patch
17 git apply must fail
18 EOF
19'
20
Junio C Hamanoad6e8ed2015-06-01 12:12:04 -070021test_expect_success 'apply exits non-zero with no-op patch' '
22 cat >input <<-\EOF &&
23 diff --get a/1 b/1
24 index 6696ea4..606eddd 100644
25 --- a/1
26 +++ b/1
27 @@ -1,1 +1,1 @@
28 1
29 EOF
30 test_must_fail git apply --stat input &&
31 test_must_fail git apply --check input
32'
33
Johannes Schindelin22cb3832018-11-12 12:54:49 -080034test_expect_success '`apply --recount` allows no-op patch' '
35 echo 1 >1 &&
36 git apply --recount --check <<-\EOF
37 diff --get a/1 b/1
38 index 6696ea4..606eddd 100644
39 --- a/1
40 +++ b/1
41 @@ -1,1 +1,1 @@
42 1
43 EOF
44'
45
René Scharfed70e9c52017-06-27 19:03:39 +020046test_expect_success 'invalid combination: create and copy' '
47 test_must_fail git apply --check - <<-\EOF
48 diff --git a/1 b/2
49 new file mode 100644
50 copy from 1
51 copy to 2
52 EOF
53'
54
55test_expect_success 'invalid combination: create and rename' '
56 test_must_fail git apply --check - <<-\EOF
57 diff --git a/1 b/2
58 new file mode 100644
59 rename from 1
60 rename to 2
61 EOF
62'
63
Brandon Caseycc64b312011-12-03 14:35:50 -060064test_done