Skip to content

Commit c5cf1b2

Browse files
committed
Correctly request force-pushing in triangular workflows
To determine whether we need to ask for force pushing, we need to query the push branch rather than the upstream branch, in case they are not the same.
1 parent d890c68 commit c5cf1b2

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

pkg/commands/models/branch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func (b *Branch) IsBehindForPull() bool {
103103
return b.RemoteBranchStoredLocally() && b.BehindForPull != "0"
104104
}
105105

106+
func (b *Branch) IsBehindForPush() bool {
107+
return b.BehindForPush != "" && b.BehindForPush != "0"
108+
}
109+
106110
// for when we're in a detached head state
107111
func (b *Branch) IsRealBranch() bool {
108112
return b.AheadForPull != "" && b.BehindForPull != ""

pkg/gui/controllers/sync_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (self *SyncController) push(currentBranch *models.Branch) error {
9090
// if we are behind our upstream branch we'll ask if the user wants to force push
9191
if currentBranch.IsTrackingRemote() {
9292
opts := pushOpts{}
93-
if currentBranch.IsBehindForPull() {
93+
if currentBranch.IsBehindForPush() {
9494
return self.requestToForcePush(currentBranch, opts)
9595
} else {
9696
return self.pushAux(currentBranch, opts)

pkg/integration/tests/sync/force_push_triangular.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ var ForcePushTriangular = NewIntegrationTest(NewIntegrationTestArgs{
3636

3737
t.Views().Files().IsFocused().Press(keys.Universal.Push)
3838

39-
// This results in an attempt to push normally, which fails with an error:
40-
t.ExpectPopup().Alert().
41-
Title(Equals("Error")).
42-
Content(Contains("Updates were rejected. Please fetch and examine the remote changes before pushing again."))
43-
44-
/* EXPECTED:
4539
t.ExpectPopup().Confirmation().
4640
Title(Equals("Force push")).
4741
Content(Equals("Your branch has diverged from the remote branch. Press <esc> to cancel, or <enter> to force push.")).
@@ -67,6 +61,5 @@ var ForcePushTriangular = NewIntegrationTest(NewIntegrationTestArgs{
6761

6862
t.Views().SubCommits().IsFocused().
6963
Lines(Contains("one"))
70-
*/
7164
},
7265
})

0 commit comments

Comments
 (0)