mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-05 15:15:49 +02:00
better error handling for stashing files
This commit is contained in:
parent
88af0fb1b6
commit
efb049cd24
@ -21,7 +21,8 @@ var (
|
||||
errNoUsername = errors.New(`No username set. Please do: git config --global user.name "Your Name"`)
|
||||
)
|
||||
|
||||
func (gui *Gui) stagedFiles(files []commands.File) []commands.File {
|
||||
func (gui *Gui) stagedFiles() []commands.File {
|
||||
files := gui.State.Files
|
||||
result := make([]commands.File, 0)
|
||||
for _, file := range files {
|
||||
if file.HasStagedChanges {
|
||||
@ -31,6 +32,17 @@ func (gui *Gui) stagedFiles(files []commands.File) []commands.File {
|
||||
return result
|
||||
}
|
||||
|
||||
func (gui *Gui) trackedFiles() []commands.File {
|
||||
files := gui.State.Files
|
||||
result := make([]commands.File, 0)
|
||||
for _, file := range files {
|
||||
if file.Tracked {
|
||||
result = append(result, file)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (gui *Gui) stageSelectedFile(g *gocui.Gui) error {
|
||||
file, err := gui.getSelectedFile(g)
|
||||
if err != nil {
|
||||
@ -180,7 +192,7 @@ func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
}
|
||||
|
||||
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||
if len(gui.stagedFiles(gui.State.Files)) == 0 && !gui.State.HasMergeConflicts {
|
||||
if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts {
|
||||
return gui.createErrorPanel(g, "There are no staged files to commit")
|
||||
}
|
||||
commitMessageView := gui.getCommitMessageView(g)
|
||||
@ -195,7 +207,7 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||
// handleCommitEditorPress - handle when the user wants to commit changes via
|
||||
// their editor rather than via the popup panel
|
||||
func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||
if len(gui.stagedFiles(gui.State.Files)) == 0 && !gui.State.HasMergeConflicts {
|
||||
if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts {
|
||||
return gui.createErrorPanel(g, "There are no staged files to commit")
|
||||
}
|
||||
gui.PrepareSubProcess(g, "git", "commit")
|
||||
|
@ -83,6 +83,9 @@ func (gui *Gui) stashDo(g *gocui.Gui, v *gocui.View, method string) error {
|
||||
}
|
||||
|
||||
func (gui *Gui) handleStashSave(g *gocui.Gui, filesView *gocui.View) error {
|
||||
if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 {
|
||||
return gui.createErrorPanel(g, "You have no tracked/staged files to stash")
|
||||
}
|
||||
gui.createPromptPanel(g, filesView, "Stash changes", func(g *gocui.Gui, v *gocui.View) error {
|
||||
if err := gui.GitCommand.StashSave(gui.trimmedContent(v)); err != nil {
|
||||
gui.createErrorPanel(g, err.Error())
|
||||
|
Loading…
x
Reference in New Issue
Block a user