Skip to content

Commit 10e04f6

Browse files
committed
fix: wrong blame data when the first line of file is an empty line (#2685)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 6934836 commit 10e04f6

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/Commands/Blame.cs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Blame(string repo, string file, string revision, bool ignoreWhitespace)
3737
ParseLine(line);
3838

3939
if (_result.IsBinary)
40-
break;
40+
return _result;
4141
}
4242

4343
if (_needUnifyCommitSHA)
@@ -49,6 +49,9 @@ public Blame(string repo, string file, string revision, bool ignoreWhitespace)
4949
}
5050
}
5151

52+
if (_content.Length > 0)
53+
_content.Length--; // Remove the last newline character
54+
5255
_result.Content = _content.ToString();
5356
return _result;
5457
}
@@ -66,9 +69,8 @@ private void ParseLine(string line)
6669
if (!match.Success)
6770
return;
6871

69-
if (_content.Length > 0)
70-
_content.Append('\n');
71-
_content.Append(match.Groups[5].Value);
72+
// Force using `\n` as line-ending
73+
_content.Append(match.Groups[5].Value).Append('\n');
7274

7375
var commit = match.Groups[1].Value;
7476
var file = match.Groups[2].Value.Trim();

0 commit comments

Comments
 (0)