mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-13 05:15:53 +02:00
improve remove file logic
This commit is contained in:
parent
0174375562
commit
08666889f4
3 changed files with 16 additions and 4 deletions
|
@ -81,7 +81,7 @@ func (c *GitCommand) GetStatusFiles() []File {
|
||||||
stagedChange := change[0:1]
|
stagedChange := change[0:1]
|
||||||
unstagedChange := statusString[1:2]
|
unstagedChange := statusString[1:2]
|
||||||
filename := statusString[3:]
|
filename := statusString[3:]
|
||||||
tracked := !includes([]string{"??", "A "}, change)
|
tracked := !includes([]string{"??", "A ", "AM"}, change)
|
||||||
file := File{
|
file := File{
|
||||||
Name: filename,
|
Name: filename,
|
||||||
DisplayString: statusString,
|
DisplayString: statusString,
|
||||||
|
@ -358,11 +358,16 @@ func (c *GitCommand) IsInMergeState() (bool, error) {
|
||||||
// RemoveFile directly
|
// RemoveFile directly
|
||||||
func (c *GitCommand) RemoveFile(file File) error {
|
func (c *GitCommand) RemoveFile(file File) error {
|
||||||
// if the file isn't tracked, we assume you want to delete it
|
// if the file isn't tracked, we assume you want to delete it
|
||||||
|
if file.HasStagedChanges {
|
||||||
|
if err := c.OSCommand.RunCommand("git reset -- " + file.Name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
if !file.Tracked {
|
if !file.Tracked {
|
||||||
return os.RemoveAll(file.Name)
|
return os.RemoveAll(c.OSCommand.Unquote(file.Name))
|
||||||
}
|
}
|
||||||
// if the file is tracked, we assume you want to just check it out
|
// if the file is tracked, we assume you want to just check it out
|
||||||
return c.OSCommand.RunCommand("git checkout " + file.Name)
|
return c.OSCommand.RunCommand("git checkout -- " + file.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checkout checks out a branch, with --force if you set the force arg to true
|
// Checkout checks out a branch, with --force if you set the force arg to true
|
||||||
|
|
|
@ -167,3 +167,10 @@ func (c *OSCommand) Quote(message string) string {
|
||||||
message = strings.Replace(message, "`", "\\`", -1)
|
message = strings.Replace(message, "`", "\\`", -1)
|
||||||
return c.Platform.escapedQuote + message + c.Platform.escapedQuote
|
return c.Platform.escapedQuote + message + c.Platform.escapedQuote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unquote removes wrapping quotations marks if they are present
|
||||||
|
// this is needed for removing quotes from staged filenames with spaces
|
||||||
|
func (c *OSCommand) Unquote(message string) string {
|
||||||
|
message = strings.Replace(message, `"`, "", -1)
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ func (gui *Gui) handleFileRemove(g *gocui.Gui, v *gocui.View) error {
|
||||||
)
|
)
|
||||||
return gui.createConfirmationPanel(g, v, strings.Title(deleteVerb)+" file", message, func(g *gocui.Gui, v *gocui.View) error {
|
return gui.createConfirmationPanel(g, v, strings.Title(deleteVerb)+" file", message, func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := gui.GitCommand.RemoveFile(file); err != nil {
|
if err := gui.GitCommand.RemoveFile(file); err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
return gui.refreshFiles(g)
|
return gui.refreshFiles(g)
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue