#!/bin/sh global test_description := ''git cat-file filters support'' source ./test-lib.sh test_expect_success 'setup ' ' echo "*.txt eol=crlf diff=txt" >.gitattributes && echo "hello" | append_cr >world.txt && git add .gitattributes world.txt && test_tick && git commit -m "Initial commit" ' proc has_cr { tr '\015' Q <$1 | grep Q >/dev/null } test_expect_success 'no filters with `git show`' ' git show HEAD:world.txt >actual && ! has_cr actual ' test_expect_success 'no filters with cat-file' ' git cat-file blob HEAD:world.txt >actual && ! has_cr actual ' test_expect_success 'cat-file --filters converts to worktree version' ' git cat-file --filters HEAD:world.txt >actual && has_cr actual ' test_expect_success 'cat-file --filters --path= works' ' sha1=$(git rev-parse -q --verify HEAD:world.txt) && git cat-file --filters --path=world.txt $sha1 >actual && has_cr actual ' test_expect_success 'cat-file --textconv --path= works' ' sha1=$(git rev-parse -q --verify HEAD:world.txt) && test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" && git cat-file --textconv --path=hello.txt $sha1 >rot13 && test uryyb = "$(cat rot13 | remove_cr)" ' test_expect_success '--path= complains without --textconv/--filters' ' sha1=$(git rev-parse -q --verify HEAD:world.txt) && test_must_fail git cat-file --path=hello.txt blob $sha1 >actual 2>err && test ! -s actual && grep "path.*needs.*filters" err ' test_expect_success 'cat-file --textconv --batch works' ' sha1=$(git rev-parse -q --verify HEAD:world.txt) && test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" && printf "%s hello.txt\n%s hello\n" $sha1 $sha1 | git cat-file --textconv --batch >actual && printf "%s blob 6\nuryyb\r\n\n%s blob 6\nhello\n\n" \ $sha1 $sha1 >expect && test_cmp expect actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git cat-file filters support">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"setup ">)} { (SQ <"\n"> <"\techo \"*.txt eol=crlf diff=txt\" >.gitattributes &&\n"> <"\techo \"hello\" | append_cr >world.txt &&\n"> <"\tgit add .gitattributes world.txt &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m \"Initial commit\"\n"> ) } ) (FuncDef name: has_cr body: (BraceGroup children: [ (Pipeline children: [ (SimpleCommand words: [{(tr)} {(SQ <"\\015">)} {(Q)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [46] ) ] ) (SimpleCommand words: [{(grep)} {(Q)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[57])] ) ] negated: False ) ] spids: [35] ) spids: [30 34] ) (C {(test_expect_success)} {(SQ <"no filters with `git show`">)} {(SQ <"\n"> <"\tgit show HEAD:world.txt >actual &&\n"> <"\t! has_cr actual\n"> <"\n">)} ) (C {(test_expect_success)} {(SQ <"no filters with cat-file">)} {(SQ <"\n"> <"\tgit cat-file blob HEAD:world.txt >actual &&\n"> <"\t! has_cr actual\n">)} ) (C {(test_expect_success)} {(SQ <"cat-file --filters converts to worktree version">)} {(SQ <"\n"> <"\tgit cat-file --filters HEAD:world.txt >actual &&\n"> <"\thas_cr actual\n">)} ) (C {(test_expect_success)} {(SQ <"cat-file --filters --path= works">)} { (SQ <"\n"> <"\tsha1=$(git rev-parse -q --verify HEAD:world.txt) &&\n"> <"\tgit cat-file --filters --path=world.txt $sha1 >actual &&\n"> <"\thas_cr actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"cat-file --textconv --path= works">)} { (SQ <"\n"> <"\tsha1=$(git rev-parse -q --verify HEAD:world.txt) &&\n"> <"\ttest_config diff.txt.textconv \"tr A-Za-z N-ZA-Mn-za-m <\" &&\n"> <"\tgit cat-file --textconv --path=hello.txt $sha1 >rot13 &&\n"> <"\ttest uryyb = \"$(cat rot13 | remove_cr)\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"--path= complains without --textconv/--filters">)} { (SQ <"\n"> <"\tsha1=$(git rev-parse -q --verify HEAD:world.txt) &&\n"> <"\ttest_must_fail git cat-file --path=hello.txt blob $sha1 >actual 2>err &&\n"> <"\ttest ! -s actual &&\n"> <"\tgrep \"path.*needs.*filters\" err\n"> ) } ) (C {(test_expect_success)} {(SQ <"cat-file --textconv --batch works">)} { (SQ <"\n"> <"\tsha1=$(git rev-parse -q --verify HEAD:world.txt) &&\n"> <"\ttest_config diff.txt.textconv \"tr A-Za-z N-ZA-Mn-za-m <\" &&\n"> <"\tprintf \"%s hello.txt\\n%s hello\\n\" $sha1 $sha1 |\n"> <"\tgit cat-file --textconv --batch >actual &&\n"> <"\tprintf \"%s blob 6\\nuryyb\\r\\n\\n%s blob 6\\nhello\\n\\n\" \\\n"> <"\t\t$sha1 $sha1 >expect &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_done)}) ] )