]> git.ipfire.org Git - thirdparty/git.git/blob - t/t8007-cat-file-textconv.sh
Merge branch 'tl/doc-cli-options-first'
[thirdparty/git.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 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
28 '
29
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
36 '
37
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
44 '
45
46
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
53 '
54
55
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
62 '
63
64 cat >expected <<EOF
65 bin: test version 2
66 EOF
67
68 test_expect_success 'no filter specified' '
69 git cat-file --textconv :one.bin >result &&
70 test_cmp expected result
71 '
72
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
77 '
78
79 test_expect_success 'cat-file without --textconv' '
80 git cat-file blob :one.bin >result &&
81 test_cmp expected result
82 '
83
84 cat >expected <<EOF
85 bin: test
86 EOF
87
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
91 '
92
93 cat >expected <<EOF
94 converted: test version 2
95 EOF
96
97 test_expect_success 'cat-file --textconv on last commit' '
98 git cat-file --textconv :one.bin >result &&
99 test_cmp expected result
100 '
101
102 cat >expected <<EOF
103 converted: test
104 EOF
105
106 test_expect_success 'cat-file --textconv on previous commit' '
107 git cat-file --textconv HEAD^:one.bin >result &&
108 test_cmp expected result
109 '
110
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
115 '
116
117
118 test_expect_success 'cat-file --textconv on index (symlink)' '
119 git cat-file --textconv :symlink.bin >result &&
120 test_cmp expected result
121 '
122
123 test_expect_success 'cat-file --textconv on HEAD (symlink)' '
124 git cat-file --textconv HEAD:symlink.bin >result &&
125 test_cmp expected result
126 '
127
128 test_done