]> git.ipfire.org Git - thirdparty/git.git/blame - t/t8007-cat-file-textconv.sh
The twentieth batch
[thirdparty/git.git] / t / t8007-cat-file-textconv.sh
CommitLineData
34bb92ec
CP
1#!/bin/sh
2
3test_description='git cat-file textconv support'
27472b51
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
34bb92ec
CP
6. ./test-lib.sh
7
8cat >helper <<'EOF'
9#!/bin/sh
6517cf7d
KS
10grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
11sed 's/^bin: /converted: /' "$1"
34bb92ec
CP
12EOF
13chmod +x helper
14
15test_expect_success 'setup ' '
6517cf7d 16 echo "bin: test" >one.bin &&
889c6f0e 17 test_ln_s_add one.bin symlink.bin &&
34bb92ec
CP
18 git add . &&
19 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
6517cf7d 20 echo "bin: test version 2" >one.bin &&
34bb92ec
CP
21 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
22'
23
68c69f90
ÆAB
24test_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 &&
245b9488 34 fatal: invalid object name '\''HEAD2'\''.
68c69f90
ÆAB
35 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 &&
245b9488 42 fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\''
68c69f90
ÆAB
43 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 &&
245b9488 51 fatal: <object>:<path> required, only <object> '\''HEAD'\'' given
68c69f90
ÆAB
52 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 &&
245b9488 60 fatal: invalid object name '\''HEAD2'\''.
68c69f90
ÆAB
61 EOF
62 test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
63 test_cmp expect actual
64'
65
34bb92ec 66cat >expected <<EOF
3ac21617 67bin: test version 2
34bb92ec
CP
68EOF
69
70test_expect_success 'no filter specified' '
3ac21617 71 git cat-file --textconv :one.bin >result &&
34bb92ec
CP
72 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
34bb92ec
CP
81test_expect_success 'cat-file without --textconv' '
82 git cat-file blob :one.bin >result &&
83 test_cmp expected result
84'
85
86cat >expected <<EOF
6517cf7d 87bin: test
34bb92ec
CP
88EOF
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'
ab3b7b9a 112
889c6f0e 113test_expect_success 'cat-file without --textconv (symlink)' '
3ac21617 114 printf "%s" "one.bin" >expected &&
ab3b7b9a 115 git cat-file blob :symlink.bin >result &&
ab3b7b9a
KS
116 test_cmp expected result
117'
118
119
889c6f0e 120test_expect_success 'cat-file --textconv on index (symlink)' '
3ac21617 121 git cat-file --textconv :symlink.bin >result &&
ab3b7b9a
KS
122 test_cmp expected result
123'
124
889c6f0e 125test_expect_success 'cat-file --textconv on HEAD (symlink)' '
3ac21617 126 git cat-file --textconv HEAD:symlink.bin >result &&
ab3b7b9a
KS
127 test_cmp expected result
128'
129
34bb92ec 130test_done