feat: indicate new upstream branch will be created on push

When pushing a branch with no upstream configured yet, the prompt
title now notes that a new remote-tracking branch will be created.
Pull paths keep the existing neutral title since they only link to
an already-existing remote branch.
This commit is contained in:
Trương Duy Khánh 2026-08-26 10:14:33 +07:00
parent 1f51ab4715
commit 4aa1e7015b
4 changed files with 16 additions and 9 deletions

View file

@ -440,7 +440,7 @@ func (self *BranchesController) press(selectedBranch *models.Branch) error {
}
func (self *BranchesController) push(branch *models.Branch) error {
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(branch, func(upstream string) error {
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(branch, true, func(upstream string) error {
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
if err != nil {
return err

View file

@ -37,9 +37,14 @@ func (self *UpstreamHelper) ParseUpstream(upstream string) (string, string, erro
return upstreamRemote, upstreamBranch, nil
}
func (self *UpstreamHelper) promptForUpstream(initialContent string, onConfirm func(string) error) error {
func (self *UpstreamHelper) promptForUpstream(initialContent string, isPush bool, onConfirm func(string) error) error {
title := self.c.Tr.EnterUpstream
if isPush {
title = self.c.Tr.EnterUpstreamNewBranch
}
self.c.Prompt(types.PromptOpts{
Title: self.c.Tr.EnterUpstream,
Title: title,
InitialContent: initialContent,
FindSuggestionsFunc: self.getRemoteBranchesSuggestionsFunc(" "),
HandleConfirm: onConfirm,
@ -48,17 +53,17 @@ func (self *UpstreamHelper) promptForUpstream(initialContent string, onConfirm f
return nil
}
func (self *UpstreamHelper) PromptForUpstreamWithInitialContent(currentBranch *models.Branch, onConfirm func(string) error) error {
func (self *UpstreamHelper) PromptForUpstreamWithInitialContent(currentBranch *models.Branch, isPush bool, onConfirm func(string) error) error {
initialContent := currentBranch.UpstreamRemote + " " + currentBranch.UpstreamBranch
if !currentBranch.IsTrackingRemote() {
initialContent = self.GetSuggestedRemote() + " " + currentBranch.Name
}
return self.promptForUpstream(initialContent, onConfirm)
return self.promptForUpstream(initialContent, isPush, onConfirm)
}
func (self *UpstreamHelper) PromptForUpstreamWithoutInitialContent(_ *models.Branch, onConfirm func(string) error) error {
return self.promptForUpstream("", onConfirm)
return self.promptForUpstream("", false, onConfirm)
}
func (self *UpstreamHelper) GetSuggestedRemote() string {

View file

@ -126,7 +126,7 @@ func (self *SyncController) push(currentBranch *models.Branch) error {
return self.pushAux(currentBranch, pushOpts{setUpstream: true})
}
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error {
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, true, func(upstream string) error {
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
if err != nil {
return err
@ -145,7 +145,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.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error {
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, false, func(upstream string) error {
if err := self.setCurrentBranchUpstream(upstream); err != nil {
return err
}
@ -178,7 +178,7 @@ func (self *SyncController) PullBranch(branch *models.Branch, worktree *models.W
}
if !branch.IsTrackingRemote() {
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(branch, func(upstream string) error {
return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(branch, false, func(upstream string) error {
upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream)
if err != nil {
return err

View file

@ -559,6 +559,7 @@ type TranslationSet struct {
ExitCustomPatchBuilder string
ExitFocusedMainView string
EnterUpstream string
EnterUpstreamNewBranch string
InvalidUpstream string
NewRemote string
NewRemoteName string
@ -1731,6 +1732,7 @@ func EnglishTranslationSet() *TranslationSet {
ExitCustomPatchBuilder: `Exit custom patch builder`,
ExitFocusedMainView: "Exit back to side panel",
EnterUpstream: `Enter upstream as '<remote> <branchname>'`,
EnterUpstreamNewBranch: `Enter upstream as '<remote> <branchname>' — new upstream branch will be created`,
InvalidUpstream: "Invalid upstream. Must be in the format '<remote> <branchname>'",
NewRemote: `New remote`,
NewRemoteName: `New remote name:`,