Browse Source

Fix diff of renamed and modified file (#1967)

Ethan Koenig 2 years ago
parent
commit
57cabb3ad3
2 changed files with 7 additions and 8 deletions
  1. 6 7
      models/git_diff.go
  2. 1 1
      templates/repo/diff/box.tmpl

+ 6 - 7
models/git_diff.go

@@ -365,10 +365,12 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
365 365
 			}
366 366
 
367 367
 			curFile = &DiffFile{
368
-				Name:     a,
369
-				Index:    len(diff.Files) + 1,
370
-				Type:     DiffFileChange,
371
-				Sections: make([]*DiffSection, 0, 10),
368
+				Name:      b,
369
+				OldName:   a,
370
+				Index:     len(diff.Files) + 1,
371
+				Type:      DiffFileChange,
372
+				Sections:  make([]*DiffSection, 0, 10),
373
+				IsRenamed: a != b,
372 374
 			}
373 375
 			diff.Files = append(diff.Files, curFile)
374 376
 			if len(diff.Files) >= maxFiles {
@@ -401,9 +403,6 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
401 403
 					curFile.Type = DiffFileChange
402 404
 				case strings.HasPrefix(line, "similarity index 100%"):
403 405
 					curFile.Type = DiffFileRename
404
-					curFile.IsRenamed = true
405
-					curFile.OldName = curFile.Name
406
-					curFile.Name = b
407 406
 				}
408 407
 				if curFile.Type > 0 {
409 408
 					if strings.HasSuffix(line, " 160000\n") {

+ 1 - 1
templates/repo/diff/box.tmpl

@@ -78,7 +78,7 @@
78 78
 					{{end}}
79 79
 				</h4>
80 80
 				<div class="ui attached table segment">
81
-					{{if not $file.IsRenamed}}
81
+					{{if ne $file.Type 4}}
82 82
 						{{$isImage := (call $.IsImageFile $file.Name)}}
83 83
 						{{if and $isImage}}
84 84
 							<div class="center">