Browse Source

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>
maint
Jonathan Nieder 15 years ago committed by Junio C Hamano
parent
commit
c51c0da222
  1. 75
      t/t4135-apply-weird-filenames.sh
  2. 3
      t/t4135/.gitignore
  3. 5
      t/t4135/add-plain.diff
  4. 5
      t/t4135/add-with backslash.diff
  5. 5
      t/t4135/add-with quote.diff
  6. 5
      t/t4135/add-with spaces.diff
  7. 5
      t/t4135/add-with tab.diff
  8. 5
      t/t4135/damaged.diff
  9. 5
      t/t4135/diff-plain.diff
  10. 5
      t/t4135/diff-with backslash.diff
  11. 5
      t/t4135/diff-with quote.diff
  12. 5
      t/t4135/diff-with spaces.diff
  13. 5
      t/t4135/diff-with tab.diff
  14. 7
      t/t4135/git-plain.diff
  15. 7
      t/t4135/git-with backslash.diff
  16. 7
      t/t4135/git-with quote.diff
  17. 7
      t/t4135/git-with spaces.diff
  18. 7
      t/t4135/git-with tab.diff
  19. 45
      t/t4135/make-patches

75
t/t4135-apply-weird-filenames.sh

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
#!/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

3
t/t4135/.gitignore vendored

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
/file-creation/
/trad-creation/
/trad-modification/

5
t/t4135/add-plain.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
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

5
t/t4135/add-with backslash.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
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

5
t/t4135/add-with quote.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
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

5
t/t4135/add-with spaces.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
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

5
t/t4135/add-with tab.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
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

5
t/t4135/damaged.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
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

5
t/t4135/diff-plain.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
--- 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

5
t/t4135/diff-with backslash.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
--- 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

5
t/t4135/diff-with quote.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
--- "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

5
t/t4135/diff-with spaces.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
--- 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

5
t/t4135/diff-with tab.diff

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
--- 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

7
t/t4135/git-plain.diff

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
diff --git a/postimage.txt b/postimage.txt
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ b/postimage.txt
@@ -0,0 +1 @@
+postimage

7
t/t4135/git-with backslash.diff

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
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

7
t/t4135/git-with quote.diff

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
diff --git "a/\"postimage\".txt" "b/\"postimage\".txt"
new file mode 100644
index 0000000..eff0c54
--- /dev/null
+++ "b/\"postimage\".txt"
@@ -0,0 +1 @@
+postimage

7
t/t4135/git-with spaces.diff

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
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

7
t/t4135/git-with tab.diff

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
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

45
t/t4135/make-patches

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
#!/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
}
Loading…
Cancel
Save