diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-04-26 11:20:16 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-05-19 09:44:38 +0200 |
commit | c5cf1b2428c7fd23f63a9fb7fe9a5911dd2f004a (patch) | |
tree | 0a905a5ba40ce4ec4c907ce8c6baf0361bb3ffc5 | |
parent | d890c68cd0a77d3b5bf8bf1c4a672f8b0a0bfbb4 (diff) |
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.
-rw-r--r-- | pkg/commands/models/branch.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/sync_controller.go | 2 | ||||
-rw-r--r-- | pkg/integration/tests/sync/force_push_triangular.go | 7 |
3 files changed, 5 insertions, 8 deletions
diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go index 75d99f4bc..25d806fca 100644 --- a/pkg/commands/models/branch.go +++ b/pkg/commands/models/branch.go @@ -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 != "" diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index 8bd8dac9a..7d7ca9eed 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -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) diff --git a/pkg/integration/tests/sync/force_push_triangular.go b/pkg/integration/tests/sync/force_push_triangular.go index 379912f6c..70912d123 100644 --- a/pkg/integration/tests/sync/force_push_triangular.go +++ b/pkg/integration/tests/sync/force_push_triangular.go @@ -36,12 +36,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.")). @@ -67,6 +61,5 @@ var ForcePushTriangular = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().SubCommits().IsFocused(). Lines(Contains("one")) - */ }, }) |