Skip to content

Commit 8354b03

Browse files
committed
blame: CRLF in the working tree and LF in the repo
A typical setup under Windows is to set core.eol to CRLF, and text files are marked as "text" in .gitattributes, or core.autocrlf is set to true. After 4d4813a "git blame" no longer works as expected for such a set-up. Every line is annotated as "Not Committed Yet", even though the working directory is clean. This is because the commit removed the conversion in blame.c for all files, with or without CRLF in the repo. Having files with CRLF in the repo and core.autocrlf=input is a temporary situation, and the files, if committed as is, will be normalized in the repo, which _will_ be a notable change. Blaming them with "Not Committed Yet" is the right result. Revert commit 4d4813a which was a misguided attempt to "solve" a non-problem. Add two test cases in t8003 to verify the correct CRLF conversion. Suggested-By: Stepan Kasal <[email protected]> Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0db3460 commit 8354b03

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

builtin/blame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
23482348
if (strbuf_read(&buf, 0, 0) < 0)
23492349
die_errno("failed to read from stdin");
23502350
}
2351+
convert_to_git(path, buf.buf, buf.len, &buf, 0);
23512352
origin->file.ptr = buf.buf;
23522353
origin->file.size = buf.len;
23532354
pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);

t/t8003-blame-corner-cases.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,24 @@ test_expect_success 'indent of line numbers, ten lines' '
191191
test $(grep -c " " actual) = 9
192192
'
193193

194-
test_expect_success 'blaming files with CRLF newlines' '
194+
test_expect_success 'setup file with CRLF newlines' '
195195
git config core.autocrlf false &&
196-
printf "testcase\r\n" >crlffile &&
196+
printf "testcase\n" >crlffile &&
197197
git add crlffile &&
198198
git commit -m testcase &&
199-
git -c core.autocrlf=input blame crlffile >actual &&
199+
printf "testcase\r\n" >crlffile
200+
'
201+
202+
test_expect_success 'blame file with CRLF core.autocrlf true' '
203+
git config core.autocrlf true &&
204+
git blame crlffile >actual &&
205+
grep "A U Thor" actual
206+
'
207+
208+
test_expect_success 'blame file with CRLF attributes text' '
209+
git config core.autocrlf false &&
210+
echo "crlffile text" >.gitattributes &&
211+
git blame crlffile >actual &&
200212
grep "A U Thor" actual
201213
'
202214

0 commit comments

Comments
 (0)