summaryrefslogtreecommitdiffstats
path: root/t/t8010-cat-file-filters.sh
blob: ca04242ca016368a5644ef7d04c8b3dab0569260 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh

test_description='git cat-file filters support'

TEST_PASSES_SANITIZE_LEAK=true
. ./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"
'

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=<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=<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=<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_must_be_empty actual &&
	grep "path.*needs.*filters" err
'

test_expect_success '--textconv/--filters complain without path' '
	test_must_fail git cat-file --textconv HEAD &&
	test_must_fail git cat-file --filters HEAD
'

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