summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-15 14:20:09 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-15 15:34:01 +1100
commit1c84f7731920e1970d52f81361d321268054e559 (patch)
tree077e68eb695b29fdf911f48a83c654b8bfb72f35 /pkg/gui
parent8d8bdb948b089250c22f3ac4f549152a209dcdb2 (diff)
always specify upstream when pushing/pulling
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/branches_panel.go23
-rw-r--r--pkg/gui/confirmation_panel.go2
-rw-r--r--pkg/gui/diffing.go4
-rw-r--r--pkg/gui/files_panel.go83
-rw-r--r--pkg/gui/presentation/branches.go8
5 files changed, 49 insertions, 71 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 880233dc9..feef98431 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -60,7 +60,12 @@ func (gui *Gui) refreshBranches() {
}
}
- gui.State.Branches = gui.Git.Loaders.Branches.Load(reflogCommits)
+ branches, err := gui.Git.Loaders.Branches.Load(reflogCommits)
+ if err != nil {
+ _ = gui.surfaceError(err)
+ }
+
+ gui.State.Branches = branches
if err := gui.postRefreshUpdate(gui.State.Contexts.Branches); err != nil {
gui.Log.Error(err)
@@ -392,25 +397,19 @@ func (gui *Gui) handleFastForward() error {
if !branch.IsTrackingRemote() {
return gui.createErrorPanel(gui.Tr.FwdNoUpstream)
}
+ if !branch.RemoteBranchStoredLocally() {
+ return gui.createErrorPanel(gui.Tr.FwdNoLocalUpstream)
+ }
if branch.HasCommitsToPush() {
return gui.createErrorPanel(gui.Tr.FwdCommitsToPush)
}
- upstream, err := gui.Git.Branch.GetUpstream(branch.Name)
- if err != nil {
- return gui.surfaceError(err)
- }
-
action := gui.Tr.Actions.FastForwardBranch
- split := strings.Split(upstream, "/")
- remoteName := split[0]
- remoteBranchName := strings.Join(split[1:], "/")
-
message := utils.ResolvePlaceholderString(
gui.Tr.Fetching,
map[string]string{
- "from": fmt.Sprintf("%s/%s", remoteName, remoteBranchName),
+ "from": fmt.Sprintf("%s/%s", branch.UpstreamRemote, branch.UpstreamBranch),
"to": branch.Name,
},
)
@@ -421,7 +420,7 @@ func (gui *Gui) handleFastForward() error {
_ = gui.pullWithLock(PullFilesOptions{action: action, FastForwardOnly: true})
} else {
gui.logAction(action)
- err := gui.Git.Sync.FastForward(branch.Name, remoteName, remoteBranchName)
+ err := gui.Git.Sync.FastForward(branch.Name, branch.UpstreamRemote, branch.UpstreamBranch)
gui.handleCredentialsPopup(err)
_ = gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{BRANCHES}})
}
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go
index ecb7d26ac..0537f1b45 100644
--- a/pkg/gui/confirmation_panel.go
+++ b/pkg/gui/confirmation_panel.go
@@ -36,8 +36,8 @@ type askOpts struct {
type promptOpts struct {
title string
initialContent string
- handleConfirm func(string) error
findSuggestionsFunc func(string) []*types.Suggestion
+ handleConfirm func(string) error
}
func (gui *Gui) ask(opts askOpts) error {
diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go
index e3b888066..2721a1880 100644
--- a/pkg/gui/diffing.go
+++ b/pkg/gui/diffing.go
@@ -44,8 +44,8 @@ func (gui *Gui) currentDiffTerminals() []string {
branch := gui.getSelectedBranch()
if branch != nil {
names := []string{branch.ID()}
- if branch.UpstreamName != "" {
- names = append(names, branch.UpstreamName)
+ if branch.IsTrackingRemote() {
+ names = append(names, branch.ID()+"@{u}")
}
return names
}
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index d121c8275..4201afb11 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -655,42 +655,40 @@ func (gui *Gui) handlePullFiles() error {
// if we have no upstream branch we need to set that first
if !currentBranch.IsTrackingRemote() {
- // see if we have this branch in our config with an upstream
- branches, err := gui.Git.Config.Branches()
- if err != nil {
- return gui.surfaceError(err)
- }
- for branchName, branch := range branches {
- if branchName == currentBranch.Name {
- return gui.pullFiles(PullFilesOptions{RemoteName: branch.Remote, BranchName: branch.Name, action: action})
- }
- }
-
suggestedRemote := getSuggestedRemote(gui.State.Remotes)
return gui.prompt(promptOpts{
title: gui.Tr.EnterUpstream,
- initialContent: suggestedRemote + "/" + currentBranch.Name,
- findSuggestionsFunc: gui.getRemoteBranchesSuggestionsFunc("/"),
+ initialContent: suggestedRemote + " " + currentBranch.Name,
+ findSuggestionsFunc: gui.getRemoteBranchesSuggestionsFunc(" "),
handleConfirm: func(upstream string) error {
- if err := gui.Git.Branch.SetCurrentBranchUpstream(upstream); err != nil {
+ var upstreamBranch, upstreamRemote string
+ split := strings.Split(upstream, " ")
+ if len(split) != 2 {
+ return gui.createErrorPanel(gui.Tr.InvalidUpstream)
+ }
+
+ upstreamRemote = split[0]
+ upstreamBranch = split[1]
+
+ if err := gui.Git.Branch.SetCurrentBranchUpstream(upstreamRemote, upstreamBranch); err != nil {
errorMessage := err.Error()
if strings.Contains(errorMessage, "does not exist") {
errorMessage = fmt.Sprintf("upstream branch %s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')", upstream)
}
return gui.createErrorPanel(errorMessage)
}
- return gui.pullFiles(PullFilesOptions{action: action})
+ return gui.pullFiles(PullFilesOptions{UpstreamRemote: upstreamRemote, UpstreamBranch: upstreamBranch, action: action})
},
})
}
- return gui.pullFiles(PullFilesOptions{action: action})
+ return gui.pullFiles(PullFilesOptions{UpstreamRemote: currentBranch.UpstreamRemote, UpstreamBranch: currentBranch.UpstreamBranch, action: action})
}
type PullFilesOptions struct {
- RemoteName string
- BranchName string
+ UpstreamRemote string
+ UpstreamBranch string
FastForwardOnly bool
action string
}
@@ -714,8 +712,8 @@ func (gui *Gui) pullWithLock(opts PullFilesOptions) error {
err := gui.Git.Sync.Pull(
git_commands.PullOptions{
- RemoteName: opts.RemoteName,
- BranchName: opts.BranchName,
+ RemoteName: opts.UpstreamRemote,
+ BranchName: opts.UpstreamBranch,
FastForwardOnly: opts.FastForwardOnly,
},
)
@@ -782,28 +780,18 @@ func (gui *Gui) pushFiles() error {
}
if currentBranch.IsTrackingRemote() {
+ opts := pushOpts{
+ force: false,
+ upstreamRemote: currentBranch.UpstreamRemote,
+ upstreamBranch: currentBranch.UpstreamBranch,
+ }
if currentBranch.HasCommitsToPull() {
- return gui.requestToForcePush()
+ opts.force = true
+ return gui.requestToForcePush(opts)
} else {
- return gui.push(pushOpts{})
+ return gui.push(opts)
}
} else {
- // see if we have an upstream for this branch in our config
- upstreamRemote, upstreamBranch, err := gui.upstreamForBranchInConfig(currentBranch.Name)
- if err != nil {
- return gui.surfaceError(err)
- }
-
- if upstreamBranch != "" {
- return gui.push(
- pushOpts{
- force: false,
- upstreamRemote: upstreamRemote,
- upstreamBranch: upstreamBranch,
- },
- )
- }
-
suggestedRemote := getSuggestedRemote(gui.State.Remotes)
if gui.Git.Config.GetPushToCurrent() {
@@ -850,7 +838,7 @@ func getSuggestedRemote(remotes []*models.Remote) string {
return remotes[0].Name
}
-func (gui *Gui) requestToForcePush() error {
+func (gui *Gui) requestToForcePush(opts pushOpts) error {
forcePushDisabled := gui.UserConfig.Git.DisableForcePushing
if forcePushDisabled {
return gui.createErrorPanel(gui.Tr.ForcePushDisabled)
@@ -860,26 +848,11 @@ func (gui *Gui) requestToForcePush() error {
title: gui.Tr.ForcePush,
prompt: gui.Tr.ForcePushPrompt,
handleConfirm: func() error {
- return gui.push(pushOpts{force: true})
+ return gui.push(opts)
},
})
}
-func (gui *Gui) upstreamForBranchInConfig(branchName string) (string, string, error) {
- branches, err := gui.Git.Config.Branches()
- if err != nil {
- return "", "", err
- }
-
- for configBranchName, configBranch := range branches {
- if configBranchName == branchName {
- return configBranch.Remote, configBranchName, nil
- }
- }
-
- return "", "", nil
-}
-
func (gui *Gui) switchToMerge() error {
file := gui.getSelectedFile()
if file == nil {
diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go
index 9b35b5c3c..c8a613516 100644
--- a/pkg/gui/presentation/branches.go
+++ b/pkg/gui/presentation/branches.go
@@ -43,7 +43,13 @@ func getBranchDisplayStrings(b *models.Branch, fullDescription bool, diffed bool
res := []string{recencyColor.Sprint(b.Recency), coloredName}
if fullDescription {
- return append(res, style.FgYellow.Sprint(b.UpstreamName))
+ return append(
+ res,
+ fmt.Sprintf("%s %s",
+ style.FgYellow.Sprint(b.UpstreamRemote),
+ style.FgYellow.Sprint(b.UpstreamBranch),
+ ),
+ )
}
return res
}