Skip to contentSkip to conversation

git blame: "Not Committed Yet" with clean WD

PATCH In review Ephrim Khong 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

for files that contain windows line endings in a repository with core.autocrlf=input, git blame will show lines as "Not Committed Yet", even though they were not modified.

Example:

--
git init
git config core.autocrlf false
echo "foo" > a
unix2dos a
git add a
git commit -m "initial commit"
git config core.autocrlf input
git status
git blame a
--

Output:

--
Reinitialized existing Git repository in /.../testblame2/.git/
unix2dos: converting file a to DOS format ...
On branch master
nothing to commit, working directory clean
On branch master
nothing to commit, working directory clean
00000000 (Not Committed Yet 2014-02-13 10:02:43 +0100 1) foo --

Is there an easy way to work around this; is this desired behaviour or mor a bug?

Thanks - Eph

#1 lore raw
Quoted 32 lines · Ephrim Khong

Hi,

for files that contain windows line endings in a repository with core.autocrlf=input, git blame will show lines as "Not Committed Yet", even though they were not modified.

Example:

--
git init
git config core.autocrlf false
echo "foo" > a
unix2dos a
git add a
git commit -m "initial commit"
git config core.autocrlf input
git status
git blame a
--

Output:

--
Reinitialized existing Git repository in /.../testblame2/.git/
unix2dos: converting file a to DOS format ...
On branch master
nothing to commit, working directory clean
On branch master
nothing to commit, working directory clean
00000000 (Not Committed Yet 2014-02-13 10:02:43 +0100 1) foo --

Quoted 2 lines

Is there an easy way to work around this; is this desired behaviour or mor a bug?

I'm pretty sure this is a bug. git blame should show the proper information in this case.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
#2 lore raw

PATCH 1/1 blame: add a failing test for a CRLF issue.

If a file contains CRLF line endings in a repository with core.autocrlf=input, then blame always marks the lines as "Not Committed Yet", even if they are unmodified. Add a failing test for this case, so we are at least aware of this issue.

---

Obviously, this doesn't actually fix the issue, but at least we're aware of it so we don't lose track of it and can fix it. A future patch can mark the test passing.

 t/t8003-blame-corner-cases.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)
t/t8003-blame-corner-cases.sh +10 -0
index e7cac1d..903f775 100755
@@ -191,4 +191,14 @@ test_expect_success 'indent of line numbers, ten lines' '
 	test $(grep -c "  " actual) = 9
 '
 
+test_expect_failure 'blaming files with CRLF newlines' '
+	git config core.autocrlf false &&
+	printf "testcase\r\n" >crlffile &&
+	git add crlffile &&
+	git commit -m testcase &&
+	git config core.autocrlf input &&
+	git blame crlffile >actual &&
+	grep "A U Thor" actual
+'
+
 test_done
Signature · 1 line
1.9.0.rc3.1008.gd08b47c.dirty
#3 lore raw

Re: [PATCH] blame: add a failing test for a CRLF issue.

Quoted 26 lines · brian m. carlson

If a file contains CRLF line endings in a repository with core.autocrlf=input, then blame always marks the lines as "Not Committed Yet", even if they are unmodified. Add a failing test for this case, so we are at least aware of this issue.

---

Obviously, this doesn't actually fix the issue, but at least we're aware of it so we don't lose track of it and can fix it. A future patch can mark the test passing.

  t/t8003-blame-corner-cases.sh | 10 ++++++++++
  1 file changed, 10 insertions(+)
t/t8003-blame-corner-cases.sh +1 -0
index e7cac1d..903f775 100755
@@ -191,4 +191,14 @@ test_expect_success 'indent of line numbers, ten lines' '
  	test $(grep -c "  " actual) = 9
  '
 
+test_expect_failure 'blaming files with CRLF newlines' '

t/t8003-blame-corner-cases.sh test_expect_success 'indent of line numbers, ten lines' ' · line 204

Quoted 10 lines
t/t8003-blame-corner-cases.sh +9 -0
+	git config core.autocrlf false &&
+	printf "testcase\r\n" >crlffile &&
+	git add crlffile &&
+	git commit -m testcase &&
+	git config core.autocrlf input &&
+	git blame crlffile >actual &&
+	grep "A U Thor" actual
+'
+
  test_done

We can test that git blame gives the same result with core.autocrlf=input and core.autocrlf=false, and make the test case look like this:

test_expect_failure 'blaming files with CRLF newlines' '

	git config core.autocrlf false &&
	printf "testcase\r\n" >crlffile &&
	git add crlffile &&
	git commit -m testcase &&
	git blame crlffile >expected &&
	git -c core.autocrlf=input blame crlffile >actual &&
	test_cmp expected actual

'