t / t4135-apply-weird-filenames.shon commit t1700-split-index: date back files to avoid racy situations (c6e5607)
   1#!/bin/sh
   2
   3test_description='git apply with weird postimage filenames'
   4
   5. ./test-lib.sh
   6
   7test_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
  21try_filename() {
  22        desc=$1
  23        postimage=$2
  24        prereq=${3:-}
  25        exp1=${4:-success}
  26        exp2=${5:-success}
  27        exp3=${6:-success}
  28
  29        test_expect_$exp1 $prereq "$desc, git-style file creation patch" "
  30                echo postimage >expected &&
  31                reset_preimage &&
  32                rm -f '$postimage' &&
  33                git apply -v \"\$vector\"/'git-$desc.diff' &&
  34                test_cmp expected '$postimage'
  35        "
  36
  37        test_expect_$exp2 $prereq "$desc, traditional patch" "
  38                echo postimage >expected &&
  39                reset_preimage &&
  40                echo preimage >'$postimage' &&
  41                git apply -v \"\$vector\"/'diff-$desc.diff' &&
  42                test_cmp expected '$postimage'
  43        "
  44
  45        test_expect_$exp3 $prereq "$desc, traditional file creation patch" "
  46                echo postimage >expected &&
  47                reset_preimage &&
  48                rm -f '$postimage' &&
  49                git apply -v \"\$vector\"/'add-$desc.diff' &&
  50                test_cmp expected '$postimage'
  51        "
  52}
  53
  54try_filename 'plain'            'postimage.txt'
  55try_filename 'with spaces'      'post image.txt'
  56try_filename 'with tab'         'post   image.txt' FUNNYNAMES
  57try_filename 'with backslash'   'post\image.txt' BSLASHPSPEC
  58try_filename 'with quote'       '"postimage".txt' FUNNYNAMES success failure success
  59
  60test_expect_success 'whitespace-damaged traditional patch' '
  61        echo postimage >expected &&
  62        reset_preimage &&
  63        rm -f postimage.txt &&
  64        git apply -v "$vector/damaged.diff" &&
  65        test_cmp expected postimage.txt
  66'
  67
  68test_expect_success 'traditional patch with colon in timezone' '
  69        echo postimage >expected &&
  70        reset_preimage &&
  71        rm -f "post image.txt" &&
  72        git apply "$vector/funny-tz.diff" &&
  73        test_cmp expected "post image.txt"
  74'
  75
  76test_expect_success 'traditional, whitespace-damaged, colon in timezone' '
  77        echo postimage >expected &&
  78        reset_preimage &&
  79        rm -f "post image.txt" &&
  80        git apply "$vector/damaged-tz.diff" &&
  81        test_cmp expected "post image.txt"
  82'
  83
  84cat >diff-from-svn <<\EOF
  85Index: Makefile
  86===================================================================
  87diff --git a/branches/Makefile
  88deleted file mode 100644
  89--- a/branches/Makefile (revision 13)
  90+++ /dev/null   (nonexistent)
  91@@ +1 0,0 @@
  92-
  93EOF
  94
  95test_expect_success 'apply handles a diff generated by Subversion' '
  96        >Makefile &&
  97        git apply -p2 diff-from-svn &&
  98        test_path_is_missing Makefile
  99'
 100
 101test_done