Merge branch 'nd/format-patch-stat-width'
[git] / t / t8007-cat-file-textconv.sh
1 #!/bin/sh
2
3 test_description='git cat-file textconv support'
4 . ./test-lib.sh
5
6 cat >helper <<'EOF'
7 #!/bin/sh
8 grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
9 sed 's/^bin: /converted: /' "$1"
10 EOF
11 chmod +x helper
12
13 test_expect_success 'setup ' '
14         echo "bin: test" >one.bin &&
15         test_ln_s_add one.bin symlink.bin &&
16         git add . &&
17         GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
18         echo "bin: test version 2" >one.bin &&
19         GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
20 '
21
22 cat >expected <<EOF
23 bin: test version 2
24 EOF
25
26 test_expect_success 'no filter specified' '
27         git cat-file --textconv :one.bin >result &&
28         test_cmp expected result
29 '
30
31 test_expect_success 'setup textconv filters' '
32         echo "*.bin diff=test" >.gitattributes &&
33         git config diff.test.textconv ./helper &&
34         git config diff.test.cachetextconv false
35 '
36
37 test_expect_success 'cat-file without --textconv' '
38         git cat-file blob :one.bin >result &&
39         test_cmp expected result
40 '
41
42 cat >expected <<EOF
43 bin: test
44 EOF
45
46 test_expect_success 'cat-file without --textconv on previous commit' '
47         git cat-file -p HEAD^:one.bin >result &&
48         test_cmp expected result
49 '
50
51 cat >expected <<EOF
52 converted: test version 2
53 EOF
54
55 test_expect_success 'cat-file --textconv on last commit' '
56         git cat-file --textconv :one.bin >result &&
57         test_cmp expected result
58 '
59
60 cat >expected <<EOF
61 converted: test
62 EOF
63
64 test_expect_success 'cat-file --textconv on previous commit' '
65         git cat-file --textconv HEAD^:one.bin >result &&
66         test_cmp expected result
67 '
68
69 test_expect_success 'cat-file without --textconv (symlink)' '
70         printf "%s" "one.bin" >expected &&
71         git cat-file blob :symlink.bin >result &&
72         test_cmp expected result
73 '
74
75
76 test_expect_success 'cat-file --textconv on index (symlink)' '
77         git cat-file --textconv :symlink.bin >result &&
78         test_cmp expected result
79 '
80
81 test_expect_success 'cat-file --textconv on HEAD (symlink)' '
82         git cat-file --textconv HEAD:symlink.bin >result &&
83         test_cmp expected result
84 '
85
86 test_done