]> source.dussan.org Git - gitea.git/commitdiff
Fix file rename/copy not supported by indexer (#9967)
authorguillep2k <18600385+guillep2k@users.noreply.github.com>
Fri, 24 Jan 2020 23:25:00 +0000 (20:25 -0300)
committertechknowlogick <techknowlogick@gitea.io>
Fri, 24 Jan 2020 23:25:00 +0000 (18:25 -0500)
modules/indexer/code/git.go

index bfa7d20438ef8f67063b617d6e336485efc3f5f9..114d5a9e6d4684ddfefd860f952b0638a306a979 100644 (file)
@@ -116,7 +116,12 @@ func nonGenesisChanges(repo *models.Repository, revision string) (*repoChanges,
                if len(line) == 0 {
                        continue
                }
-               filename := strings.TrimSpace(line[1:])
+               fields := strings.Split(line, "\t")
+               if len(fields) < 2 {
+                       log.Warn("Unparseable output for diff --name-status: `%s`)", line)
+                       continue
+               }
+               filename := fields[1]
                if len(filename) == 0 {
                        continue
                } else if filename[0] == '"' {
@@ -126,11 +131,31 @@ func nonGenesisChanges(repo *models.Repository, revision string) (*repoChanges,
                        }
                }
 
-               switch status := line[0]; status {
+               switch status := fields[0][0]; status {
                case 'M', 'A':
                        updatedFilenames = append(updatedFilenames, filename)
                case 'D':
                        changes.RemovedFilenames = append(changes.RemovedFilenames, filename)
+               case 'R', 'C':
+                       if len(fields) < 3 {
+                               log.Warn("Unparseable output for diff --name-status: `%s`)", line)
+                               continue
+                       }
+                       dest := fields[2]
+                       if len(dest) == 0 {
+                               log.Warn("Unparseable output for diff --name-status: `%s`)", line)
+                               continue
+                       }
+                       if dest[0] == '"' {
+                               dest, err = strconv.Unquote(dest)
+                               if err != nil {
+                                       return nil, err
+                               }
+                       }
+                       if status == 'R' {
+                               changes.RemovedFilenames = append(changes.RemovedFilenames, filename)
+                       }
+                       updatedFilenames = append(updatedFilenames, dest)
                default:
                        log.Warn("Unrecognized status: %c (line=%s)", status, line)
                }