diff --git a/README.md b/README.md new file mode 100644 index 000000000..35411b7e1 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# lazygit +simple terminal UI for git commands + + +![Gif](https://image.ibb.co/nxyY58/shortone.gif) diff --git a/branches_panel.go b/branches_panel.go index 8000da2a9..4060b670a 100644 --- a/branches_panel.go +++ b/branches_panel.go @@ -24,6 +24,16 @@ func handleForceCheckout(g *gocui.Gui, v *gocui.View) error { }, nil) } +func handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { + createPromptPanel(g, v, "Branch Name:", func(g *gocui.Gui, v *gocui.View) error { + if output, err := gitCheckout(trimmedContent(v), false); err != nil { + return createErrorPanel(g, output) + } + return refreshSidePanels(g) + }) + return nil +} + func handleNewBranch(g *gocui.Gui, v *gocui.View) error { branch := state.Branches[0] createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", func(g *gocui.Gui, v *gocui.View) error { @@ -31,7 +41,7 @@ func handleNewBranch(g *gocui.Gui, v *gocui.View) error { return createErrorPanel(g, output) } refreshSidePanels(g) - return handleCommitSelect(g, v) + return handleBranchSelect(g, v) }) return nil } @@ -59,6 +69,7 @@ func renderBranchesOptions(g *gocui.Gui) error { "space": "checkout", "f": "force checkout", "m": "merge", + "c": "checkout by name", }) } diff --git a/gitcommands.go b/gitcommands.go index 6c01aa889..091a638f8 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -165,7 +165,14 @@ func getGitBranches() []Branch { return branches } rawString, _ := runDirectCommand(getBranchesCommand) - for i, line := range splitLines(rawString) { + branchLines := splitLines(rawString) + if len(branchLines) == 0 { + // sometimes the getBranchesCommand command returns nothing, in which case + // we assume you've just init'd or cloned the repo and you've got master + // checked out + branches = append(branches, branchFromLine(" *\tmaster", 0)) + } + for i, line := range branchLines { branches = append(branches, branchFromLine(line, i)) } return branches diff --git a/gui.go b/gui.go index 314bf3960..01ae7640f 100644 --- a/gui.go +++ b/gui.go @@ -146,6 +146,9 @@ func keybindings(g *gocui.Gui) error { if err := g.SetKeybinding("branches", gocui.KeySpace, gocui.ModNone, handleBranchPress); err != nil { return err } + if err := g.SetKeybinding("branches", 'c', gocui.ModNone, handleCheckoutByName); err != nil { + return err + } if err := g.SetKeybinding("branches", 'F', gocui.ModNone, handleForceCheckout); err != nil { return err }