summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-13 21:16:24 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-13 21:36:16 +1100
commitf43ba728e3206b354d8cb66470fa2a42300c01a8 (patch)
treeca07ae1218481cead322d027e30b1f7d5c29a478 /pkg
parentb6623625700e1267f6543fa43a9f0322723ca1e5 (diff)
prompt to set upstream when pulling on untracked branch
prompt to set upstream when pulling on untracked branch
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git.go4
-rw-r--r--pkg/gui/commits_panel.go2
-rw-r--r--pkg/gui/files_panel.go31
-rw-r--r--pkg/gui/keybindings.go2
-rw-r--r--pkg/i18n/english.go3
5 files changed, 37 insertions, 5 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 16b09faa7..145b188fe 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -1052,3 +1052,7 @@ func (c *GitCommand) BeginInteractiveRebaseForCommit(commits []*Commit, commitIn
return nil
}
+
+func (c *GitCommand) SetUpstreamBranch(upstream string) error {
+ return c.OSCommand.RunCommand(fmt.Sprintf("git branch -u %s", upstream))
+}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index a20c52f45..d47394b75 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -405,7 +405,7 @@ func (gui *Gui) handleCommitPick(g *gocui.Gui, v *gocui.View) error {
// at this point we aren't actually rebasing so we will interpret this as an
// attempt to pull. We might revoke this later after enabling configurable keybindings
- return gui.pullFiles(g, v)
+ return gui.handlePullFiles(g, v)
}
func (gui *Gui) handleCommitRevert(g *gocui.Gui, v *gocui.View) error {
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 034860115..56ca123b4 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -408,7 +408,31 @@ func (gui *Gui) catSelectedFile(g *gocui.Gui) (string, error) {
return cat, nil
}
-func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error {
+ // if we have no upstream branch we need to set that first
+ _, pullables := gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount()
+ currentBranchName, err := gui.GitCommand.CurrentBranchName()
+ if err != nil {
+ return err
+ }
+ if pullables == "?" {
+ return gui.createPromptPanel(g, v, gui.Tr.SLocalize("EnterUpstream"), "origin/"+currentBranchName, func(g *gocui.Gui, v *gocui.View) error {
+ upstream := gui.trimmedContent(v)
+ if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil {
+ errorMessage := err.Error()
+ if strings.Contains(errorMessage, "does not exist") {
+ errorMessage = fmt.Sprintf("upstream branch %s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')", upstream)
+ }
+ return gui.createErrorPanel(gui.g, errorMessage)
+ }
+ return gui.pullFiles(v)
+ })
+ }
+
+ return gui.pullFiles(v)
+}
+
+func (gui *Gui) pullFiles(v *gocui.View) error {
if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PullWait")); err != nil {
return err
}
@@ -417,10 +441,11 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error {
unamePassOpend := false
err := gui.GitCommand.Pull(func(passOrUname string) string {
unamePassOpend = true
- return gui.waitForPassUname(g, v, passOrUname)
+ return gui.waitForPassUname(gui.g, v, passOrUname)
})
- gui.HandleCredentialsPopup(g, unamePassOpend, err)
+ gui.HandleCredentialsPopup(gui.g, unamePassOpend, err)
}()
+
return nil
}
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 6b1aec020..5f10965e9 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -136,7 +136,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "",
Key: 'p',
Modifier: gocui.ModNone,
- Handler: gui.pullFiles,
+ Handler: gui.handlePullFiles,
Description: gui.Tr.SLocalize("pull"),
}, {
ViewName: "",
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 347253236..9610a578a 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -837,6 +837,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "EnterUpstream",
Other: `Enter upstream as '<remote> <branchname>'`,
+ }, &i18n.Message{
+ ID: "EnterUpstreamWithSlash",
+ Other: `Enter upstream as '<remote>/<branchname>'`,
},
)
}