Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2010 Andreas Gruenbacher
4 #
5
6 test_description='git apply filename consistency check'
7
8
9 . ./test-lib.sh
10
11 test_expect_success setup '
12 cat > bad1.patch <<EOF &&
13 diff --git a/f b/f
14 new file mode 100644
15 index 0000000..d00491f
16 --- /dev/null
17 +++ b/f-blah
18 @@ -0,0 +1 @@
19 +1
20 EOF
21 cat > bad2.patch <<EOF
22 diff --git a/f b/f
23 deleted file mode 100644
24 index d00491f..0000000
25 --- b/f-blah
26 +++ /dev/null
27 @@ -1 +0,0 @@
28 -1
29 EOF
30 '
31
32 test_expect_success 'apply diff with inconsistent filenames in headers' '
33 test_must_fail git apply bad1.patch 2>err &&
34 test_grep "inconsistent new filename" err &&
35 test_must_fail git apply bad2.patch 2>err &&
36 test_grep "inconsistent old filename" err
37 '
38
39 test_expect_success 'apply diff with new filename missing from headers' '
40 cat >missing_new_filename.diff <<-\EOF &&
41 diff --git a/f b/f
42 index 0000000..d00491f
43 --- a/f
44 @@ -0,0 +1 @@
45 +1
46 EOF
47 test_must_fail git apply missing_new_filename.diff 2>err &&
48 test_grep "lacks filename information" err
49 '
50
51 test_expect_success 'apply diff with old filename missing from headers' '
52 cat >missing_old_filename.diff <<-\EOF &&
53 diff --git a/f b/f
54 index d00491f..0000000
55 +++ b/f
56 @@ -1 +0,0 @@
57 -1
58 EOF
59 test_must_fail git apply missing_old_filename.diff 2>err &&
60 test_grep "lacks filename information" err
61 '
62
63 test_done