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). 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: 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 ### Ubuntu
Packages for Ubuntu 14.04 and up are available via Launchpad PPA. Packages for Ubuntu 14.04 and up are available via Launchpad PPA.
@ -54,6 +53,7 @@ sudo apt-get install lazygit
- [ ] Configurable Keybindings - [ ] Configurable Keybindings
- [ ] Configurable Color Themes - [ ] Configurable Color Themes
- [ ] Spawning Subprocesses (help needed - have a look at https://github.com/jesseduffield/lazygit/pull/18) - [ ] Spawning Subprocesses (help needed - have a look at https://github.com/jesseduffield/lazygit/pull/18)
- [ ] Performance
- [ ] i18n - [ ] i18n
## Contributing ## Contributing

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"strings"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
) )
@ -90,7 +91,10 @@ func handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
} }
go func() { go func() {
branch := getSelectedBranch(v) 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) renderString(g, "main", diff)
}() }()
return nil return nil

View File

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

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"runtime"
"strings" "strings"
"time" "time"
@ -111,12 +112,20 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile {
return result return result
} }
func platformShell() (string, string) {
if runtime.GOOS == "windows" {
return "cmd", "/c"
}
return "sh", "-c"
}
func runDirectCommand(command string) (string, error) { func runDirectCommand(command string) (string, error) {
timeStart := time.Now() timeStart := time.Now()
commandLog(command) commandLog(command)
shell, shellArg := platformShell()
cmdOut, err := exec. cmdOut, err := exec.
Command("bash", "-c", command). Command(shell, shellArg, command).
CombinedOutput() CombinedOutput()
devLog("run direct command time for command: ", command, time.Now().Sub(timeStart)) devLog("run direct command time for command: ", command, time.Now().Sub(timeStart))
return sanitisedCommandOutput(cmdOut, err) return sanitisedCommandOutput(cmdOut, err)
@ -174,7 +183,7 @@ func branchFromLine(line string, index int) Branch {
func getGitBranches() []Branch { func getGitBranches() []Branch {
branches := make([]Branch, 0) branches := make([]Branch, 0)
// check if there are any branches // check if there are any branches
branchCheck, _ := runDirectCommand("git branch") branchCheck, _ := runCommand("git branch")
if branchCheck == "" { if branchCheck == "" {
return append(branches, branchFromLine("master", 0)) 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. // 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 // Worth mentioning this has nothing to do with the 'git merge' operation
func getAndMergeFetchedBranches(branches []Branch) []Branch { 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) branchLines := splitLines(rawString)
for _, line := range branchLines { for _, line := range branchLines {
line = strings.Replace(line, "* ", "", -1)
line = strings.TrimSpace(line)
if branchAlreadyStored(line, branches) { if branchAlreadyStored(line, branches) {
continue continue
} }
@ -561,11 +575,3 @@ git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
| tr -d ' ' | 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`

5
gui.go
View File

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