interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t8007-cat-file-textconv.sh

129 lines · 3127 bytes Raw Blame History
1#!/bin/sh
2
3test_description='git cat-file textconv support'
4
5. ./test-lib.sh
6
7cat >helper <<'EOF'
8#!/bin/sh
9grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
10sed 's/^bin: /converted: /' "$1"
11EOF
12chmod +x helper
13
14test_expect_success 'setup ' '
15 echo "bin: test" >one.bin &&
16 test_ln_s_add one.bin symlink.bin &&
17 git add . &&
18 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
19 echo "bin: test version 2" >one.bin &&
20 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
21'
22
23test_expect_success 'usage: <bad rev>' '
24 cat >expect <<-\EOF &&
25 fatal: Not a valid object name HEAD2
26 EOF
27 test_must_fail git cat-file --textconv HEAD2 2>actual &&
28 test_cmp expect actual
29'
30
31test_expect_success 'usage: <bad rev>:<bad path>' '
32 cat >expect <<-\EOF &&
33 fatal: invalid object name '\''HEAD2'\''.
34 EOF
35 test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual &&
36 test_cmp expect actual
37'
38
39test_expect_success 'usage: <rev>:<bad path>' '
40 cat >expect <<-\EOF &&
41 fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\''
42 EOF
43 test_must_fail git cat-file --textconv HEAD:two.bin 2>actual &&
44 test_cmp expect actual
45'
46
47
48test_expect_success 'usage: <rev> with no <path>' '
49 cat >expect <<-\EOF &&
50 fatal: <object>:<path> required, only <object> '\''HEAD'\'' given
51 EOF
52 test_must_fail git cat-file --textconv HEAD 2>actual &&
53 test_cmp expect actual
54'
55
56
57test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' '
58 cat >expect <<-\EOF &&
59 fatal: invalid object name '\''HEAD2'\''.
60 EOF
61 test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual &&
62 test_cmp expect actual
63'
64
65cat >expected <<EOF
66bin: test version 2
67EOF
68
69test_expect_success 'no filter specified' '
70 git cat-file --textconv :one.bin >result &&
71 test_cmp expected result
72'
73
74test_expect_success 'setup textconv filters' '
75 echo "*.bin diff=test" >.gitattributes &&
76 git config diff.test.textconv ./helper &&
77 git config diff.test.cachetextconv false
78'
79
80test_expect_success 'cat-file without --textconv' '
81 git cat-file blob :one.bin >result &&
82 test_cmp expected result
83'
84
85cat >expected <<EOF
86bin: test
87EOF
88
89test_expect_success 'cat-file without --textconv on previous commit' '
90 git cat-file -p HEAD^:one.bin >result &&
91 test_cmp expected result
92'
93
94cat >expected <<EOF
95converted: test version 2
96EOF
97
98test_expect_success 'cat-file --textconv on last commit' '
99 git cat-file --textconv :one.bin >result &&
100 test_cmp expected result
101'
102
103cat >expected <<EOF
104converted: test
105EOF
106
107test_expect_success 'cat-file --textconv on previous commit' '
108 git cat-file --textconv HEAD^:one.bin >result &&
109 test_cmp expected result
110'
111
112test_expect_success 'cat-file without --textconv (symlink)' '
113 printf "%s" "one.bin" >expected &&
114 git cat-file blob :symlink.bin >result &&
115 test_cmp expected result
116'
117
118
119test_expect_success 'cat-file --textconv on index (symlink)' '
120 git cat-file --textconv :symlink.bin >result &&
121 test_cmp expected result
122'
123
124test_expect_success 'cat-file --textconv on HEAD (symlink)' '
125 git cat-file --textconv HEAD:symlink.bin >result &&
126 test_cmp expected result
127'
128
129test_done