Преглед изворни кода

Fix the bug with files switching to binary

Signed-off-by: Vadim Markovtsev <vadim@sourced.tech>
Vadim Markovtsev пре 6 година
родитељ
комит
a68a4ef955
1 измењених фајлова са 8 додато и 2 уклоњено
  1. 8 2
      leaves/burndown.go

+ 8 - 2
leaves/burndown.go

@@ -1149,12 +1149,18 @@ func (analyser *BurndownAnalysis) handleInsertion(
 func (analyser *BurndownAnalysis) handleDeletion(
 func (analyser *BurndownAnalysis) handleDeletion(
 	change *object.Change, author int, cache map[plumbing.Hash]*items.CachedBlob) error {
 	change *object.Change, author int, cache map[plumbing.Hash]*items.CachedBlob) error {
 
 
-	name := change.From.Name
+	var name string
+	if change.To.TreeEntry.Hash != plumbing.ZeroHash {
+		// became binary
+		name = change.To.Name
+	} else {
+		name = change.From.Name
+	}
 	file, exists := analyser.files[name]
 	file, exists := analyser.files[name]
 	blob := cache[change.From.TreeEntry.Hash]
 	blob := cache[change.From.TreeEntry.Hash]
 	lines, err := blob.CountLines()
 	lines, err := blob.CountLines()
 	if exists && err != nil {
 	if exists && err != nil {
-		return fmt.Errorf("file %s unexpectedly became binary", name)
+		return fmt.Errorf("previous version of %s unexpectedly became binary", name)
 	}
 	}
 	if !exists {
 	if !exists {
 		return nil
 		return nil