1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-05 15:15:49 +02:00

Merge branch 'master' into feature/use-dep

This commit is contained in:
Jesse Duffield 2018-08-07 17:12:37 +10:00
commit 138f40d7ae
5 changed files with 32 additions and 16 deletions

View File

@ -18,8 +18,7 @@ Then just call `lazygit` in your terminal inside a git repository.
If you want, you can also add an alias for this with `echo "alias lg='lazygit'" >> ~/.zshrc` (or whichever rc file you're using).
Please note:
On MacOS you may have to add `~/go/bin` to your $PATH variable.
On MacOS you may have to add `~/go/bin` to your $PATH variable, or `%HOME%\go\bin` to your %PATH% in Windows
### Ubuntu
Packages for Ubuntu 14.04 and up are available via Launchpad PPA.
@ -54,6 +53,7 @@ sudo apt-get install lazygit
- [ ] Configurable Keybindings
- [ ] Configurable Color Themes
- [ ] Spawning Subprocesses (help needed - have a look at https://github.com/jesseduffield/lazygit/pull/18)
- [ ] Performance
- [ ] i18n
## Contributing

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"strings"
"github.com/jesseduffield/gocui"
)
@ -90,7 +91,10 @@ func handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
}
go func() {
branch := getSelectedBranch(v)
diff, _ := getBranchGraph(branch.Name, branch.BaseBranch)
diff, err := getBranchGraph(branch.Name, branch.BaseBranch)
if err != nil && strings.HasPrefix(diff, "fatal: ambiguous argument") {
diff = "There is no tracking for this branch"
}
renderString(g, "main", diff)
}()
return nil

View File

@ -78,6 +78,9 @@ func getSelectedFile(g *gocui.Gui) (GitFile, error) {
func handleFileRemove(g *gocui.Gui, v *gocui.View) error {
file, err := getSelectedFile(g)
if err != nil {
if err == ErrNoFiles {
return nil
}
return err
}
var deleteVerb string

View File

@ -7,6 +7,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"time"
@ -111,12 +112,20 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile {
return result
}
func platformShell() (string, string) {
if runtime.GOOS == "windows" {
return "cmd", "/c"
}
return "sh", "-c"
}
func runDirectCommand(command string) (string, error) {
timeStart := time.Now()
commandLog(command)
shell, shellArg := platformShell()
cmdOut, err := exec.
Command("bash", "-c", command).
Command(shell, shellArg, command).
CombinedOutput()
devLog("run direct command time for command: ", command, time.Now().Sub(timeStart))
return sanitisedCommandOutput(cmdOut, err)
@ -174,7 +183,7 @@ func branchFromLine(line string, index int) Branch {
func getGitBranches() []Branch {
branches := make([]Branch, 0)
// check if there are any branches
branchCheck, _ := runDirectCommand("git branch")
branchCheck, _ := runCommand("git branch")
if branchCheck == "" {
return append(branches, branchFromLine("master", 0))
}
@ -205,9 +214,14 @@ func branchAlreadyStored(branchLine string, branches []Branch) bool {
// directory i.e. things we've fetched but haven't necessarily checked out.
// Worth mentioning this has nothing to do with the 'git merge' operation
func getAndMergeFetchedBranches(branches []Branch) []Branch {
rawString, _ := runDirectCommand(getHeadsCommand)
rawString, err := runDirectCommand("git branch --sort=-committerdate --no-color")
if err != nil {
return branches
}
branchLines := splitLines(rawString)
for _, line := range branchLines {
line = strings.Replace(line, "* ", "", -1)
line = strings.TrimSpace(line)
if branchAlreadyStored(line, branches) {
continue
}
@ -561,11 +575,3 @@ git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
| tr -d ' '
}
`
const getHeadsCommand = `git show-ref \
| grep 'refs/heads/\|refs/remotes/origin/' \
| sed 's/.*refs\/heads\///g' \
| sed 's/.*refs\/remotes\/origin\///g' \
| grep -v '^HEAD$' \
| sort \
| uniq`

3
gui.go
View File

@ -6,6 +6,7 @@ import (
// "io/ioutil"
"log"
"runtime"
"strings"
"time"
@ -136,7 +137,9 @@ func keybindings(g *gocui.Gui) error {
func layout(g *gocui.Gui) error {
g.Highlight = true
g.SelFgColor = gocui.ColorWhite | gocui.AttrBold
if runtime.GOOS != "windows" {
g.FgColor = gocui.ColorBlack
}
width, height := g.Size()
leftSideWidth := width / 3
statusFilesBoundary := 2