summaryrefslogtreecommitdiffstats
path: root/pkg/gui/files_panel.go
diff options
context:
space:
mode:
authorMarius Bergmann <marius@yeai.de>2021-12-05 22:52:26 +0100
committerJesse Duffield <jessedduffield@gmail.com>2021-12-26 15:47:58 +1100
commit38743ec99fafb6b093c1f5d117c9bcaa708dbcde (patch)
treea461a64b79ed3fd9543099be5276db5f4c3ce669 /pkg/gui/files_panel.go
parent630de34bf21658b9447af39bc9c6d752b2b1e921 (diff)
Suggest existing remote for non-tracking branch
Currently, when pushing or pulling a branch that has no tracking remote, lazygit suggests the (hard-coded) remote named 'origin'. However, a repository might not have a remote with this name, in which case the suggestion makes no sense. This happens to me quite regularly when I choose a more meaningful name than 'origin' for a remote. This change keeps the current behavior by suggesting 'origin' when there is either a remote with that name or no remote at all. However, when 'origin' does not exist, the name of the first remote is suggested. Suggest existing remote for non-tracking branch Currently, when pushing or pulling a branch that has no tracking remote, lazygit suggests the (hard-coded) remote named 'origin'. However, a repository might not have a remote with this name, in which case the suggestion makes no sense. This happens to me quite regularly when I choose a more meaningful name than 'origin' for a remote. This change keeps the current behavior by suggesting 'origin' when there is either a remote with that name or no remote at all. However, when 'origin' does not exist, the name of the first existing remote is suggested.
Diffstat (limited to 'pkg/gui/files_panel.go')
-rw-r--r--pkg/gui/files_panel.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 3bc600420..a0e71bc20 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -660,9 +660,11 @@ func (gui *Gui) handlePullFiles() error {
}
}
+ suggestedRemote := getSuggestedRemote(gui.State.Remotes)
+
return gui.prompt(promptOpts{
title: gui.Tr.EnterUpstream,
- initialContent: "origin/" + currentBranch.Name,
+ initialContent: suggestedRemote + "/" + currentBranch.Name,
findSuggestionsFunc: gui.getRemoteBranchesSuggestionsFunc("/"),
handleConfirm: func(upstream string) error {
if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil {
@@ -797,12 +799,14 @@ func (gui *Gui) pushFiles() error {
)
}
+ suggestedRemote := getSuggestedRemote(gui.State.Remotes)
+
if gui.GitCommand.PushToCurrent {
return gui.push(pushOpts{setUpstream: true})
} else {
return gui.prompt(promptOpts{
title: gui.Tr.EnterUpstream,
- initialContent: "origin " + currentBranch.Name,
+ initialContent: suggestedRemote + " " + currentBranch.Name,
findSuggestionsFunc: gui.getRemoteBranchesSuggestionsFunc(" "),
handleConfirm: func(upstream string) error {
var upstreamBranch, upstreamRemote string
@@ -827,6 +831,20 @@ func (gui *Gui) pushFiles() error {
}
}
+func getSuggestedRemote(remotes []*models.Remote) string {
+ if len(remotes) == 0 {
+ return "origin"
+ }
+
+ for _, remote := range remotes {
+ if remote.Name == "origin" {
+ return remote.Name
+ }
+ }
+
+ return remotes[0].Name
+}
+
func (gui *Gui) requestToForcePush() error {
forcePushDisabled := gui.Config.GetUserConfig().Git.DisableForcePushing
if forcePushDisabled {