]>
Commit | Line | Data |
---|---|---|
34bb92ec CP |
1 | #!/bin/sh |
2 | ||
3 | test_description='git cat-file textconv support' | |
4 | . ./test-lib.sh | |
5 | ||
6 | cat >helper <<'EOF' | |
7 | #!/bin/sh | |
6517cf7d KS |
8 | grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } |
9 | sed 's/^bin: /converted: /' "$1" | |
34bb92ec CP |
10 | EOF |
11 | chmod +x helper | |
12 | ||
13 | test_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 |
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 && | |
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 | ||
38 | test_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 | ||
47 | test_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 | ||
56 | test_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 | 64 | cat >expected <<EOF |
3ac21617 | 65 | bin: test version 2 |
34bb92ec CP |
66 | EOF |
67 | ||
68 | test_expect_success 'no filter specified' ' | |
3ac21617 | 69 | git cat-file --textconv :one.bin >result && |
34bb92ec CP |
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 | ||
34bb92ec CP |
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 | |
6517cf7d | 85 | bin: test |
34bb92ec CP |
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 | ' | |
ab3b7b9a | 110 | |
889c6f0e | 111 | test_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 | 118 | test_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 | 123 | test_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 | 128 | test_done |