summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorDavid Chen <weichen2000121@gmail.com>2020-01-07 09:57:06 -0800
committerGitHub <noreply@github.com>2020-01-07 09:57:06 -0800
commit844a2db83af5b23411ee5794033a1b8baeb97af0 (patch)
tree216b05fa42f26c4cfbcc4d1421511981fbeaab1e /pkg/gui
parent529ba45cc74c9f777c0589fa85b4a5f3ee109402 (diff)
parent09aabce3cd38312e854fdbb29046acba42a67f38 (diff)
Merge branch 'master' into custom-keybindings
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/branches_panel.go13
-rw-r--r--pkg/gui/commits_panel.go11
-rw-r--r--pkg/gui/files_panel.go13
-rw-r--r--pkg/gui/gui.go4
-rw-r--r--pkg/gui/keybindings.go7
-rw-r--r--pkg/gui/remote_branches_panel.go2
-rw-r--r--pkg/gui/tags_panel.go2
7 files changed, 41 insertions, 11 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index f78d86ab8..985be932e 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -128,7 +128,7 @@ func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(g, gui.Tr.SLocalize("AlreadyCheckedOutBranch"))
}
branch := gui.getSelectedBranch()
- return gui.handleCheckoutBranch(branch.Name)
+ return gui.handleCheckoutRef(branch.Name)
}
func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error {
@@ -165,17 +165,17 @@ func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
}, nil)
}
-func (gui *Gui) handleCheckoutBranch(branchName string) error {
- if err := gui.GitCommand.Checkout(branchName, false); err != nil {
+func (gui *Gui) handleCheckoutRef(ref string) error {
+ if err := gui.GitCommand.Checkout(ref, false); err != nil {
// note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
if strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch") {
// offer to autostash changes
return gui.createConfirmationPanel(gui.g, gui.getBranchesView(), true, gui.Tr.SLocalize("AutoStashTitle"), gui.Tr.SLocalize("AutoStashPrompt"), func(g *gocui.Gui, v *gocui.View) error {
- if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + branchName); err != nil {
+ if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + ref); err != nil {
return gui.createErrorPanel(g, err.Error())
}
- if err := gui.GitCommand.Checkout(branchName, false); err != nil {
+ if err := gui.GitCommand.Checkout(ref, false); err != nil {
return gui.createErrorPanel(g, err.Error())
}
@@ -198,12 +198,13 @@ func (gui *Gui) handleCheckoutBranch(branchName string) error {
}
gui.State.Panels.Branches.SelectedLine = 0
+ gui.State.Panels.Commits.SelectedLine = 0
return gui.refreshSidePanels(gui.g)
}
func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error {
gui.createPromptPanel(g, v, gui.Tr.SLocalize("BranchName")+":", "", func(g *gocui.Gui, v *gocui.View) error {
- return gui.handleCheckoutBranch(gui.trimmedContent(v))
+ return gui.handleCheckoutRef(gui.trimmedContent(v))
})
return nil
}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 22ea6fe7e..3f82584c1 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -611,3 +611,14 @@ func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
return gui.handleCommitSelect(g, v)
})
}
+
+func (gui *Gui) handleCheckoutCommit(g *gocui.Gui, v *gocui.View) error {
+ commit := gui.getSelectedCommit(g)
+ if commit == nil {
+ return gui.renderString(g, "main", gui.Tr.SLocalize("NoCommitsThisBranch"))
+ }
+
+ return gui.createConfirmationPanel(g, gui.getCommitsView(), true, gui.Tr.SLocalize("checkoutCommit"), gui.Tr.SLocalize("SureCheckoutThisCommit"), func(g *gocui.Gui, v *gocui.View) error {
+ return gui.handleCheckoutRef(commit.Sha)
+ }, nil)
+}
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 463db817e..aa2e8592e 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -604,14 +604,21 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error {
description: gui.Tr.SLocalize("softReset"),
command: "git reset --soft HEAD",
handler: func() error {
- return gui.GitCommand.ResetSoftHead()
+ return gui.GitCommand.ResetSoft("HEAD")
},
},
{
description: gui.Tr.SLocalize("hardReset"),
command: "git reset --hard HEAD",
handler: func() error {
- return gui.GitCommand.ResetHardHead()
+ return gui.GitCommand.ResetHard("HEAD")
+ },
+ },
+ {
+ description: gui.Tr.SLocalize("hardResetUpstream"),
+ command: "git reset --hard @{upstream}",
+ handler: func() error {
+ return gui.GitCommand.ResetHard("@{upstream}")
},
},
{
@@ -624,7 +631,7 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error {
handleMenuPress := func(index int) error {
if err := options[index].handler(); err != nil {
- return err
+ return gui.createErrorPanel(gui.g, err.Error())
}
return gui.refreshFiles()
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index ba379fc56..5b2f9cc14 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"math"
"os"
+ "runtime"
"sync"
// "io"
@@ -28,6 +29,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/updates"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/mattn/go-runewidth"
"github.com/sirupsen/logrus"
)
@@ -782,6 +784,8 @@ func (gui *Gui) Run() error {
}
defer g.Close()
+ g.ASCII = runtime.GOOS == "windows" && runewidth.IsEastAsian()
+
if gui.Config.GetUserConfig().GetBool("gui.mouseEvents") {
g.Mouse = true
}
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 032281608..dade5aa51 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -718,6 +718,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "commits",
Key: gui.getKey("universal.select"),
Modifier: gocui.ModNone,
+ Handler: gui.handleCheckoutCommit,
+ Description: gui.Tr.SLocalize("checkoutCommit"),
+ },
+ {
+ ViewName: "commits",
+ Key: 'h',
+ Modifier: gocui.ModNone,
Handler: gui.handleToggleDiffCommit,
Description: gui.Tr.SLocalize("CommitsDiff"),
},
diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go
index af9835999..2de045e4d 100644
--- a/pkg/gui/remote_branches_panel.go
+++ b/pkg/gui/remote_branches_panel.go
@@ -79,7 +79,7 @@ func (gui *Gui) handleCheckoutRemoteBranch(g *gocui.Gui, v *gocui.View) error {
if remoteBranch == nil {
return nil
}
- if err := gui.handleCheckoutBranch(remoteBranch.RemoteName + "/" + remoteBranch.Name); err != nil {
+ if err := gui.handleCheckoutRef(remoteBranch.RemoteName + "/" + remoteBranch.Name); err != nil {
return err
}
return gui.switchBranchesPanelContext("local-branches")
diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go
index e1f9d364a..e287156ac 100644
--- a/pkg/gui/tags_panel.go
+++ b/pkg/gui/tags_panel.go
@@ -90,7 +90,7 @@ func (gui *Gui) handleCheckoutTag(g *gocui.Gui, v *gocui.View) error {
if tag == nil {
return nil
}
- if err := gui.handleCheckoutBranch(tag.Name); err != nil {
+ if err := gui.handleCheckoutRef(tag.Name); err != nil {
return err
}
return gui.switchBranchesPanelContext("local-branches")