Skip to content

Commit c51c0da

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Helped-by: Johannes Sixt <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb7306b commit c51c0da

19 files changed

+213
-0
lines changed

t/t4135-apply-weird-filenames.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/file-creation/
2+
/trad-creation/
3+
/trad-modification/

t/t4135/add-plain.diff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)