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 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 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 diff --git a/gitcommands.go b/gitcommands.go index 71e737a6e..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("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` diff --git a/gui.go b/gui.go index 4d883cae5..7c5344dd8 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