summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-13 22:14:57 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-13 22:25:42 +1100
commit3b1d705473494cca9894ec051d9d928c0c8926c7 (patch)
tree8e6661248e5ab7aced0aee0f68995bb1f57ee398
parentf43ba728e3206b354d8cb66470fa2a42300c01a8 (diff)
show upstream branch for branch
-rw-r--r--pkg/commands/git.go5
-rw-r--r--pkg/gui/branches_panel.go8
-rw-r--r--pkg/i18n/english.go3
3 files changed, 15 insertions, 1 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 145b188fe..ad275d10f 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -530,6 +530,11 @@ func (c *GitCommand) GetBranchGraph(branchName string) (string, error) {
return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git log --graph --color --abbrev-commit --decorate --date=relative --pretty=medium -100 %s", branchName))
}
+func (c *GitCommand) GetUpstreamForBranch(branchName string) (string, error) {
+ output, err := c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git rev-parse --abbrev-ref --symbolic-full-name %s@{u}", branchName))
+ return strings.TrimSpace(output), err
+}
+
// Ignore adds a file to the gitignore for the repo
func (c *GitCommand) Ignore(filename string) error {
return c.OSCommand.AppendLineToFile(".gitignore", filename)
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 23aa17a26..adea31072 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -4,8 +4,10 @@ import (
"fmt"
"strings"
+ "github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/utils"
)
// list panel functions
@@ -53,11 +55,15 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
_ = gui.RenderSelectedBranchUpstreamDifferences()
}()
go func() {
+ upstream, _ := gui.GitCommand.GetUpstreamForBranch(branch.Name)
+ if strings.Contains(upstream, "no upstream configured for branch") {
+ upstream = gui.Tr.SLocalize("notTrackingRemote")
+ }
graph, err := gui.GitCommand.GetBranchGraph(branch.Name)
if err != nil && strings.HasPrefix(graph, "fatal: ambiguous argument") {
graph = gui.Tr.SLocalize("NoTrackingThisBranch")
}
- _ = gui.renderString(g, "main", graph)
+ _ = gui.renderString(g, "main", fmt.Sprintf("%s → %s\n\n%s", utils.ColoredString(branch.Name, color.FgGreen), utils.ColoredString(upstream, color.FgRed), graph))
}()
return nil
}
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 9610a578a..b15f60bbb 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -840,6 +840,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "EnterUpstreamWithSlash",
Other: `Enter upstream as '<remote>/<branchname>'`,
+ }, &i18n.Message{
+ ID: "notTrackingRemote",
+ Other: "(not tracking any remote)",
},
)
}