diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-20 12:07:11 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-20 12:46:27 +1100 |
commit | ad1468f66f8af1724a99bc4c1a653ac71c6cadcb (patch) | |
tree | 1ec69ad08f0f07a6d9f881be034ee3400df4cc13 /pkg/commands/files.go | |
parent | 058bcddc53cff6360583cd575fe64da76b53f94b (diff) |
better handling of discarding files
Diffstat (limited to 'pkg/commands/files.go')
-rw-r--r-- | pkg/commands/files.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 00b32e732..55a5f55d3 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -107,15 +107,34 @@ func (c *GitCommand) DiscardAllFileChanges(file *models.File) error { return nil } - // if the file isn't tracked, we assume you want to delete it quotedFileName := c.OSCommand.Quote(file.Name) + + if file.ShortStatus == "AA" { + if err := c.OSCommand.RunCommand("git checkout --ours -- %s", quotedFileName); err != nil { + return err + } + if err := c.OSCommand.RunCommand("git add %s", quotedFileName); err != nil { + return err + } + return nil + } + + if file.ShortStatus == "DU" { + return c.OSCommand.RunCommand("git rm %s", quotedFileName) + } + + // if the file isn't tracked, we assume you want to delete it if file.HasStagedChanges || file.HasMergeConflicts { if err := c.OSCommand.RunCommand("git reset -- %s", quotedFileName); err != nil { return err } } - if !file.Tracked { + if file.ShortStatus == "DD" || file.ShortStatus == "AU" { + return nil + } + + if file.Added { return c.removeFile(file.Name) } return c.DiscardUnstagedFileChanges(file) |