@matheusbsbs / matheus-bagliano / commits / c51c0da222
Fork 0

tests: exercise "git apply" with weird filenames

Check that "git apply" can cope with strange filenames, particularly filenames with spaces. Not all platforms have a sane enough diff -u and expand to reliably create the such patches and maybe future versions of GNU diff will handle funny characters differently, so this uses pre-generated patches. The script used to generate them is in t/t4135/make-patches. Filenames with tabs are not usable on NTFS; use something like the FUNNYNAMES prerequisite from v1.3.0-rc1~67 (2006-03-03) to skip the relevant tests when appropriate. The detection is not shared in test-lib.sh to avoid wasting time while running other test scripts. Backslash is the path separator on Windows, so do not used it in file names there (v1.6.3-rc0~93^2~6, 2009-03-13). Finally, filenames starting with a quotation mark do not behave well in msys (see v1.7.0-rc0~94^2, t4030, t4031: work around bogus MSYS bash path conversion, 2010-01-01), so skip those tests on Windows, too. Helped-by: Andreas Schwab <schwab@linux-m68k.org> Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Aug 18, 2010 at 20:48 UTC c51c0da2225d65ec1984d40bacbc3f43a0bfa178
19 files changed +213
t/t4135-apply-weird-filenames.sh new
+75
@@ -0,0 +1,75 @@
1 +#!/bin/sh
2 +
3 +test_description='git apply with weird postimage filenames'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success 'setup' '
8 + vector=$TEST_DIRECTORY/t4135 &&
9 +
10 + test_tick &&
11 + git commit --allow-empty -m preimage &&
12 + git tag preimage &&
13 +
14 + reset_preimage() {
15 + git checkout -f preimage^0 &&
16 + git read-tree -u --reset HEAD &&
17 + git update-index --refresh
18 + } &&
19 +
20 + test_when_finished "rm -f \"tab embedded.txt\"" &&
21 + test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" &&
22 + if touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
23 + then
24 + test_set_prereq FUNNYNAMES
25 + fi
26 +'
27 +
28 +try_filename() {
29 + desc=$1
30 + postimage=$2
31 + prereq=${3:-}
32 + exp1=${4:-success}
33 + exp2=${5:-success}
34 + exp3=${6:-success}
35 +
36 + test_expect_$exp1 $prereq "$desc, git-style file creation patch" "
37 + echo postimage >expected &&
38 + reset_preimage &&
39 + rm -f '$postimage' &&
40 + git apply -v \"\$vector\"/'git-$desc.diff' &&
41 + test_cmp expected '$postimage'
42 + "
43 +
44 + test_expect_$exp2 $prereq "$desc, traditional patch" "
45 + echo postimage >expected &&
46 + reset_preimage &&
47 + echo preimage >'$postimage' &&
48 + git apply -v \"\$vector\"/'diff-$desc.diff' &&
49 + test_cmp expected '$postimage'
50 + "
51 +
52 + test_expect_$exp3 $prereq "$desc, traditional file creation patch" "
53 + echo postimage >expected &&
54 + reset_preimage &&
55 + rm -f '$postimage' &&
56 + git apply -v \"\$vector\"/'add-$desc.diff' &&
57 + test_cmp expected '$postimage'
58 + "
59 +}
60 +
61 +try_filename 'plain' 'postimage.txt'
62 +try_filename 'with spaces' 'post image.txt' '' success failure failure
63 +try_filename 'with tab' 'post image.txt' FUNNYNAMES success failure failure
64 +try_filename 'with backslash' 'post\image.txt' BSLASHPSPEC
65 +try_filename 'with quote' '"postimage".txt' FUNNYNAMES success failure success
66 +
67 +test_expect_success 'whitespace-damaged traditional patch' '
68 + echo postimage >expected &&
69 + reset_preimage &&
70 + rm -f postimage.txt &&
71 + git apply -v "$vector/damaged.diff" &&
72 + test_cmp expected postimage.txt
73 +'
74 +
75 +test_done
t/t4135/.gitignore new
+3
@@ -0,0 +1,3 @@
1 +/file-creation/
2 +/trad-creation/
3 +/trad-modification/
t/t4135/add-plain.diff new
+5
@@ -0,0 +1,5 @@
1 +diff -pruN a/postimage.txt b/postimage.txt
2 +--- a/postimage.txt 1969-12-31 18:00:00.000000000 -0600
3 ++++ b/postimage.txt 2010-08-18 20:13:31.484002255 -0500
4 +@@ -0,0 +1 @@
5 ++postimage
t/t4135/add-with backslash.diff new
+5
@@ -0,0 +1,5 @@
1 +diff -pruN a/post\image.txt b/post\image.txt
2 +--- a/post\image.txt 1969-12-31 18:00:00.000000000 -0600
3 ++++ b/post\image.txt 2010-08-18 20:13:31.692002255 -0500
4 +@@ -0,0 +1 @@
5 ++postimage
t/t4135/add-with quote.diff new
+5
@@ -0,0 +1,5 @@
1 +diff -pruN a/"postimage".txt b/"postimage".txt
2 +--- a/"postimage".txt 1969-12-31 18:00:00.000000000 -0600
3 ++++ b/"postimage".txt 2010-08-18 20:13:31.756002255 -0500
4 +@@ -0,0 +1 @@
5 ++postimage
t/t4135/add-with spaces.diff new
+5
@@ -0,0 +1,5 @@
1 +diff -pruN a/post image.txt b/post image.txt
2 +--- a/post image.txt 1969-12-31 18:00:00.000000000 -0600
3 ++++ b/post image.txt 2010-08-18 20:13:31.556002255 -0500
4 +@@ -0,0 +1 @@
5 ++postimage
t/t4135/add-with tab.diff new
+5
@@ -0,0 +1,5 @@
1 +diff -pruN a/post image.txt b/post image.txt
2 +--- a/post image.txt 1969-12-31 18:00:00.000000000 -0600
3 ++++ b/post image.txt 2010-08-18 20:13:31.628002255 -0500
4 +@@ -0,0 +1 @@
5 ++postimage
t/t4135/damaged.diff new
+5
@@ -0,0 +1,5 @@
1 +diff -pruN a/postimage.txt b/postimage.txt
2 +--- a/postimage.txt 1969-12-31 18:00:00.000000000 -0600
3 ++++ b/postimage.txt 2010-08-18 20:13:31.484002255 -0500
4 +@@ -0,0 +1 @@
5 ++postimage
t/t4135/diff-plain.diff new
+5
@@ -0,0 +1,5 @@
1 +--- postimage.txt.orig 2010-08-18 20:13:31.432002255 -0500
2 ++++ postimage.txt 2010-08-18 20:13:31.432002255 -0500
3 +@@ -1 +1 @@
4 +-preimage
5 ++postimage
t/t4135/diff-with backslash.diff new
+5
@@ -0,0 +1,5 @@
1 +--- post\image.txt.orig 2010-08-18 20:13:31.680002255 -0500
2 ++++ post\image.txt 2010-08-18 20:13:31.680002255 -0500
3 +@@ -1 +1 @@
4 +-preimage
5 ++postimage
t/t4135/diff-with quote.diff new
+5
@@ -0,0 +1,5 @@
1 +--- "postimage".txt.orig 2010-08-18 20:13:31.744002255 -0500
2 ++++ "postimage".txt 2010-08-18 20:13:31.744002255 -0500
3 +@@ -1 +1 @@
4 +-preimage
5 ++postimage
t/t4135/diff-with spaces.diff new
+5
@@ -0,0 +1,5 @@
1 +--- post image.txt.orig 2010-08-18 20:13:31.544002255 -0500
2 ++++ post image.txt 2010-08-18 20:13:31.544002255 -0500
3 +@@ -1 +1 @@
4 +-preimage
5 ++postimage
t/t4135/diff-with tab.diff new
+5
@@ -0,0 +1,5 @@
1 +--- post image.txt.orig 2010-08-18 20:13:31.616002255 -0500
2 ++++ post image.txt 2010-08-18 20:13:31.616002255 -0500
3 +@@ -1 +1 @@
4 +-preimage
5 ++postimage
t/t4135/git-plain.diff new
+7
@@ -0,0 +1,7 @@
1 +diff --git a/postimage.txt b/postimage.txt
2 +new file mode 100644
3 +index 0000000..eff0c54
4 +--- /dev/null
5 ++++ b/postimage.txt
6 +@@ -0,0 +1 @@
7 ++postimage
t/t4135/git-with backslash.diff new
+7
@@ -0,0 +1,7 @@
1 +diff --git "a/post\\image.txt" "b/post\\image.txt"
2 +new file mode 100644
3 +index 0000000..eff0c54
4 +--- /dev/null
5 ++++ "b/post\\image.txt"
6 +@@ -0,0 +1 @@
7 ++postimage
t/t4135/git-with quote.diff new
+7
@@ -0,0 +1,7 @@
1 +diff --git "a/\"postimage\".txt" "b/\"postimage\".txt"
2 +new file mode 100644
3 +index 0000000..eff0c54
4 +--- /dev/null
5 ++++ "b/\"postimage\".txt"
6 +@@ -0,0 +1 @@
7 ++postimage
t/t4135/git-with spaces.diff new
+7
@@ -0,0 +1,7 @@
1 +diff --git a/post image.txt b/post image.txt
2 +new file mode 100644
3 +index 0000000..eff0c54
4 +--- /dev/null
5 ++++ b/post image.txt
6 +@@ -0,0 +1 @@
7 ++postimage
t/t4135/git-with tab.diff new
+7
@@ -0,0 +1,7 @@
1 +diff --git "a/post\timage.txt" "b/post\timage.txt"
2 +new file mode 100644
3 +index 0000000..eff0c54
4 +--- /dev/null
5 ++++ "b/post\timage.txt"
6 +@@ -0,0 +1 @@
7 ++postimage
t/t4135/make-patches new
+45
@@ -0,0 +1,45 @@
1 +#!/bin/sh
2 +
3 +do_filename() {
4 + desc=$1
5 + postimage=$2
6 +
7 + rm -fr file-creation &&
8 + git init file-creation &&
9 + (
10 + cd file-creation &&
11 + git commit --allow-empty -m init &&
12 + echo postimage >"$postimage" &&
13 + git add -N "$postimage" &&
14 + git diff HEAD >"../git-$desc.diff"
15 + ) &&
16 +
17 + rm -fr trad-modification &&
18 + mkdir trad-modification &&
19 + (
20 + cd trad-modification &&
21 + echo preimage >"$postimage.orig" &&
22 + echo postimage >"$postimage" &&
23 + ! diff -u "$postimage.orig" "$postimage" >"../diff-$desc.diff"
24 + ) &&
25 +
26 + rm -fr trad-creation &&
27 + mkdir trad-creation &&
28 + (
29 + cd trad-creation &&
30 + mkdir a b &&
31 + echo postimage >"b/$postimage" &&
32 + ! diff -pruN a b >"../add-$desc.diff"
33 + )
34 +}
35 +
36 +do_filename plain postimage.txt &&
37 +do_filename 'with spaces' 'post image.txt' &&
38 +do_filename 'with tab' 'post image.txt' &&
39 +do_filename 'with backslash' 'post\image.txt' &&
40 +do_filename 'with quote' '"postimage".txt' &&
41 +expand add-plain.diff >damaged.diff ||
42 +{
43 + echo >&2 Failed. &&
44 + exit 1
45 +}