Skip to content

Commit ab3b7b9

Browse files
navytuxgitster
authored andcommitted
blame,cat-file: Demonstrate --textconv is wrongly running converter on symlinks
git blame --textconv is wrongly calling the textconv filter on symlinks: symlinks are stored as blobs whose content is the target of the link, and blame calls the textconv filter on a temporary file filled-in with the content of this blob. For example: $ git blame -C -C regular-file.pdf Error: May not be a PDF file (continuing anyway) Error: PDF file is damaged - attempting to reconstruct xref table... Error: Couldn't find trailer dictionary Error: Couldn't read xref table Warning: program returned non-zero exit code #1 fatal: unable to read files to diff That errors come from pdftotext run on symlink.pdf being extracted to /tmp/ with one-line plain-text content pointing to link destination. So several failures are demonstrated here: - git cat-file --textconv :symlink.bin # also HEAD:symlink.bin - git blame --textconv symlink.bin - git blame -C -C --textconv regular-file # but also looks on symlink.bin At present they all fail with something like. E: /tmp/j3ELEs_symlink.bin is not "binary" file NOTE: git diff doesn't try to textconv the pathnames, it runs the textual diff without textconv, which is the expected behavior. Signed-off-by: Kirill Smelkov <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6517cf7 commit ab3b7b9

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

t/t8006-blame-textconv.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ chmod +x helper
1717
test_expect_success 'setup ' '
1818
echo "bin: test 1" >one.bin &&
1919
echo "bin: test number 2" >two.bin &&
20+
if test_have_prereq SYMLINKS; then
21+
ln -s one.bin symlink.bin
22+
fi &&
2023
git add . &&
2124
GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
2225
echo "bin: test 1 version 2" >one.bin &&
2326
echo "bin: test number 2 version 2" >>two.bin &&
27+
if test_have_prereq SYMLINKS; then
28+
ln -sf two.bin symlink.bin
29+
fi &&
2430
GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
2531
'
2632

@@ -78,4 +84,47 @@ test_expect_success 'blame from previous revision' '
7884
test_cmp expected result
7985
'
8086

87+
cat >expected <<EOF
88+
(Number2 2010-01-01 20:00:00 +0000 1) two.bin
89+
EOF
90+
91+
test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
92+
git blame --no-textconv symlink.bin >blame &&
93+
find_blame <blame >result &&
94+
test_cmp expected result
95+
'
96+
97+
# fails with '...symlink.bin is not "binary" file'
98+
test_expect_failure SYMLINKS 'blame --textconv (on symlink)' '
99+
git blame --textconv symlink.bin >blame &&
100+
find_blame <blame >result &&
101+
test_cmp expected result
102+
'
103+
104+
# cp two.bin three.bin and make small tweak
105+
# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
106+
test_expect_success SYMLINKS 'make another new commit' '
107+
cat >three.bin <<\EOF &&
108+
bin: test number 2
109+
bin: test number 2 version 2
110+
bin: test number 2 version 3
111+
bin: test number 3
112+
EOF
113+
git add three.bin &&
114+
GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
115+
'
116+
117+
# fails with '...symlink.bin is not "binary" file'
118+
test_expect_failure SYMLINKS 'blame on last commit (-C -C, symlink)' '
119+
git blame -C -C three.bin >blame &&
120+
find_blame <blame >result &&
121+
cat >expected <<\EOF &&
122+
(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
123+
(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
124+
(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
125+
(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
126+
EOF
127+
test_cmp expected result
128+
'
129+
81130
test_done

t/t8007-cat-file-textconv.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ chmod +x helper
1212

1313
test_expect_success 'setup ' '
1414
echo "bin: test" >one.bin &&
15+
if test_have_prereq SYMLINKS; then
16+
ln -s one.bin symlink.bin
17+
fi &&
1518
git add . &&
1619
GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
1720
echo "bin: test version 2" >one.bin &&
@@ -68,4 +71,30 @@ test_expect_success 'cat-file --textconv on previous commit' '
6871
git cat-file --textconv HEAD^:one.bin >result &&
6972
test_cmp expected result
7073
'
74+
75+
test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' '
76+
git cat-file blob :symlink.bin >result &&
77+
printf "%s" "one.bin" >expected
78+
test_cmp expected result
79+
'
80+
81+
82+
# fails because cat-file tries to run converter on symlink.bin
83+
test_expect_failure SYMLINKS 'cat-file --textconv on index (symlink)' '
84+
! git cat-file --textconv :symlink.bin 2>result &&
85+
cat >expected <<\EOF &&
86+
fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
87+
EOF
88+
test_cmp expected result
89+
'
90+
91+
# fails because cat-file tries to run converter on symlink.bin
92+
test_expect_failure SYMLINKS 'cat-file --textconv on HEAD (symlink)' '
93+
! git cat-file --textconv HEAD:symlink.bin 2>result &&
94+
cat >expected <<EOF &&
95+
fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin
96+
EOF
97+
test_cmp expected result
98+
'
99+
71100
test_done

0 commit comments

Comments
 (0)