]> git.ipfire.org Git - thirdparty/git.git/blame - t/t8007-cat-file-textconv.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t8007-cat-file-textconv.sh
CommitLineData
34bb92ec
CP
1#!/bin/sh
2
3test_description='git cat-file textconv support'
4. ./test-lib.sh
5
6cat >helper <<'EOF'
7#!/bin/sh
6517cf7d
KS
8grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
9sed 's/^bin: /converted: /' "$1"
34bb92ec
CP
10EOF
11chmod +x helper
12
13test_expect_success 'setup ' '
6517cf7d 14 echo "bin: test" >one.bin &&
889c6f0e 15 test_ln_s_add one.bin symlink.bin &&
34bb92ec
CP
16 git add . &&
17 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
6517cf7d 18 echo "bin: test version 2" >one.bin &&
34bb92ec
CP
19 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
20'
21
68c69f90
ÆAB
22test_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
28'
29
30test_expect_success 'usage: <bad rev>:<bad path>' '
31 cat >expect <<-\EOF &&
245b9488 32 fatal: invalid object name '\''HEAD2'\''.
68c69f90
ÆAB
33 EOF
34 test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual &&
35 test_cmp expect actual
36'
37
38test_expect_success 'usage: <rev>:<bad path>' '
39 cat >expect <<-\EOF &&
245b9488 40 fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\''
68c69f90
ÆAB
41 EOF
42 test_must_fail git cat-file --textconv HEAD:two.bin 2>actual &&
43 test_cmp expect actual
44'
45
46
47test_expect_success 'usage: <rev> with no <path>' '
48 cat >expect <<-\EOF &&
245b9488 49 fatal: <object>:<path> required, only <object> '\''HEAD'\'' given
68c69f90
ÆAB
50 EOF
51 test_must_fail git cat-file --textconv HEAD 2>actual &&
52 test_cmp expect actual
53'
54
55
56test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' '
57 cat >expect <<-\EOF &&
245b9488 58 fatal: invalid object name '\''HEAD2'\''.
68c69f90
ÆAB
59 EOF
60 test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
61 test_cmp expect actual
62'
63
34bb92ec 64cat >expected <<EOF
3ac21617 65bin: test version 2
34bb92ec
CP
66EOF
67
68test_expect_success 'no filter specified' '
3ac21617 69 git cat-file --textconv :one.bin >result &&
34bb92ec
CP
70 test_cmp expected result
71'
72
73test_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
77'
78
34bb92ec
CP
79test_expect_success 'cat-file without --textconv' '
80 git cat-file blob :one.bin >result &&
81 test_cmp expected result
82'
83
84cat >expected <<EOF
6517cf7d 85bin: test
34bb92ec
CP
86EOF
87
88test_expect_success 'cat-file without --textconv on previous commit' '
89 git cat-file -p HEAD^:one.bin >result &&
90 test_cmp expected result
91'
92
93cat >expected <<EOF
94converted: test version 2
95EOF
96
97test_expect_success 'cat-file --textconv on last commit' '
98 git cat-file --textconv :one.bin >result &&
99 test_cmp expected result
100'
101
102cat >expected <<EOF
103converted: test
104EOF
105
106test_expect_success 'cat-file --textconv on previous commit' '
107 git cat-file --textconv HEAD^:one.bin >result &&
108 test_cmp expected result
109'
ab3b7b9a 110
889c6f0e 111test_expect_success 'cat-file without --textconv (symlink)' '
3ac21617 112 printf "%s" "one.bin" >expected &&
ab3b7b9a 113 git cat-file blob :symlink.bin >result &&
ab3b7b9a
KS
114 test_cmp expected result
115'
116
117
889c6f0e 118test_expect_success 'cat-file --textconv on index (symlink)' '
3ac21617 119 git cat-file --textconv :symlink.bin >result &&
ab3b7b9a
KS
120 test_cmp expected result
121'
122
889c6f0e 123test_expect_success 'cat-file --textconv on HEAD (symlink)' '
3ac21617 124 git cat-file --textconv HEAD:symlink.bin >result &&
ab3b7b9a
KS
125 test_cmp expected result
126'
127
34bb92ec 128test_done