Skip to content

Commit 4190564

Browse files
committed
Merge branch 'ag/patch-header-verify'
* ag/patch-header-verify: builtin-apply.c: fix the --- and +++ header filename consistency check
2 parents 06dbc1e + da91593 commit 4190564

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

builtin-apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
692692
if (isnull)
693693
die("git apply: bad git-diff - expected /dev/null, got %s on line %d", name, linenr);
694694
another = find_name(line, NULL, p_value, TERM_TAB);
695-
if (!another || memcmp(another, name, len))
695+
if (!another || memcmp(another, name, len + 1))
696696
die("git apply: bad git-diff - inconsistent %s filename on line %d", oldnew, linenr);
697697
free(another);
698698
return orig_name;

t/t4133-apply-filenames.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2010 Andreas Gruenbacher
4+
#
5+
6+
test_description='git apply filename consistency check'
7+
8+
. ./test-lib.sh
9+
10+
test_expect_success setup '
11+
cat > bad1.patch <<EOF
12+
diff --git a/f b/f
13+
new file mode 100644
14+
index 0000000..d00491f
15+
--- /dev/null
16+
+++ b/f-blah
17+
@@ -0,0 +1 @@
18+
+1
19+
EOF
20+
cat > bad2.patch <<EOF
21+
diff --git a/f b/f
22+
deleted file mode 100644
23+
index d00491f..0000000
24+
--- b/f-blah
25+
+++ /dev/null
26+
@@ -1 +0,0 @@
27+
-1
28+
EOF
29+
'
30+
31+
test_expect_success 'apply diff with inconsistent filenames in headers' '
32+
test_must_fail git apply bad1.patch 2>err
33+
grep "inconsistent new filename" err
34+
test_must_fail git apply bad2.patch 2>err
35+
grep "inconsistent old filename" err
36+
'
37+
38+
test_done

0 commit comments

Comments
 (0)