t / t4135-apply-weird-filenames.shon commit Third batch for 2.7 (b27dacc)
   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        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
  28try_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
  61try_filename 'plain'            'postimage.txt'
  62try_filename 'with spaces'      'post image.txt'
  63try_filename 'with tab'         'post   image.txt' FUNNYNAMES
  64try_filename 'with backslash'   'post\image.txt' BSLASHPSPEC
  65try_filename 'with quote'       '"postimage".txt' FUNNYNAMES success failure success
  66
  67test_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
  75test_expect_success 'traditional patch with colon in timezone' '
  76        echo postimage >expected &&
  77        reset_preimage &&
  78        rm -f "post image.txt" &&
  79        git apply "$vector/funny-tz.diff" &&
  80        test_cmp expected "post image.txt"
  81'
  82
  83test_expect_success 'traditional, whitespace-damaged, colon in timezone' '
  84        echo postimage >expected &&
  85        reset_preimage &&
  86        rm -f "post image.txt" &&
  87        git apply "$vector/damaged-tz.diff" &&
  88        test_cmp expected "post image.txt"
  89'
  90
  91test_done