Merge branch 'tb/commit-graph-genv2-upgrade-fix' into maint
[git/debian.git] / t / t8007-cat-file-textconv.sh
blobb067983ba1c6adf152131c96a67fc7a709e6666b
1 #!/bin/sh
3 test_description='git cat-file textconv support'
4 . ./test-lib.sh
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
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"
22 test_expect_success 'usage: <bad rev>' '
23 cat >expect <<-\EOF &&
24 fatal: Not a valid object name HEAD2
25 EOF
26 test_must_fail git cat-file --textconv HEAD2 2>actual &&
27 test_cmp expect actual
30 test_expect_success 'usage: <bad rev>:<bad path>' '
31 cat >expect <<-\EOF &&
32 fatal: invalid object name '\''HEAD2'\''.
33 EOF
34 test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual &&
35 test_cmp expect actual
38 test_expect_success 'usage: <rev>:<bad path>' '
39 cat >expect <<-\EOF &&
40 fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\''
41 EOF
42 test_must_fail git cat-file --textconv HEAD:two.bin 2>actual &&
43 test_cmp expect actual
47 test_expect_success 'usage: <rev> with no <path>' '
48 cat >expect <<-\EOF &&
49 fatal: <object>:<path> required, only <object> '\''HEAD'\'' given
50 EOF
51 test_must_fail git cat-file --textconv HEAD 2>actual &&
52 test_cmp expect actual
56 test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' '
57 cat >expect <<-\EOF &&
58 fatal: invalid object name '\''HEAD2'\''.
59 EOF
60 test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
61 test_cmp expect actual
64 cat >expected <<EOF
65 bin: test version 2
66 EOF
68 test_expect_success 'no filter specified' '
69 git cat-file --textconv :one.bin >result &&
70 test_cmp expected result
73 test_expect_success 'setup textconv filters' '
74 echo "*.bin diff=test" >.gitattributes &&
75 git config diff.test.textconv ./helper &&
76 git config diff.test.cachetextconv false
79 test_expect_success 'cat-file without --textconv' '
80 git cat-file blob :one.bin >result &&
81 test_cmp expected result
84 cat >expected <<EOF
85 bin: test
86 EOF
88 test_expect_success 'cat-file without --textconv on previous commit' '
89 git cat-file -p HEAD^:one.bin >result &&
90 test_cmp expected result
93 cat >expected <<EOF
94 converted: test version 2
95 EOF
97 test_expect_success 'cat-file --textconv on last commit' '
98 git cat-file --textconv :one.bin >result &&
99 test_cmp expected result
102 cat >expected <<EOF
103 converted: test
106 test_expect_success 'cat-file --textconv on previous commit' '
107 git cat-file --textconv HEAD^:one.bin >result &&
108 test_cmp expected result
111 test_expect_success 'cat-file without --textconv (symlink)' '
112 printf "%s" "one.bin" >expected &&
113 git cat-file blob :symlink.bin >result &&
114 test_cmp expected result
118 test_expect_success 'cat-file --textconv on index (symlink)' '
119 git cat-file --textconv :symlink.bin >result &&
120 test_cmp expected result
123 test_expect_success 'cat-file --textconv on HEAD (symlink)' '
124 git cat-file --textconv HEAD:symlink.bin >result &&
125 test_cmp expected result
128 test_done