mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-24 08:52:21 +02:00
factoring out error panel creation
This commit is contained in:
parent
d1ead5b0cf
commit
9c018c6138
@ -9,7 +9,7 @@ import (
|
||||
func handleBranchPress(g *gocui.Gui, v *gocui.View) error {
|
||||
branch := getSelectedBranch(v)
|
||||
if output, err := gitCheckout(branch.Name, false); err != nil {
|
||||
createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
createErrorPanel(g, output)
|
||||
}
|
||||
return refreshSidePanels(g, v)
|
||||
}
|
||||
@ -18,7 +18,7 @@ func handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
|
||||
branch := getSelectedBranch(v)
|
||||
return createConfirmationPanel(g, v, "Force Checkout Branch", "Are you sure you want force checkout? You will lose all local changes (y/n)", func(g *gocui.Gui, v *gocui.View) error {
|
||||
if output, err := gitCheckout(branch.Name, true); err != nil {
|
||||
createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
createErrorPanel(g, output)
|
||||
}
|
||||
return refreshSidePanels(g, v)
|
||||
}, nil)
|
||||
@ -27,9 +27,8 @@ func handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
|
||||
func handleNewBranch(g *gocui.Gui, v *gocui.View) error {
|
||||
branch := state.Branches[0]
|
||||
createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", func(g *gocui.Gui, v *gocui.View) error {
|
||||
// TODO: make sure the buffer is stripped of whitespace
|
||||
if output, err := gitNewBranch(v.Buffer()); err != nil {
|
||||
return createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
if output, err := gitNewBranch(trimmedContent(v)); err != nil {
|
||||
return createErrorPanel(g, output)
|
||||
}
|
||||
refreshSidePanels(g, v)
|
||||
return handleCommitSelect(g, v)
|
||||
@ -49,8 +48,7 @@ func handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
return renderString(g, "main", "No branches for this repo")
|
||||
}
|
||||
go func() {
|
||||
lineNumber := getItemPosition(v)
|
||||
branch := state.Branches[lineNumber]
|
||||
branch := getSelectedBranch(v)
|
||||
diff, _ := getBranchDiff(branch.Name, branch.BaseBranch)
|
||||
renderString(g, "main", diff)
|
||||
}()
|
||||
|
@ -47,7 +47,7 @@ func handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error {
|
||||
panic(err)
|
||||
}
|
||||
if output, err := gitResetToCommit(commit.Sha); err != nil {
|
||||
return createSimpleConfirmationPanel(g, commitView, "Error", output)
|
||||
return createErrorPanel(g, output)
|
||||
}
|
||||
if err := refreshCommits(g); err != nil {
|
||||
panic(err)
|
||||
@ -75,17 +75,17 @@ func handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
|
||||
func handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error {
|
||||
if getItemPosition(v) != 0 {
|
||||
return createSimpleConfirmationPanel(g, v, "Error", "Can only squash topmost commit")
|
||||
return createErrorPanel(g, "Can only squash topmost commit")
|
||||
}
|
||||
if len(state.Commits) == 1 {
|
||||
return createSimpleConfirmationPanel(g, v, "Error", "You have no commits to squash with")
|
||||
return createErrorPanel(g, "You have no commits to squash with")
|
||||
}
|
||||
commit, err := getSelectedCommit(g)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if output, err := gitSquashPreviousTwoCommits(commit.Name); err != nil {
|
||||
return createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
return createErrorPanel(g, output)
|
||||
}
|
||||
if err := refreshCommits(g); err != nil {
|
||||
panic(err)
|
||||
@ -96,11 +96,11 @@ func handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error {
|
||||
|
||||
func handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
|
||||
if getItemPosition(v) != 0 {
|
||||
return createSimpleConfirmationPanel(g, v, "Error", "Can only rename topmost commit")
|
||||
return createErrorPanel(g, "Can only rename topmost commit")
|
||||
}
|
||||
createPromptPanel(g, v, "Rename Commit", func(g *gocui.Gui, v *gocui.View) error {
|
||||
if output, err := gitRenameCommit(v.Buffer()); err != nil {
|
||||
return createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
return createErrorPanel(g, output)
|
||||
}
|
||||
if err := refreshCommits(g); err != nil {
|
||||
panic(err)
|
||||
|
@ -91,7 +91,7 @@ func handleIgnoreFile(g *gocui.Gui, v *gocui.View) error {
|
||||
}
|
||||
|
||||
func handleFileSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
baseString := "tab: switch to branches, space: toggle staged, c: commit changes, o: open, s: open in sublime, i: ignore"
|
||||
baseString := "tab: next panel, S: stash files, space: toggle staged, c: commit changes, o: open, s: open in sublime, i: ignore"
|
||||
item, err := getSelectedFile(v)
|
||||
if err != nil {
|
||||
if err != ErrNoFiles {
|
||||
@ -103,15 +103,33 @@ func handleFileSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
}
|
||||
var optionsString string
|
||||
if item.Tracked {
|
||||
optionsString = baseString + ", r: checkout"
|
||||
optionsString = baseString + ", d: checkout"
|
||||
} else {
|
||||
optionsString = baseString + ", r: delete"
|
||||
optionsString = baseString + ", d: delete"
|
||||
}
|
||||
renderString(g, "options", optionsString)
|
||||
diff := getDiff(item)
|
||||
return renderString(g, "main", diff)
|
||||
}
|
||||
|
||||
func handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||
if len(stagedFiles(state.GitFiles)) == 0 {
|
||||
return createErrorPanel(g, "There are no staged files to commit")
|
||||
}
|
||||
createPromptPanel(g, filesView, "Commit message", func(g *gocui.Gui, v *gocui.View) error {
|
||||
message := trimmedContent(v)
|
||||
if message == "" {
|
||||
return createErrorPanel(g, "You cannot commit without a commit message")
|
||||
}
|
||||
if err := gitCommit(message); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
refreshFiles(g)
|
||||
return refreshCommits(g)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func genericFileOpen(g *gocui.Gui, v *gocui.View, open func(string) (string, error)) error {
|
||||
file, err := getSelectedFile(v)
|
||||
if err != nil {
|
||||
@ -155,7 +173,9 @@ func refreshFiles(g *gocui.Gui) error {
|
||||
}
|
||||
}
|
||||
correctCursor(filesView)
|
||||
handleFileSelect(g, filesView)
|
||||
if filesView == g.CurrentView() {
|
||||
handleFileSelect(g, filesView)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -164,7 +184,7 @@ func pullFiles(g *gocui.Gui, v *gocui.View) error {
|
||||
createSimpleConfirmationPanel(g, v, "", "Pulling...")
|
||||
go func() {
|
||||
if output, err := gitPull(); err != nil {
|
||||
createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
createErrorPanel(g, output)
|
||||
} else {
|
||||
closeConfirmationPrompt(g)
|
||||
refreshCommits(g)
|
||||
@ -181,7 +201,7 @@ func pushFiles(g *gocui.Gui, v *gocui.View) error {
|
||||
createSimpleConfirmationPanel(g, v, "", "Pushing...")
|
||||
go func() {
|
||||
if output, err := gitPush(); err != nil {
|
||||
createSimpleConfirmationPanel(g, v, "Error", output)
|
||||
createErrorPanel(g, output)
|
||||
} else {
|
||||
closeConfirmationPrompt(g)
|
||||
refreshCommits(g)
|
||||
|
Loading…
Reference in New Issue
Block a user