From 6985e529493b992d822b0523507c522bd84762e6 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 12:49:31 +1000 Subject: [PATCH 01/11] handle error from git log that arises from lack of tracking --- branches_panel.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/branches_panel.go b/branches_panel.go index 90cb66d8b..0b8508a3d 100644 --- a/branches_panel.go +++ b/branches_panel.go @@ -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 From a4a975a69c8a7459f1dbfabc62f98b00efd142c8 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 12:51:03 +1000 Subject: [PATCH 02/11] don't panic on no files when pressing d --- files_panel.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files_panel.go b/files_panel.go index 50d6b64e2..a69deaa25 100644 --- a/files_panel.go +++ b/files_panel.go @@ -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 From a4f4a1623779704222925031885e389103b975e1 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 13:31:45 +1000 Subject: [PATCH 03/11] fix panel outlines for windows --- gui.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gui.go b/gui.go index 4d883cae5..aac0c82bb 100644 --- a/gui.go +++ b/gui.go @@ -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 - g.FgColor = gocui.ColorBlack + if runtime.GOOS == "windows" { + g.FgColor = gocui.ColorBlack + } width, height := g.Size() leftSideWidth := width / 3 statusFilesBoundary := 2 From 384d2e3c835fde68b5b896632cf4564c7ad51c76 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 13:44:00 +1000 Subject: [PATCH 04/11] use sh instead of bash --- gitcommands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitcommands.go b/gitcommands.go index 71e737a6e..31615a346 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -116,7 +116,7 @@ func runDirectCommand(command string) (string, error) { commandLog(command) cmdOut, err := exec. - Command("bash", "-c", command). + Command("sh", "-c", command). CombinedOutput() devLog("run direct command time for command: ", command, time.Now().Sub(timeStart)) return sanitisedCommandOutput(cmdOut, err) @@ -174,7 +174,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)) } From 28caaf6f1c8ffb0d0d5d6815f95e4c418c2efdf0 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 14:01:41 +1000 Subject: [PATCH 05/11] invert platform check --- gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.go b/gui.go index aac0c82bb..7c5344dd8 100644 --- a/gui.go +++ b/gui.go @@ -137,7 +137,7 @@ 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" { + if runtime.GOOS != "windows" { g.FgColor = gocui.ColorBlack } width, height := g.Size() From ab03902d08a0e5dcf1530714c3e87ed533b10549 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 14:08:56 +1000 Subject: [PATCH 06/11] return on error when merging branches --- gitcommands.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gitcommands.go b/gitcommands.go index 31615a346..2de3cbe9a 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -205,7 +205,10 @@ 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(getHeadsCommand) + if err != nil { + return branches + } branchLines := splitLines(rawString) for _, line := range branchLines { if branchAlreadyStored(line, branches) { From e23ed80eaae8a1fde099bbf3bad46ebcf3797b85 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 14:10:15 +1000 Subject: [PATCH 07/11] use git branch when merging branches --- gitcommands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitcommands.go b/gitcommands.go index 2de3cbe9a..dfb91b914 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -205,7 +205,7 @@ 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, err := runDirectCommand(getHeadsCommand) + rawString, err := runDirectCommand("git branch") if err != nil { return branches } From 46fb4c5f0a968adc6650bfad0ef7a3fdb3568837 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 14:23:10 +1000 Subject: [PATCH 08/11] swap out bash command for a git one --- gitcommands.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/gitcommands.go b/gitcommands.go index dfb91b914..2dce88f8d 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -205,12 +205,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, err := runDirectCommand("git branch") + 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 } @@ -564,11 +566,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` From 948f6a1f7a7ad439b98fa498b13dd26903f8820f Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 14:08:56 +1000 Subject: [PATCH 09/11] return on error when merging branches --- gitcommands.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gitcommands.go b/gitcommands.go index 71e737a6e..122de1401 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -205,7 +205,10 @@ 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(getHeadsCommand) + if err != nil { + return branches + } branchLines := splitLines(rawString) for _, line := range branchLines { if branchAlreadyStored(line, branches) { From a70753364cd3949e419ea0c0a4f73619479a3594 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 15:21:50 +1000 Subject: [PATCH 10/11] platform specific shell usage --- gitcommands.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gitcommands.go b/gitcommands.go index 2dce88f8d..50c1f2a9f 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -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("sh", "-c", command). + Command(shell, shellArg, command). CombinedOutput() devLog("run direct command time for command: ", command, time.Now().Sub(timeStart)) return sanitisedCommandOutput(cmdOut, err) From b80e8111c6f3a1347edd69522aa93bacd6f47af9 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 7 Aug 2018 15:50:56 +1000 Subject: [PATCH 11/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85e9d3e5b..6c85f0992 100644 --- a/README.md +++ b/README.md @@ -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