mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
fix renamed files looking wrong
This commit is contained in:
@ -21,7 +21,7 @@ func (c *GitCommand) CatFile(fileName string) (string, error) {
|
|||||||
// StageFile stages a file
|
// StageFile stages a file
|
||||||
func (c *GitCommand) StageFile(fileName string) error {
|
func (c *GitCommand) StageFile(fileName string) error {
|
||||||
// renamed files look like "file1 -> file2"
|
// renamed files look like "file1 -> file2"
|
||||||
fileNames := strings.Split(fileName, " -> ")
|
fileNames := strings.Split(fileName, models.RENAME_SEPARATOR)
|
||||||
return c.OSCommand.RunCommand("git add -- %s", c.OSCommand.Quote(fileNames[len(fileNames)-1]))
|
return c.OSCommand.RunCommand("git add -- %s", c.OSCommand.Quote(fileNames[len(fileNames)-1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func (c *GitCommand) UnStageFile(fileName string, tracked bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// renamed files look like "file1 -> file2"
|
// renamed files look like "file1 -> file2"
|
||||||
fileNames := strings.Split(fileName, " -> ")
|
fileNames := strings.Split(fileName, models.RENAME_SEPARATOR)
|
||||||
for _, name := range fileNames {
|
for _, name := range fileNames {
|
||||||
if err := c.OSCommand.RunCommand(command, c.OSCommand.Quote(name)); err != nil {
|
if err := c.OSCommand.RunCommand(command, c.OSCommand.Quote(name)); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -63,7 +63,7 @@ func (c *GitCommand) BeforeAndAfterFileForRename(file *models.File) (*models.Fil
|
|||||||
// all files, passing the --no-renames flag and then recursively call the function
|
// all files, passing the --no-renames flag and then recursively call the function
|
||||||
// again for the before file and after file. At some point we should fix the abstraction itself
|
// again for the before file and after file. At some point we should fix the abstraction itself
|
||||||
|
|
||||||
split := strings.Split(file.Name, " -> ")
|
split := strings.Split(file.Name, models.RENAME_SEPARATOR)
|
||||||
filesWithoutRenames := c.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
|
filesWithoutRenames := c.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
|
||||||
var beforeFile *models.File
|
var beforeFile *models.File
|
||||||
var afterFile *models.File
|
var afterFile *models.File
|
||||||
@ -143,7 +143,7 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(file *models.File, plain bool, cache
|
|||||||
cachedArg := ""
|
cachedArg := ""
|
||||||
trackedArg := "--"
|
trackedArg := "--"
|
||||||
colorArg := c.colorArg()
|
colorArg := c.colorArg()
|
||||||
split := strings.Split(file.Name, " -> ") // in case of a renamed file we get the new filename
|
split := strings.Split(file.Name, models.RENAME_SEPARATOR) // in case of a renamed file we get the new filename
|
||||||
fileName := c.OSCommand.Quote(split[len(split)-1])
|
fileName := c.OSCommand.Quote(split[len(split)-1])
|
||||||
if cached {
|
if cached {
|
||||||
cachedArg = "--cached"
|
cachedArg = "--cached"
|
||||||
|
@ -14,7 +14,7 @@ func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchM
|
|||||||
reverseFlag = " -R "
|
reverseFlag = " -R "
|
||||||
}
|
}
|
||||||
|
|
||||||
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --submodule --no-ext-diff --name-status -z %s %s %s", reverseFlag, from, to)
|
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --submodule --no-ext-diff --name-status -z --no-renames %s %s %s", reverseFlag, from, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,19 @@ func (c *GitCommand) GitStatus(opts GitStatusOptions) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
statusLines = strings.Replace(statusLines, "\x00", "\n", -1)
|
splitLines := strings.Split(statusLines, "\x00")
|
||||||
return statusLines, nil
|
// if a line starts with 'R' then the next line is the original file.
|
||||||
|
for i := 0; i < len(splitLines)-1; i++ {
|
||||||
|
original := splitLines[i]
|
||||||
|
if strings.HasPrefix(original, "R ") {
|
||||||
|
next := splitLines[i+1]
|
||||||
|
updated := "R " + next + models.RENAME_SEPARATOR + strings.TrimPrefix(original, "R ")
|
||||||
|
splitLines[i] = updated
|
||||||
|
splitLines = append(splitLines[0:i+1], splitLines[i+2:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(splitLines, "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergeStatusFiles merge status files
|
// MergeStatusFiles merge status files
|
||||||
|
Reference in New Issue
Block a user