Skip to content

Commit 3ac2161

Browse files
Michael J Grubergitster
authored andcommitted
cat-file: do not die on --textconv without textconv filters
When a command is supposed to use textconv filters (by default or with "--textconv") and none are configured then the blob is output without conversion; the only exception to this rule is "cat-file --textconv". Make it behave like the rest of textconv aware commands. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 083b993 commit 3ac2161

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

builtin/cat-file.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
115115
case 'e':
116116
return !has_sha1_file(sha1);
117117

118+
case 'c':
119+
if (!obj_context.path[0])
120+
die("git cat-file --textconv %s: <object> must be <sha1:path>",
121+
obj_name);
122+
123+
if (textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size))
124+
break;
125+
118126
case 'p':
119127
type = sha1_object_info(sha1, NULL);
120128
if (type < 0)
@@ -141,16 +149,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
141149
/* otherwise just spit out the data */
142150
break;
143151

144-
case 'c':
145-
if (!obj_context.path[0])
146-
die("git cat-file --textconv %s: <object> must be <sha1:path>",
147-
obj_name);
148-
149-
if (!textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size))
150-
die("git cat-file --textconv: unable to run textconv on %s",
151-
obj_name);
152-
break;
153-
154152
case 0:
155153
if (type_from_string(exp_type) == OBJ_BLOB) {
156154
unsigned char blob_sha1[20];

t/t8007-cat-file-textconv.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ test_expect_success 'setup ' '
2222
'
2323

2424
cat >expected <<EOF
25-
fatal: git cat-file --textconv: unable to run textconv on :one.bin
25+
bin: test version 2
2626
EOF
2727

2828
test_expect_success 'no filter specified' '
29-
git cat-file --textconv :one.bin 2>result
29+
git cat-file --textconv :one.bin >result &&
3030
test_cmp expected result
3131
'
3232

@@ -36,10 +36,6 @@ test_expect_success 'setup textconv filters' '
3636
git config diff.test.cachetextconv false
3737
'
3838

39-
cat >expected <<EOF
40-
bin: test version 2
41-
EOF
42-
4339
test_expect_success 'cat-file without --textconv' '
4440
git cat-file blob :one.bin >result &&
4541
test_cmp expected result
@@ -73,25 +69,19 @@ test_expect_success 'cat-file --textconv on previous commit' '
7369
'
7470

7571
test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' '
72+
printf "%s" "one.bin" >expected &&
7673
git cat-file blob :symlink.bin >result &&
77-
printf "%s" "one.bin" >expected
7874
test_cmp expected result
7975
'
8076

8177

8278
test_expect_success SYMLINKS 'cat-file --textconv on index (symlink)' '
83-
! git cat-file --textconv :symlink.bin 2>result &&
84-
cat >expected <<\EOF &&
85-
fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
86-
EOF
79+
git cat-file --textconv :symlink.bin >result &&
8780
test_cmp expected result
8881
'
8982

9083
test_expect_success SYMLINKS 'cat-file --textconv on HEAD (symlink)' '
91-
! git cat-file --textconv HEAD:symlink.bin 2>result &&
92-
cat >expected <<EOF &&
93-
fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin
94-
EOF
84+
git cat-file --textconv HEAD:symlink.bin >result &&
9585
test_cmp expected result
9686
'
9787

0 commit comments

Comments
 (0)