#!/bin/sh global test_description := ''check that read-tree rejects confusing paths'' source ./test-lib.sh test_expect_success 'create base tree' ' echo content >file && git add file && git commit -m base && blob=$(git rev-parse HEAD:file) && tree=$(git rev-parse HEAD^{tree}) ' test_expect_success 'enable core.protectHFS for rejection tests' ' git config core.protectHFS true ' test_expect_success 'enable core.protectNTFS for rejection tests' ' git config core.protectNTFS true ' while read path pretty { : $(pretty:=$path) matchstr $path { *SPACE { global path := ""$(path%SPACE) "" } } test_expect_success "reject $pretty at end of path" ' printf "100644 blob %s\t%s" "$blob" "$path" >tree && bogus=$(git mktree tree && bogus=$(git mktree tree && ok=$(git mktree )} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"create base tree">)} { (SQ <"\n"> <"\techo content >file &&\n"> <"\tgit add file &&\n"> <"\tgit commit -m base &&\n"> <"\tblob=$(git rev-parse HEAD:file) &&\n"> <"\ttree=$(git rev-parse HEAD^{tree})\n"> ) } ) (C {(test_expect_success)} {(SQ <"enable core.protectHFS for rejection tests">)} {(SQ <"\n"> <"\tgit config core.protectHFS true\n">)} ) (C {(test_expect_success)} {(SQ <"enable core.protectNTFS for rejection tests">)} {(SQ <"\n"> <"\tgit config core.protectNTFS true\n">)} ) (While cond: [(Sentence child:(C {(read)} {(path)} {(pretty)}) terminator:)] body: (DoGroup children: [ (C {(Lit_Other ":")} { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonEquals arg_word:{($ VSub_Name "$path")}) spids: [68 72] ) } ) (Case to_match: {(DQ ($ VSub_Name "$path"))} arms: [ (case_arm pat_list: [{(Lit_Other "*") (SPACE)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:path) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Percent arg_word:{(SPACE)}) spids: [91 95] ) (" ") ) } spids: [89] ) ] spids: [89] ) ] spids: [84 86 100 -1] ) ] spids: [75 81 103] ) (C {(test_expect_success)} {(DQ ("reject ") ($ VSub_Name "$pretty") (" at end of path"))} { (SQ <"\n"> <"\t\tprintf \"100644 blob %s\\t%s\" \"$blob\" \"$path\" >tree &&\n"> <"\t\tbogus=$(git mktree <"\t\ttest_must_fail git read-tree $bogus\n"> <"\t"> ) } ) (C {(test_expect_success)} {(DQ ("reject ") ($ VSub_Name "$pretty") (" as subtree"))} { (SQ <"\n"> <"\t\tprintf \"040000 tree %s\\t%s\" \"$tree\" \"$path\" >tree &&\n"> <"\t\tbogus=$(git mktree <"\t\ttest_must_fail git read-tree $bogus\n"> <"\t"> ) } ) ] spids: [63 140] ) redirects: [ (HereDoc op_id: Redir_DLessDash fd: -1 body: { (DQ (".\n") ("..\n") (".git\n") (".GIT\n") (${ VSub_Name u200c) (".Git {u200c}.Git\n") (.gI) (${ VSub_Name u200c) ("T .gI{u200c}T\n") (.GiT) (${ VSub_Name u200c) (" .GiT{u200c}\n") ("git~1\n") (".git.SPACE .git.{space}\n") (.) (EscapedLiteralPart token:) (EscapedLiteralPart token:) (.GIT) (EscapedLiteralPart token:) (EscapedLiteralPart token:) ("foobar backslashes\n") (.git) (EscapedLiteralPart token:) (EscapedLiteralPart token:) ("foobar backslashes2\n") ) } do_expansion: True here_end: EOF was_filled: True spids: [142] ) ] ) (C {(test_expect_success)} {(SQ <"utf-8 paths allowed with core.protectHFS off">)} { (SQ <"\n"> <"\ttest_when_finished \"git read-tree HEAD\" &&\n"> <"\ttest_config core.protectHFS false &&\n"> <"\tprintf \"100644 blob %s\\t%s\" \"$blob\" \".gi${u200c}t\" >tree &&\n"> <"\tok=$(git mktree <"\tgit read-tree $ok\n"> ) } ) (C {(test_done)}) ] )