From c4b958e3fddc0b50900def5b32f9ff4246d22a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Wed, 13 Apr 2022 15:21:01 +0200 Subject: [PATCH] There's gotta be a better way for initial content --- pkg/gui/controllers/branches_controller.go | 2 +- .../controllers/helpers/upstream_helper.go | 20 ++++++++++++++----- pkg/gui/controllers/sync_controller.go | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 4bf439f1c..66187e36a 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -123,7 +123,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error { DisplayStrings: []string{self.c.Tr.LcSetUpstream}, OnPress: func() error { - return self.helpers.Upstream.PromptForUpstream(selectedBranch, func(upstream string) error { + return self.helpers.Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error { upstreamRemote, upstreamBranch, err := self.helpers.Upstream.ParseUpstream(upstream) if err != nil { return self.c.Error(err) diff --git a/pkg/gui/controllers/helpers/upstream_helper.go b/pkg/gui/controllers/helpers/upstream_helper.go index a0307a9d4..a3ece704e 100644 --- a/pkg/gui/controllers/helpers/upstream_helper.go +++ b/pkg/gui/controllers/helpers/upstream_helper.go @@ -17,7 +17,8 @@ type UpstreamHelper struct { type IUpstreamHelper interface { ParseUpstream(string) (string, string, error) - PromptForUpstream(*models.Branch, func(string) error) error + PromptForUpstreamWithInitialContent(*models.Branch, func(string) error) error + PromptForUpstreamWithoutInitialContent(*models.Branch, func(string) error) error GetSuggestedRemote() string } @@ -48,17 +49,26 @@ func (self *UpstreamHelper) ParseUpstream(upstream string) (string, string, erro return upstreamRemote, upstreamBranch, nil } -func (self *UpstreamHelper) PromptForUpstream(currentBranch *models.Branch, onConfirm func(string) error) error { - suggestedRemote := self.GetSuggestedRemote() - +func (self *UpstreamHelper) promptForUpstream(currentBranch *models.Branch, initialContent string, onConfirm func(string) error) error { return self.c.Prompt(types.PromptOpts{ Title: self.c.Tr.EnterUpstream, - InitialContent: suggestedRemote + " " + currentBranch.Name, + InitialContent: initialContent, FindSuggestionsFunc: self.getRemoteBranchesSuggestionsFunc(" "), HandleConfirm: onConfirm, }) } +func (self *UpstreamHelper) PromptForUpstreamWithInitialContent(currentBranch *models.Branch, onConfirm func(string) error) error { + suggestedRemote := self.GetSuggestedRemote() + initialContent := suggestedRemote + " " + currentBranch.Name + + return self.promptForUpstream(currentBranch, initialContent, onConfirm) +} + +func (self *UpstreamHelper) PromptForUpstreamWithoutInitialContent(currentBranch *models.Branch, onConfirm func(string) error) error { + return self.promptForUpstream(currentBranch, "", onConfirm) +} + func (self *UpstreamHelper) GetSuggestedRemote() string { return getSuggestedRemote(self.model.Remotes) } diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index 046edb369..9eb4ae16a 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -79,7 +79,7 @@ func (self *SyncController) push(currentBranch *models.Branch) error { if self.git.Config.GetPushToCurrent() { return self.pushAux(pushOpts{setUpstream: true}) } else { - return self.helpers.Upstream.PromptForUpstream(currentBranch, func(upstream string) error { + return self.helpers.Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error { upstreamRemote, upstreamBranch, err := self.helpers.Upstream.ParseUpstream(upstream) if err != nil { return self.c.Error(err) @@ -100,7 +100,7 @@ func (self *SyncController) pull(currentBranch *models.Branch) error { // if we have no upstream branch we need to set that first if !currentBranch.IsTrackingRemote() { - return self.helpers.Upstream.PromptForUpstream(currentBranch, func(upstream string) error { + return self.helpers.Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error { if err := self.setCurrentBranchUpstream(upstream); err != nil { return self.c.Error(err) }