git-prompt: use here-doc instead of here-string
[git/gitster.git] / t / t8010-cat-file-filters.sh
blobeb64b766bdfa24ee6fa3e8578188844b10e1ef66
1 #!/bin/sh
3 test_description='git cat-file filters support'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup ' '
9 echo "*.txt eol=crlf diff=txt" >.gitattributes &&
10 echo "hello" | append_cr >world.txt &&
11 git add .gitattributes world.txt &&
12 test_tick &&
13 git commit -m "Initial commit"
16 has_cr () {
17 tr '\015' Q <"$1" | grep Q >/dev/null
20 test_expect_success 'no filters with `git show`' '
21 git show HEAD:world.txt >actual &&
22 ! has_cr actual
26 test_expect_success 'no filters with cat-file' '
27 git cat-file blob HEAD:world.txt >actual &&
28 ! has_cr actual
31 test_expect_success 'cat-file --filters converts to worktree version' '
32 git cat-file --filters HEAD:world.txt >actual &&
33 has_cr actual
36 test_expect_success 'cat-file --filters --path=<path> works' '
37 sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
38 git cat-file --filters --path=world.txt $sha1 >actual &&
39 has_cr actual
42 test_expect_success 'cat-file --textconv --path=<path> works' '
43 sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
44 test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&
45 git cat-file --textconv --path=hello.txt $sha1 >rot13 &&
46 test uryyb = "$(remove_cr <rot13)"
49 test_expect_success '--path=<path> complains without --textconv/--filters' '
50 sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
51 test_must_fail git cat-file --path=hello.txt blob $sha1 >actual 2>err &&
52 test_must_be_empty actual &&
53 grep "path.*needs.*filters" err
56 test_expect_success '--textconv/--filters complain without path' '
57 test_must_fail git cat-file --textconv HEAD &&
58 test_must_fail git cat-file --filters HEAD
61 test_expect_success 'cat-file --textconv --batch works' '
62 sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
63 test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&
64 printf "%s hello.txt\n%s hello\n" $sha1 $sha1 |
65 git cat-file --textconv --batch >actual &&
66 printf "%s blob 6\nuryyb\r\n\n%s blob 6\nhello\n\n" \
67 $sha1 $sha1 >expect &&
68 test_cmp expect actual
71 test_done