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