aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/patch.go
diff options
context:
space:
mode:
authoroleksiishnyra <oshnyra@osdb.io>2019-03-14 23:06:17 +0200
committerOleksii Shnyra <oleksii@global>2019-03-14 23:18:33 +0200
commit2a9b544f175ce8bd0268e5516485888738164e41 (patch)
tree71889c98a14369bba52662c6d867d94876516a8c /plumbing/object/patch.go
parent948b0c930bf1b173b172e5f28aa71da454c3a093 (diff)
downloadgo-git-2a9b544f175ce8bd0268e5516485888738164e41.tar.gz
plumbing: object, Count stats properly when no new line added at the end. Fixes #1074
Signed-off-by: Oleksii Shnyra <oleksii@global>
Diffstat (limited to 'plumbing/object/patch.go')
-rw-r--r--plumbing/object/patch.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/plumbing/object/patch.go b/plumbing/object/patch.go
index adeaccb..068589e 100644
--- a/plumbing/object/patch.go
+++ b/plumbing/object/patch.go
@@ -320,11 +320,18 @@ func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
}
for _, chunk := range fp.Chunks() {
+ s := chunk.Content()
switch chunk.Type() {
case fdiff.Add:
- cs.Addition += strings.Count(chunk.Content(), "\n")
+ cs.Addition += strings.Count(s, "\n")
+ if s[len(s)-1] != '\n' {
+ cs.Addition++
+ }
case fdiff.Delete:
- cs.Deletion += strings.Count(chunk.Content(), "\n")
+ cs.Deletion += strings.Count(s, "\n")
+ if s[len(s)-1] != '\n' {
+ cs.Deletion++
+ }
}
}