#!/bin/sh global test_description := ''git apply with weird postimage filenames'' source ./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 test_have_prereq !MINGW && touch -- "tab embedded.txt" '''''"quoteembedded".txt''''' then test_set_prereq FUNNYNAMES fi ' proc try_filename { global desc := $1 global postimage := $2 global prereq := $(3:-) global exp1 := $(4:-success) global exp2 := $(5:-success) global 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' try_filename 'with tab' 'post image.txt' FUNNYNAMES 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_expect_success 'traditional patch with colon in timezone' ' echo postimage >expected && reset_preimage && rm -f "post image.txt" && git apply "$vector/funny-tz.diff" && test_cmp expected "post image.txt" ' test_expect_success 'traditional, whitespace-damaged, colon in timezone' ' echo postimage >expected && reset_preimage && rm -f "post image.txt" && git apply "$vector/damaged-tz.diff" && test_cmp expected "post image.txt" ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git apply with weird postimage filenames">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tvector=$TEST_DIRECTORY/t4135 &&\n"> <"\n"> <"\ttest_tick &&\n"> <"\tgit commit --allow-empty -m preimage &&\n"> <"\tgit tag preimage &&\n"> <"\n"> <"\treset_preimage() {\n"> <"\t\tgit checkout -f preimage^0 &&\n"> <"\t\tgit read-tree -u --reset HEAD &&\n"> <"\t\tgit update-index --refresh\n"> <"\t} &&\n"> <"\n"> <"\ttest_when_finished \"rm -f \\\"tab\tembedded.txt\\\"\" &&\n"> <"\ttest_when_finished \"rm -f "> ) (EscapedLiteralPart token:) (SQ <"\\\"quoteembedded\\\".txt">) (EscapedLiteralPart token:) (SQ <"\" &&\n"> <"\tif test_have_prereq !MINGW &&\n"> <"\t\ttouch -- \"tab\tembedded.txt\" ">) (EscapedLiteralPart token:) (SQ <"\"quoteembedded\".txt">) (EscapedLiteralPart token:) (SQ <"\n"> <"\tthen\n"> <"\t\ttest_set_prereq FUNNYNAMES\n"> <"\tfi\n">) } ) (FuncDef name: try_filename body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:desc) op: Equal rhs: {($ VSub_Number "$1")} spids: [68] ) ] spids: [68] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:postimage) op: Equal rhs: {($ VSub_Number "$2")} spids: [72] ) ] spids: [72] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:prereq) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{}) spids: [77 80] ) } spids: [76] ) ] spids: [76] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exp1) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(success)}) spids: [84 88] ) } spids: [83] ) ] spids: [83] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exp2) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(success)}) spids: [92 96] ) } spids: [91] ) ] spids: [91] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exp3) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(success)}) spids: [100 104] ) } spids: [99] ) ] spids: [99] ) (C {(test_expect_) ($ VSub_Name "$exp1")} {($ VSub_Name "$prereq")} {(DQ ($ VSub_Name "$desc") (", git-style file creation patch"))} { (DQ ("\n") ("\t\techo postimage >expected &&\n") ("\t\treset_preimage &&\n") ("\t\trm -f '") ($ VSub_Name "$postimage") ("' &&\n") ("\t\tgit apply -v ") (EscapedLiteralPart token:) (EscapedLiteralPart token:) (vector) (EscapedLiteralPart token:) ("/'git-") ($ VSub_Name "$desc") (".diff' &&\n") ("\t\ttest_cmp expected '") ($ VSub_Name "$postimage") ("'\n") ("\t") ) } ) (C {(test_expect_) ($ VSub_Name "$exp2")} {($ VSub_Name "$prereq")} {(DQ ($ VSub_Name "$desc") (", traditional patch"))} { (DQ ("\n") ("\t\techo postimage >expected &&\n") ("\t\treset_preimage &&\n") ("\t\techo preimage >'") ($ VSub_Name "$postimage") ("' &&\n") ("\t\tgit apply -v ") (EscapedLiteralPart token:) (EscapedLiteralPart token:) (vector) (EscapedLiteralPart token:) ("/'diff-") ($ VSub_Name "$desc") (".diff' &&\n") ("\t\ttest_cmp expected '") ($ VSub_Name "$postimage") ("'\n") ("\t") ) } ) (C {(test_expect_) ($ VSub_Name "$exp3")} {($ VSub_Name "$prereq")} {(DQ ($ VSub_Name "$desc") (", traditional file creation patch"))} { (DQ ("\n") ("\t\techo postimage >expected &&\n") ("\t\treset_preimage &&\n") ("\t\trm -f '") ($ VSub_Name "$postimage") ("' &&\n") ("\t\tgit apply -v ") (EscapedLiteralPart token:) (EscapedLiteralPart token:) (vector) (EscapedLiteralPart token:) ("/'add-") ($ VSub_Name "$desc") (".diff' &&\n") ("\t\ttest_cmp expected '") ($ VSub_Name "$postimage") ("'\n") ("\t") ) } ) ] spids: [65] ) spids: [61 64] ) (C {(try_filename)} {(SQ )} {(SQ )}) (C {(try_filename)} {(SQ <"with spaces">)} {(SQ <"post image.txt">)}) (C {(try_filename)} {(SQ <"with tab">)} {(SQ <"post\timage.txt">)} {(FUNNYNAMES)}) (C {(try_filename)} {(SQ <"with backslash">)} {(SQ <"post\\image.txt">)} {(BSLASHPSPEC)}) (C {(try_filename)} {(SQ <"with quote">)} {(SQ <"\"postimage\".txt">)} {(FUNNYNAMES)} {(success)} {(failure)} {(success)} ) (C {(test_expect_success)} {(SQ <"whitespace-damaged traditional patch">)} { (SQ <"\n"> <"\techo postimage >expected &&\n"> <"\treset_preimage &&\n"> <"\trm -f postimage.txt &&\n"> <"\tgit apply -v \"$vector/damaged.diff\" &&\n"> <"\ttest_cmp expected postimage.txt\n"> ) } ) (C {(test_expect_success)} {(SQ <"traditional patch with colon in timezone">)} { (SQ <"\n"> <"\techo postimage >expected &&\n"> <"\treset_preimage &&\n"> <"\trm -f \"post image.txt\" &&\n"> <"\tgit apply \"$vector/funny-tz.diff\" &&\n"> <"\ttest_cmp expected \"post image.txt\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"traditional, whitespace-damaged, colon in timezone">)} { (SQ <"\n"> <"\techo postimage >expected &&\n"> <"\treset_preimage &&\n"> <"\trm -f \"post image.txt\" &&\n"> <"\tgit apply \"$vector/damaged-tz.diff\" &&\n"> <"\ttest_cmp expected \"post image.txt\"\n"> ) } ) (C {(test_done)}) ] )