blob: c8266f17f14af3c1af34661ccf9c039d04cfbe31 [file] [log] [blame]
Clément Poulain34bb92e2010-06-09 19:02:09 +02001#!/bin/sh
2
3test_description='git cat-file textconv support'
Ævar Arnfjörð Bjarmason27472b52022-07-01 12:42:59 +02004
5TEST_PASSES_SANITIZE_LEAK=true
Clément Poulain34bb92e2010-06-09 19:02:09 +02006. ./test-lib.sh
7
8cat >helper <<'EOF'
9#!/bin/sh
Kirill Smelkov6517cf72010-09-29 15:35:22 +040010grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
11sed 's/^bin: /converted: /' "$1"
Clément Poulain34bb92e2010-06-09 19:02:09 +020012EOF
13chmod +x helper
14
15test_expect_success 'setup ' '
Kirill Smelkov6517cf72010-09-29 15:35:22 +040016 echo "bin: test" >one.bin &&
Johannes Sixt889c6f02013-06-07 22:53:28 +020017 test_ln_s_add one.bin symlink.bin &&
Clément Poulain34bb92e2010-06-09 19:02:09 +020018 git add . &&
19 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
Kirill Smelkov6517cf72010-09-29 15:35:22 +040020 echo "bin: test version 2" >one.bin &&
Clément Poulain34bb92e2010-06-09 19:02:09 +020021 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
22'
23
Ævar Arnfjörð Bjarmason68c69f92021-12-28 14:28:42 +010024test_expect_success 'usage: <bad rev>' '
25 cat >expect <<-\EOF &&
26 fatal: Not a valid object name HEAD2
27 EOF
28 test_must_fail git cat-file --textconv HEAD2 2>actual &&
29 test_cmp expect actual
30'
31
32test_expect_success 'usage: <bad rev>:<bad path>' '
33 cat >expect <<-\EOF &&
Ævar Arnfjörð Bjarmason245b9482021-12-28 14:28:50 +010034 fatal: invalid object name '\''HEAD2'\''.
Ævar Arnfjörð Bjarmason68c69f92021-12-28 14:28:42 +010035 EOF
36 test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual &&
37 test_cmp expect actual
38'
39
40test_expect_success 'usage: <rev>:<bad path>' '
41 cat >expect <<-\EOF &&
Ævar Arnfjörð Bjarmason245b9482021-12-28 14:28:50 +010042 fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\''
Ævar Arnfjörð Bjarmason68c69f92021-12-28 14:28:42 +010043 EOF
44 test_must_fail git cat-file --textconv HEAD:two.bin 2>actual &&
45 test_cmp expect actual
46'
47
48
49test_expect_success 'usage: <rev> with no <path>' '
50 cat >expect <<-\EOF &&
Ævar Arnfjörð Bjarmason245b9482021-12-28 14:28:50 +010051 fatal: <object>:<path> required, only <object> '\''HEAD'\'' given
Ævar Arnfjörð Bjarmason68c69f92021-12-28 14:28:42 +010052 EOF
53 test_must_fail git cat-file --textconv HEAD 2>actual &&
54 test_cmp expect actual
55'
56
57
58test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' '
59 cat >expect <<-\EOF &&
Ævar Arnfjörð Bjarmason245b9482021-12-28 14:28:50 +010060 fatal: invalid object name '\''HEAD2'\''.
Ævar Arnfjörð Bjarmason68c69f92021-12-28 14:28:42 +010061 EOF
62 test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
63 test_cmp expect actual
64'
65
Clément Poulain34bb92e2010-06-09 19:02:09 +020066cat >expected <<EOF
Michael J Gruber3ac21612013-05-10 17:10:13 +020067bin: test version 2
Clément Poulain34bb92e2010-06-09 19:02:09 +020068EOF
69
70test_expect_success 'no filter specified' '
Michael J Gruber3ac21612013-05-10 17:10:13 +020071 git cat-file --textconv :one.bin >result &&
Clément Poulain34bb92e2010-06-09 19:02:09 +020072 test_cmp expected result
73'
74
75test_expect_success 'setup textconv filters' '
76 echo "*.bin diff=test" >.gitattributes &&
77 git config diff.test.textconv ./helper &&
78 git config diff.test.cachetextconv false
79'
80
Clément Poulain34bb92e2010-06-09 19:02:09 +020081test_expect_success 'cat-file without --textconv' '
82 git cat-file blob :one.bin >result &&
83 test_cmp expected result
84'
85
86cat >expected <<EOF
Kirill Smelkov6517cf72010-09-29 15:35:22 +040087bin: test
Clément Poulain34bb92e2010-06-09 19:02:09 +020088EOF
89
90test_expect_success 'cat-file without --textconv on previous commit' '
91 git cat-file -p HEAD^:one.bin >result &&
92 test_cmp expected result
93'
94
95cat >expected <<EOF
96converted: test version 2
97EOF
98
99test_expect_success 'cat-file --textconv on last commit' '
100 git cat-file --textconv :one.bin >result &&
101 test_cmp expected result
102'
103
104cat >expected <<EOF
105converted: test
106EOF
107
108test_expect_success 'cat-file --textconv on previous commit' '
109 git cat-file --textconv HEAD^:one.bin >result &&
110 test_cmp expected result
111'
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400112
Johannes Sixt889c6f02013-06-07 22:53:28 +0200113test_expect_success 'cat-file without --textconv (symlink)' '
Michael J Gruber3ac21612013-05-10 17:10:13 +0200114 printf "%s" "one.bin" >expected &&
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400115 git cat-file blob :symlink.bin >result &&
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400116 test_cmp expected result
117'
118
119
Johannes Sixt889c6f02013-06-07 22:53:28 +0200120test_expect_success 'cat-file --textconv on index (symlink)' '
Michael J Gruber3ac21612013-05-10 17:10:13 +0200121 git cat-file --textconv :symlink.bin >result &&
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400122 test_cmp expected result
123'
124
Johannes Sixt889c6f02013-06-07 22:53:28 +0200125test_expect_success 'cat-file --textconv on HEAD (symlink)' '
Michael J Gruber3ac21612013-05-10 17:10:13 +0200126 git cat-file --textconv HEAD:symlink.bin >result &&
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400127 test_cmp expected result
128'
129
Clément Poulain34bb92e2010-06-09 19:02:09 +0200130test_done