Commit c51c0da2 authored by Jonathan Nieder's avatar Jonathan Nieder Committed by Junio C Hamano

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's avatarAndreas Schwab <[email protected]>
Helped-by: default avatarJohannes Sixt <[email protected]>
Signed-off-by: default avatarJonathan Nieder <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent bb7306b5
#!/bin/sh
test_description='git apply with weird postimage filenames'
. ./test-lib.sh
test_expect_success 'setup' '
vector=$TEST_DIRECTORY/t4135 &&
test_tick &&
git commit --allow-empty -m preimage &&
git tag preimage &&
reset_preimage() {
git checkout -f preimage^0 &&
git read-tree -u --reset HEAD &&
git update-index --refresh
} &&
test_when_finished "rm -f \"tab embedded.txt\"" &&
test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" &&
if touch -- "tab embedded.txt" '\''"quoteembedded".txt'\''
then
test_set_prereq FUNNYNAMES
fi
'
try_filename() {
desc=$1
postimage=$2
prereq=${3:-}
exp1=${4:-success}
exp2=${5:-success}
exp3=${6:-success}
test_expect_$exp1 $prereq "$desc, git-style file creation patch" "
echo postimage >expected &&
reset_preimage &&
rm -f '$postimage' &&
git apply -v \"\$vector\"/'git-$desc.diff' &&
test_cmp expected '$postimage'
"
test_expect_$exp2 $prereq "$desc, traditional patch" "
echo postimage >expected &&
reset_preimage &&
echo preimage >'$postimage' &&
git apply -v \"\$vector\"/'diff-$desc.diff' &&
test_cmp expected '$postimage'
"
test_expect_$exp3 $prereq "$desc, traditional file creation patch" "
echo postimage >expected &&
reset_preimage &&
rm -f '$postimage' &&
git apply -v \"\$vector\"/'add-$desc.diff' &&
test_cmp expected '$postimage'
"
}
try_filename 'plain' 'postimage.txt'
try_filename 'with spaces' 'post image.txt' '' success failure failure
try_filename 'with tab' 'post image.txt' FUNNYNAMES success failure failure
try_filename 'with backslash' 'post\image.txt' BSLASHPSPEC
try_filename 'with quote' '"postimage".txt' FUNNYNAMES success failure success
test_expect_success 'whitespace-damaged traditional patch' '
echo postimage >expected &&
reset_preimage &&
rm -f postimage.txt &&
git apply -v "$vector/damaged.diff" &&
test_cmp expected postimage.txt
'
test_done
/file-creation/
/trad-creation/
/trad-modification/
diff -pruN a/postimage.txt b/postimage.txt
--- a/postimage.txt 1969-12-31 18:00:00.000000000 -0600
+++ b/postimage.txt 2010-08-18 20:13:31.484002255 -0500
@@ -0,0 +1 @@
+postimage
diff -pruN a/post\image.txt b/post\image.txt
--- a/post\image.txt 1969-12-31 18:00:00.000000000 -0600
+++ b/post\image.txt 2010-08-18 20:13:31.692002255 -0500
@@ -0,0 +1 @@
+postimage
diff -pruN a/"postimage".txt b/"postimage".txt
--- a/"postimage".txt 1969-12-31 18:00:00.000000000 -0600
+++ b/"postimage".txt 2010-08-18 20:13:31.756002255 -0500
@@ -0,0 +1 @@
+postimage
diff -pruN a/post image.txt b/post image.txt
--- a/post image.txt 1969-12-31 18:00:00.000000000 -0600
+++ b/post image.txt 2010-08-18 20:13:31.556002255 -0500
@@ -0,0 +1 @@
+postimage
diff -pruN a/post image.txt b/post image.txt
--- a/post image.txt 1969-12-31 18:00:00.000000000 -0600
+++ b/post image.txt 2010-08-18 20:13:31.628002255 -0500
@@ -0,0 +1 @@
+postimage
diff -pruN a/postimage.txt b/postimage.txt
--- a/postimage.txt 1969-12-31 18:00:00.000000000 -0600
+++ b/postimage.txt 2010-08-18 20:13:31.484002255 -0500
@@ -0,0 +1 @@
+postimage
--- postimage.txt.orig 2010-08-18 20:13:31.432002255 -0500
+++ postimage.txt 2010-08-18 20:13:31.432002255 -0500
@@ -1 +1 @@
-preimage
+postimage
--- post\image.txt.orig 2010-08-18 20:13:31.680002255 -0500
+++ post\image.txt 2010-08-18 20:13:31.680002255 -0500
@@ -1 +1 @@
-preimage
+postimage
--- "postimage".txt.orig 2010-08-18 20:13:31.744002255 -0500
+++ "postimage".txt 2010-08-18 20:13:31.744002255 -0500
@@ -1 +1 @@
-preimage
+postimage
--- post image.txt.orig 2010-08-18 20:13:31.544002255 -0500
+++ post image.txt 2010-08-18 20:13:31.544002255 -0500
@@ -1 +1 @@
-preimage
+postimage
--- post image.txt.orig 2010-08-18 20:13:31.616002255 -0500
+++ post image.txt 2010-08-18 20:13:31.616002255 -0500
@@ -1 +1 @@
-preimage
+postimage
diff --git a/postimage.txt b/postimage.txt
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ b/postimage.txt
@@ -0,0 +1 @@
+postimage
diff --git "a/post\\image.txt" "b/post\\image.txt"
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ "b/post\\image.txt"
@@ -0,0 +1 @@
+postimage
diff --git "a/\"postimage\".txt" "b/\"postimage\".txt"
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ "b/\"postimage\".txt"
@@ -0,0 +1 @@
+postimage
diff --git a/post image.txt b/post image.txt
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ b/post image.txt
@@ -0,0 +1 @@
+postimage
diff --git "a/post\timage.txt" "b/post\timage.txt"
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ "b/post\timage.txt"
@@ -0,0 +1 @@
+postimage
#!/bin/sh
do_filename() {
desc=$1
postimage=$2
rm -fr file-creation &&
git init file-creation &&
(
cd file-creation &&
git commit --allow-empty -m init &&
echo postimage >"$postimage" &&
git add -N "$postimage" &&
git diff HEAD >"../git-$desc.diff"
) &&
rm -fr trad-modification &&
mkdir trad-modification &&
(
cd trad-modification &&
echo preimage >"$postimage.orig" &&
echo postimage >"$postimage" &&
! diff -u "$postimage.orig" "$postimage" >"../diff-$desc.diff"
) &&
rm -fr trad-creation &&
mkdir trad-creation &&
(
cd trad-creation &&
mkdir a b &&
echo postimage >"b/$postimage" &&
! diff -pruN a b >"../add-$desc.diff"
)
}
do_filename plain postimage.txt &&
do_filename 'with spaces' 'post image.txt' &&
do_filename 'with tab' 'post image.txt' &&
do_filename 'with backslash' 'post\image.txt' &&
do_filename 'with quote' '"postimage".txt' &&
expand add-plain.diff >damaged.diff ||
{
echo >&2 Failed. &&
exit 1
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment