mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
check if user has configured to push to current by default
This commit is contained in:
@ -85,6 +85,9 @@ type GitCommand struct {
|
|||||||
DotGitDir string
|
DotGitDir string
|
||||||
onSuccessfulContinue func() error
|
onSuccessfulContinue func() error
|
||||||
PatchManager *PatchManager
|
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
|
// NewGitCommand it runs git commands
|
||||||
@ -92,6 +95,15 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer,
|
|||||||
var worktree *gogit.Worktree
|
var worktree *gogit.Worktree
|
||||||
var repo *gogit.Repository
|
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{
|
fs := []func() error{
|
||||||
func() error {
|
func() error {
|
||||||
return verifyInGitRepo(osCommand.RunCommand)
|
return verifyInGitRepo(osCommand.RunCommand)
|
||||||
@ -128,6 +140,7 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer,
|
|||||||
getLocalGitConfig: gitconfig.Local,
|
getLocalGitConfig: gitconfig.Local,
|
||||||
removeFile: os.RemoveAll,
|
removeFile: os.RemoveAll,
|
||||||
DotGitDir: dotGitDir,
|
DotGitDir: dotGitDir,
|
||||||
|
PushToCurrent: pushToCurrent,
|
||||||
}
|
}
|
||||||
|
|
||||||
gitCommand.PatchManager = NewPatchManager(log, gitCommand.ApplyPatch)
|
gitCommand.PatchManager = NewPatchManager(log, gitCommand.ApplyPatch)
|
||||||
|
@ -497,9 +497,13 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.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), "")
|
return gui.pushWithForceFlag(g, v, false, gui.trimmedContent(v), "")
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else if currentBranch.Pullables == "0" {
|
} else if currentBranch.Pullables == "0" {
|
||||||
return gui.pushWithForceFlag(g, v, false, "", "")
|
return gui.pushWithForceFlag(g, v, false, "", "")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user