From 0173fdb9dfb763a13098be96d1693e19b01db8ca Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 20 Feb 2019 19:47:01 +1100 Subject: [PATCH] support file renames --- pkg/commands/git.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index fa6e4c5fe..23cfc2e46 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -387,7 +387,15 @@ func (c *GitCommand) UnStageFile(fileName string, tracked bool) error { if tracked { command = "git reset HEAD %s" } - return c.OSCommand.RunCommand(fmt.Sprintf(command, c.OSCommand.Quote(fileName))) + + // renamed files look like "file1 -> file2" + fileNames := strings.Split(fileName, " -> ") + for _, name := range fileNames { + if err := c.OSCommand.RunCommand(fmt.Sprintf(command, c.OSCommand.Quote(name))); err != nil { + return err + } + } + return nil } // GitStatus returns the plaintext short status of the repo @@ -532,7 +540,8 @@ func (c *GitCommand) Diff(file *File, plain bool) string { cachedArg := "" trackedArg := "--" colorArg := "--color" - fileName := c.OSCommand.Quote(file.Name) + split := strings.Split(file.Name, " -> ") // in case of a renamed file we get the new filename + fileName := c.OSCommand.Quote(split[len(split)-1]) if file.HasStagedChanges && !file.HasUnstagedChanges { cachedArg = "--cached" }