mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
apply gofmt -s -w
This commit is contained in:
parent
9a3b565806
commit
7b7621c18c
218
commits_panel.go
218
commits_panel.go
@ -1,138 +1,138 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrNoCommits : When no commits are found for the branch
|
// ErrNoCommits : When no commits are found for the branch
|
||||||
ErrNoCommits = errors.New("No commits for this branch")
|
ErrNoCommits = errors.New("No commits for this branch")
|
||||||
)
|
)
|
||||||
|
|
||||||
func refreshCommits(g *gocui.Gui) error {
|
func refreshCommits(g *gocui.Gui) error {
|
||||||
g.Update(func(*gocui.Gui) error {
|
g.Update(func(*gocui.Gui) error {
|
||||||
state.Commits = getCommits()
|
state.Commits = getCommits()
|
||||||
v, err := g.View("commits")
|
v, err := g.View("commits")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
v.Clear()
|
v.Clear()
|
||||||
red := color.New(color.FgRed)
|
red := color.New(color.FgRed)
|
||||||
yellow := color.New(color.FgYellow)
|
yellow := color.New(color.FgYellow)
|
||||||
white := color.New(color.FgWhite)
|
white := color.New(color.FgWhite)
|
||||||
shaColor := white
|
shaColor := white
|
||||||
for _, commit := range state.Commits {
|
for _, commit := range state.Commits {
|
||||||
if commit.Pushed {
|
if commit.Pushed {
|
||||||
shaColor = red
|
shaColor = red
|
||||||
} else {
|
} else {
|
||||||
shaColor = yellow
|
shaColor = yellow
|
||||||
}
|
}
|
||||||
shaColor.Fprint(v, commit.Sha+" ")
|
shaColor.Fprint(v, commit.Sha+" ")
|
||||||
white.Fprintln(v, commit.Name)
|
white.Fprintln(v, commit.Name)
|
||||||
}
|
}
|
||||||
refreshStatus(g)
|
refreshStatus(g)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error {
|
func handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error {
|
||||||
return createConfirmationPanel(g, commitView, "Reset To Commit", "Are you sure you want to reset to this commit?", func(g *gocui.Gui, v *gocui.View) error {
|
return createConfirmationPanel(g, commitView, "Reset To Commit", "Are you sure you want to reset to this commit?", func(g *gocui.Gui, v *gocui.View) error {
|
||||||
commit, err := getSelectedCommit(g)
|
commit, err := getSelectedCommit(g)
|
||||||
devLog(commit)
|
devLog(commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if output, err := gitResetToCommit(commit.Sha); err != nil {
|
if output, err := gitResetToCommit(commit.Sha); err != nil {
|
||||||
return createErrorPanel(g, output)
|
return createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
if err := refreshCommits(g); err != nil {
|
if err := refreshCommits(g); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := refreshFiles(g); err != nil {
|
if err := refreshFiles(g); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
resetOrigin(commitView)
|
resetOrigin(commitView)
|
||||||
return handleCommitSelect(g, nil)
|
return handleCommitSelect(g, nil)
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderCommitsOptions(g *gocui.Gui) error {
|
func renderCommitsOptions(g *gocui.Gui) error {
|
||||||
return renderOptionsMap(g, map[string]string{
|
return renderOptionsMap(g, map[string]string{
|
||||||
"s": "squash down",
|
"s": "squash down",
|
||||||
"r": "rename",
|
"r": "rename",
|
||||||
"g": "reset to this commit",
|
"g": "reset to this commit",
|
||||||
"← → ↑ ↓": "navigate",
|
"← → ↑ ↓": "navigate",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
func handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := renderCommitsOptions(g); err != nil {
|
if err := renderCommitsOptions(g); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commit, err := getSelectedCommit(g)
|
commit, err := getSelectedCommit(g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != ErrNoCommits {
|
if err != ErrNoCommits {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return renderString(g, "main", "No commits for this branch")
|
return renderString(g, "main", "No commits for this branch")
|
||||||
}
|
}
|
||||||
commitText := gitShow(commit.Sha)
|
commitText := gitShow(commit.Sha)
|
||||||
return renderString(g, "main", commitText)
|
return renderString(g, "main", commitText)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error {
|
func handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
if getItemPosition(v) != 0 {
|
if getItemPosition(v) != 0 {
|
||||||
return createErrorPanel(g, "Can only squash topmost commit")
|
return createErrorPanel(g, "Can only squash topmost commit")
|
||||||
}
|
}
|
||||||
if len(state.Commits) == 1 {
|
if len(state.Commits) == 1 {
|
||||||
return createErrorPanel(g, "You have no commits to squash with")
|
return createErrorPanel(g, "You have no commits to squash with")
|
||||||
}
|
}
|
||||||
commit, err := getSelectedCommit(g)
|
commit, err := getSelectedCommit(g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if output, err := gitSquashPreviousTwoCommits(commit.Name); err != nil {
|
if output, err := gitSquashPreviousTwoCommits(commit.Name); err != nil {
|
||||||
return createErrorPanel(g, output)
|
return createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
if err := refreshCommits(g); err != nil {
|
if err := refreshCommits(g); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
refreshStatus(g)
|
refreshStatus(g)
|
||||||
return handleCommitSelect(g, v)
|
return handleCommitSelect(g, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
|
func handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
|
||||||
if getItemPosition(v) != 0 {
|
if getItemPosition(v) != 0 {
|
||||||
return createErrorPanel(g, "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 {
|
createPromptPanel(g, v, "Rename Commit", func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if output, err := gitRenameCommit(v.Buffer()); err != nil {
|
if output, err := gitRenameCommit(v.Buffer()); err != nil {
|
||||||
return createErrorPanel(g, output)
|
return createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
if err := refreshCommits(g); err != nil {
|
if err := refreshCommits(g); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return handleCommitSelect(g, v)
|
return handleCommitSelect(g, v)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSelectedCommit(g *gocui.Gui) (Commit, error) {
|
func getSelectedCommit(g *gocui.Gui) (Commit, error) {
|
||||||
v, err := g.View("commits")
|
v, err := g.View("commits")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if len(state.Commits) == 0 {
|
if len(state.Commits) == 0 {
|
||||||
return Commit{}, ErrNoCommits
|
return Commit{}, ErrNoCommits
|
||||||
}
|
}
|
||||||
lineNumber := getItemPosition(v)
|
lineNumber := getItemPosition(v)
|
||||||
if lineNumber > len(state.Commits)-1 {
|
if lineNumber > len(state.Commits)-1 {
|
||||||
colorLog(color.FgRed, "potential error in getSelected Commit (mismatched ui and state)", state.Commits, lineNumber)
|
colorLog(color.FgRed, "potential error in getSelected Commit (mismatched ui and state)", state.Commits, lineNumber)
|
||||||
return state.Commits[len(state.Commits)-1], nil
|
return state.Commits[len(state.Commits)-1], nil
|
||||||
}
|
}
|
||||||
return state.Commits[lineNumber], nil
|
return state.Commits[lineNumber], nil
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,43 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
func refreshStatus(g *gocui.Gui) error {
|
func refreshStatus(g *gocui.Gui) error {
|
||||||
v, err := g.View("status")
|
v, err := g.View("status")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// for some reason if this isn't wrapped in an update the clear seems to
|
// for some reason if this isn't wrapped in an update the clear seems to
|
||||||
// be applied after the other things or something like that; the panel's
|
// be applied after the other things or something like that; the panel's
|
||||||
// contents end up cleared
|
// contents end up cleared
|
||||||
g.Update(func(*gocui.Gui) error {
|
g.Update(func(*gocui.Gui) error {
|
||||||
v.Clear()
|
v.Clear()
|
||||||
pushables, pullables := gitUpstreamDifferenceCount()
|
pushables, pullables := gitUpstreamDifferenceCount()
|
||||||
fmt.Fprint(v, "↑"+pushables+"↓"+pullables)
|
fmt.Fprint(v, "↑"+pushables+"↓"+pullables)
|
||||||
branches := state.Branches
|
branches := state.Branches
|
||||||
if err := updateHasMergeConflictStatus(); err != nil {
|
if err := updateHasMergeConflictStatus(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if state.HasMergeConflicts {
|
if state.HasMergeConflicts {
|
||||||
colour := color.New(color.FgYellow)
|
colour := color.New(color.FgYellow)
|
||||||
fmt.Fprint(v, coloredString(" (merging)", colour))
|
fmt.Fprint(v, coloredString(" (merging)", colour))
|
||||||
}
|
}
|
||||||
if len(branches) == 0 {
|
if len(branches) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
branch := branches[0]
|
branch := branches[0]
|
||||||
// utilising the fact these all have padding to only grab the name
|
// utilising the fact these all have padding to only grab the name
|
||||||
// from the display string with the existing coloring applied
|
// from the display string with the existing coloring applied
|
||||||
fmt.Fprint(v, " "+branch.DisplayString[4:])
|
fmt.Fprint(v, " "+branch.DisplayString[4:])
|
||||||
colorLog(color.FgCyan, time.Now().Sub(startTime))
|
colorLog(color.FgCyan, time.Now().Sub(startTime))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user