Skip to content

Commit 6c0d0fa

Browse files
overshomsapk
authored andcommitted
plumbing: object, Count stats properly when no new line added at the end. Fixes src-d#1074
Signed-off-by: Oleksii Shnyra <oleksii@global> Signed-off-by: Antoine GIRARD <[email protected]>
1 parent 80091b8 commit 6c0d0fa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

plumbing/object/patch.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,18 @@ func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
320320
}
321321

322322
for _, chunk := range fp.Chunks() {
323+
s := chunk.Content()
323324
switch chunk.Type() {
324325
case fdiff.Add:
325-
cs.Addition += strings.Count(chunk.Content(), "\n")
326+
cs.Addition += strings.Count(s, "\n")
327+
if s[len(s)-1] != '\n' {
328+
cs.Addition++
329+
}
326330
case fdiff.Delete:
327-
cs.Deletion += strings.Count(chunk.Content(), "\n")
331+
cs.Deletion += strings.Count(s, "\n")
332+
if s[len(s)-1] != '\n' {
333+
cs.Deletion++
334+
}
328335
}
329336
}
330337

0 commit comments

Comments
 (0)