1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-09 09:22:48 +03:00

Remove return value of Alert/Confirm/Prompt

This might seem controversial; in many cases the client code gets longer,
because it needs an extra line for an explicit `return nil`. I still prefer
this, because it makes it clearer which calls can return errors.
This commit is contained in:
Stefan Haller
2024-09-05 11:10:27 +02:00
parent b15a1c7ae7
commit d4ef8e53d5
39 changed files with 303 additions and 131 deletions

View File

@@ -79,7 +79,7 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
self.c.OnUIThread(func() error {
// (Before showing the prompt, render again to remove the inline status)
self.c.Contexts().Branches.HandleRender()
return self.c.Confirm(types.ConfirmOpts{
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.AutoStashTitle,
Prompt: self.c.Tr.AutoStashPrompt,
HandleConfirm: func() error {
@@ -97,6 +97,8 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
})
},
})
return nil
})
return nil
}
@@ -292,7 +294,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
}
return self.c.Prompt(types.PromptOpts{
self.c.Prompt(types.PromptOpts{
Title: message,
InitialContent: suggestedBranchName,
HandleConfirm: func(response string) error {
@@ -305,7 +307,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
if err := newBranchFunc(newBranchName, from); err != nil {
if IsSwitchBranchUncommitedChangesError(err) {
// offer to autostash changes
return self.c.Confirm(types.ConfirmOpts{
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.AutoStashTitle,
Prompt: self.c.Tr.AutoStashPrompt,
HandleConfirm: func() error {
@@ -325,6 +327,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
return refreshError
},
})
return nil
}
return err
@@ -333,6 +337,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
return refresh()
},
})
return nil
}
// SanitizedBranchName will remove all spaces in favor of a dash "-" to meet