summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-05-30 21:08:57 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-06-01 08:12:45 +0200
commit116c18e9571bd6708ce56ed41fd84dde25a93de5 (patch)
tree895bea32ad6ea821ae82271fbebeac1763717d97 /pkg
parente93617b1de4b668aa7e4ac4bf483df4d11cf1edb (diff)
Use --force instead of --force-with-lease when remote is not stored locally
--force-with-lease simply doesn't work in this case, it will always return a "stale info" error.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_commands/sync.go2
-rw-r--r--pkg/commands/git_commands/sync_test.go8
-rw-r--r--pkg/gui/controllers/sync_controller.go6
3 files changed, 14 insertions, 2 deletions
diff --git a/pkg/commands/git_commands/sync.go b/pkg/commands/git_commands/sync.go
index 31561455a..1c93fc260 100644
--- a/pkg/commands/git_commands/sync.go
+++ b/pkg/commands/git_commands/sync.go
@@ -18,6 +18,7 @@ func NewSyncCommands(gitCommon *GitCommon) *SyncCommands {
// Push pushes to a branch
type PushOpts struct {
+ Force bool
ForceWithLease bool
UpstreamRemote string
UpstreamBranch string
@@ -30,6 +31,7 @@ func (self *SyncCommands) PushCmdObj(task gocui.Task, opts PushOpts) (oscommands
}
cmdArgs := NewGitCmd("push").
+ ArgIf(opts.Force, "--force").
ArgIf(opts.ForceWithLease, "--force-with-lease").
ArgIf(opts.SetUpstream, "--set-upstream").
ArgIf(opts.UpstreamRemote != "", opts.UpstreamRemote).
diff --git a/pkg/commands/git_commands/sync_test.go b/pkg/commands/git_commands/sync_test.go
index f1f76415d..6ff8da840 100644
--- a/pkg/commands/git_commands/sync_test.go
+++ b/pkg/commands/git_commands/sync_test.go
@@ -33,6 +33,14 @@ func TestSyncPush(t *testing.T) {
},
},
{
+ testName: "Push with force enabled",
+ opts: PushOpts{Force: true},
+ test: func(cmdObj oscommands.ICmdObj, err error) {
+ assert.Equal(t, cmdObj.Args(), []string{"git", "push", "--force"})
+ assert.NoError(t, err)
+ },
+ },
+ {
testName: "Push with force disabled, upstream supplied",
opts: PushOpts{
ForceWithLease: false,
diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go
index d94a49bb1..8c7334031 100644
--- a/pkg/gui/controllers/sync_controller.go
+++ b/pkg/gui/controllers/sync_controller.go
@@ -179,6 +179,7 @@ func (self *SyncController) pullWithLock(task gocui.Task, opts PullFilesOptions)
}
type pushOpts struct {
+ force bool
forceWithLease bool
upstreamRemote string
upstreamBranch string
@@ -197,13 +198,14 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
err := self.c.Git().Sync.Push(
task,
git_commands.PushOpts{
+ Force: opts.force,
ForceWithLease: opts.forceWithLease,
UpstreamRemote: opts.upstreamRemote,
UpstreamBranch: opts.upstreamBranch,
SetUpstream: opts.setUpstream,
})
if err != nil {
- if !opts.forceWithLease && strings.Contains(err.Error(), "Updates were rejected") {
+ if !opts.force && !opts.forceWithLease && strings.Contains(err.Error(), "Updates were rejected") {
if opts.remoteBranchStoredLocally {
return errors.New(self.c.Tr.UpdatesRejected)
}
@@ -217,7 +219,7 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
Prompt: self.forcePushPrompt(),
HandleConfirm: func() error {
newOpts := opts
- newOpts.forceWithLease = true
+ newOpts.force = true
return self.pushAux(currentBranch, newOpts)
},