1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

More stuff

This commit is contained in:
Jesse Duffield 2018-05-26 15:44:44 +10:00
parent bb12309c7c
commit 10fd353a50
3 changed files with 85 additions and 0 deletions

72
branches_panel.go Normal file
View File

@ -0,0 +1,72 @@
// lots of this has been directly ported from one of the example files, will brush up later
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
// "io"
// "io/ioutil"
// "strings"
"github.com/fatih/color"
"github.com/jroimartin/gocui"
)
func handleBranchPress(g *gocui.Gui, v *gocui.View) error {
branch := getSelectedBranch(v)
if err := gitCheckout(branch.Name, false); err != nil {
panic(err)
}
refreshBranches(v)
refreshFiles(g)
refreshLogs(g)
return nil
}
func getSelectedBranch(v *gocui.View) Branch {
lineNumber := getItemPosition(v)
return state.Branches[lineNumber]
}
func handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
renderString(g, "options", "space: checkout")
lineNumber := getItemPosition(v)
branch := state.Branches[lineNumber]
diff, _ := getBranchDiff(branch.Name, branch.BaseBranch)
if err := renderString(g, "main", diff); err != nil {
return err
}
return nil
}
func refreshBranches(v *gocui.View) error {
state.Branches = getGitBranches()
yellow := color.New(color.FgYellow)
red := color.New(color.FgRed)
white := color.New(color.FgWhite)
green := color.New(color.FgGreen)
v.Clear()
for _, branch := range state.Branches {
if branch.Type == "feature" {
green.Fprintln(v, branch.DisplayString)
continue
}
if branch.Type == "bugfix" {
yellow.Fprintln(v, branch.DisplayString)
continue
}
if branch.Type == "hotfix" {
red.Fprintln(v, branch.DisplayString)
continue
}
white.Fprintln(v, branch.DisplayString)
}
resetOrigin(v)
return nil
}

View File

@ -134,3 +134,11 @@ func refreshFiles(g *gocui.Gui) error {
correctCursor(filesView)
return nil
}
func pullFiles(g *gocui.Gui, v *gocui.Gui) error {
if err := gitPull(); err != nil {
// should show error
panic(err)
}
return refreshFiles(g)
}

View File

@ -245,6 +245,11 @@ func gitCommit(message string) error {
return err
}
func gitPull() error {
_, err := runDirectCommand("git pull --no-edit")
return err
}
const getBranchesCommand = `set -e
git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
seen=":"