interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4100-apply-stat.sh

140 lines · 3181 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='git apply --stat --summary test, with --recount
7
8'
9
10. ./test-lib.sh
11
12UNC='s/^\(@@ -[1-9][0-9]*\),[0-9]* \(+[1-9][0-9]*\),[0-9]* @@/\1,999 \2,999 @@/'
13
14num=0
15while read title
16do
17 num=$(( $num + 1 ))
18 test_expect_success "$title" '
19 git apply --stat --summary \
20 <"$TEST_DIRECTORY/t4100/t-apply-$num.patch" >current &&
21 test_cmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current
22 '
23
24 test_expect_success "$title with recount" '
25 sed -e "$UNC" <"$TEST_DIRECTORY/t4100/t-apply-$num.patch" |
26 git apply --recount --stat --summary >current &&
27 test_cmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current
28 '
29done <<\EOF
30rename
31copy
32rewrite
33mode
34non git (1)
35non git (2)
36non git (3)
37incomplete (1)
38incomplete (2)
39EOF
40
41test_expect_success 'applying a hunk header which overflows fails' '
42 cat >patch <<-\EOF &&
43 diff -u a/file b/file
44 --- a/file
45 +++ b/file
46 @@ -98765432109876543210 +98765432109876543210 @@
47 -a
48 +b
49 EOF
50 test_must_fail git apply patch 2>err &&
51 echo "error: corrupt patch at patch:4" >expect &&
52 test_cmp expect err
53'
54
55test_expect_success 'applying a hunk header which overflows from stdin fails' '
56 cat >patch <<-\EOF &&
57 diff -u a/file b/file
58 --- a/file
59 +++ b/file
60 @@ -98765432109876543210 +98765432109876543210 @@
61 -a
62 +b
63 EOF
64 test_must_fail git apply <patch 2>err &&
65 echo "error: corrupt patch at <stdin>:4" >expect &&
66 test_cmp expect err
67'
68
69test_expect_success 'applying multiple patches reports the corrupted input' '
70 cat >good.patch <<-\EOF &&
71 diff -u a/file b/file
72 --- a/file
73 +++ b/file
74 @@ -1 +1 @@
75 -a
76 +b
77 EOF
78 cat >bad.patch <<-\EOF &&
79 diff -u a/file b/file
80 --- a/file
81 +++ b/file
82 @@ -98765432109876543210 +98765432109876543210 @@
83 -a
84 +b
85 EOF
86 test_must_fail git apply --stat --summary good.patch bad.patch 2>err &&
87 echo "error: corrupt patch at bad.patch:4" >expect &&
88 test_cmp expect err
89'
90
91test_expect_success 'applying a patch without a header reports the input' '
92 cat >fragment.patch <<-\EOF &&
93 @@ -1 +1 @@
94 -a
95 +b
96 EOF
97 test_must_fail git apply fragment.patch 2>err &&
98 echo "error: patch fragment without header at fragment.patch:1: @@ -1 +1 @@" >expect &&
99 test_cmp expect err
100'
101
102test_expect_success 'applying a patch with a missing filename reports the input' '
103 cat >missing.patch <<-\EOF &&
104 diff --git a/f b/f
105 index 7898192..6178079 100644
106 --- a/f
107 @@ -1 +1 @@
108 -a
109 +b
110 EOF
111 test_must_fail git apply missing.patch 2>err &&
112 echo "error: git diff header lacks filename information at missing.patch:4" >expect &&
113 test_cmp expect err
114'
115
116test_expect_success 'applying a patch with an invalid mode reports the input' '
117 cat >mode.patch <<-\EOF &&
118 diff --git a/f b/f
119 old mode 10x644
120 EOF
121 test_must_fail git apply mode.patch 2>err &&
122 cat >expect <<-\EOF &&
123 error: invalid mode at mode.patch:2: 10x644
124
125 EOF
126 test_cmp expect err
127'
128
129test_expect_success 'applying a patch with only garbage reports the input' '
130 cat >garbage.patch <<-\EOF &&
131 diff --git a/f b/f
132 --- a/f
133 +++ b/f
134 this is garbage
135 EOF
136 test_must_fail git apply garbage.patch 2>err &&
137 echo "error: patch with only garbage at garbage.patch:4" >expect &&
138 test_cmp expect err
139'
140test_done