Skip to content

Commit

Permalink
Correctly request force-pushing in triangular workflows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stefanhaller committed May 17, 2024
1 parent ad41afe commit 3073e53
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/commands/models/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (b *Branch) IsBehindForPull() bool {
return b.RemoteBranchStoredLocally() && b.BehindForPull != "0"
}

func (b *Branch) IsBehindForPush() bool {
return b.BehindForPush != "" && b.BehindForPush != "0"
}

// for when we're in a detached head state
func (b *Branch) IsRealBranch() bool {
return b.AheadForPull != "" && b.BehindForPull != ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (self *SyncController) push(currentBranch *models.Branch) error {
// if we are behind our upstream branch we'll ask if the user wants to force push
if currentBranch.IsTrackingRemote() {
opts := pushOpts{}
if currentBranch.IsBehindForPull() {
if currentBranch.IsBehindForPush() {
return self.requestToForcePush(currentBranch, opts)
} else {
return self.pushAux(currentBranch, opts)
Expand Down
7 changes: 0 additions & 7 deletions pkg/integration/tests/sync/force_push_triangular.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ var ForcePushTriangular = NewIntegrationTest(NewIntegrationTestArgs{

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

// This results in an attempt to push normally, which fails with an error:
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Contains("Updates were rejected. Please fetch and examine the remote changes before pushing again."))

/* EXPECTED:
t.ExpectPopup().Confirmation().
Title(Equals("Force push")).
Content(Equals("Your branch has diverged from the remote branch. Press <esc> to cancel, or <enter> to force push.")).
Expand All @@ -66,6 +60,5 @@ var ForcePushTriangular = NewIntegrationTest(NewIntegrationTestArgs{

t.Views().SubCommits().IsFocused().
Lines(Contains("one"))
*/
},
})

0 comments on commit 3073e53

Please sign in to comment.