diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-05-15 21:26:02 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-05-15 21:41:23 +1000 |
commit | 1c259f69f670a7d910b85065aa630223f50bf796 (patch) | |
tree | 029244ce31053df2851acd6ae62a34ed2cc10f19 | |
parent | 913f17ee3e2c74dac354005d0ee446ae4a6eab52 (diff) |
check if user has configured to push to current by default
-rw-r--r-- | pkg/commands/git.go | 13 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 10 |
2 files changed, 20 insertions, 3 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 94234cab3..f7e004108 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -85,6 +85,9 @@ type GitCommand struct { DotGitDir string onSuccessfulContinue func() error PatchManager *PatchManager + + // Push to current determines whether the user has configured to push to the remote branch of the same name as the current or not + PushToCurrent bool } // NewGitCommand it runs git commands @@ -92,6 +95,15 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer, var worktree *gogit.Worktree var repo *gogit.Repository + // see what our default push behaviour is + output, err := osCommand.RunCommandWithOutput("git config --get push.default") + pushToCurrent := false + if err != nil { + log.Errorf("error reading git config: %v", err) + } else { + pushToCurrent = strings.TrimSpace(output) == "current" + } + fs := []func() error{ func() error { return verifyInGitRepo(osCommand.RunCommand) @@ -128,6 +140,7 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer, getLocalGitConfig: gitconfig.Local, removeFile: os.RemoveAll, DotGitDir: dotGitDir, + PushToCurrent: pushToCurrent, } gitCommand.PatchManager = NewPatchManager(log, gitCommand.ApplyPatch) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 36665fe3c..2500fdf97 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -497,9 +497,13 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { } } - return gui.createPromptPanel(g, v, gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranch.Name, func(g *gocui.Gui, v *gocui.View) error { - return gui.pushWithForceFlag(g, v, false, gui.trimmedContent(v), "") - }) + if gui.GitCommand.PushToCurrent { + return gui.pushWithForceFlag(g, v, false, "", "--set-upstream") + } else { + return gui.createPromptPanel(g, v, gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranch.Name, func(g *gocui.Gui, v *gocui.View) error { + return gui.pushWithForceFlag(g, v, false, gui.trimmedContent(v), "") + }) + } } else if currentBranch.Pullables == "0" { return gui.pushWithForceFlag(g, v, false, "", "") } |