Skip to content

Commit

Permalink
feat(status): Remove untracked file on discard (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin authored Jan 20, 2023
1 parent 59c83e3 commit 7428a0a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cli/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *status) defineKeybindings() error {
Key: '!',
Display: "!",
Desc: "discard changes",
Handler: s.checkoutEntry,
Handler: s.discardEntry,
},
&prompt.KeyBinding{
Key: 'q',
Expand Down Expand Up @@ -192,12 +192,14 @@ func (s *status) resetAllEntries(item interface{}) error {
return s.runCommandWithArgs(args)
}

func (s *status) checkoutEntry(item interface{}) error {
func (s *status) discardEntry(item interface{}) error {
entry := item.(*git.StatusEntry)
var args []string
if entry.EntryType == git.StatusEntryTypeUntracked {
return nil // you can't checkout untracked items
args = []string{"clean", "--force", entry.String()}
} else {
args = []string{"checkout", "--", entry.String()}
}
args := []string{"checkout", "--", entry.String()}
return s.runCommandWithArgs(args)
}

Expand Down

0 comments on commit 7428a0a

Please sign in to comment.