mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-19 12:12:42 +02:00
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.
This commit is contained in:
parent
e93617b1de
commit
116c18e957
@ -18,6 +18,7 @@ func NewSyncCommands(gitCommon *GitCommon) *SyncCommands {
|
|||||||
|
|
||||||
// Push pushes to a branch
|
// Push pushes to a branch
|
||||||
type PushOpts struct {
|
type PushOpts struct {
|
||||||
|
Force bool
|
||||||
ForceWithLease bool
|
ForceWithLease bool
|
||||||
UpstreamRemote string
|
UpstreamRemote string
|
||||||
UpstreamBranch string
|
UpstreamBranch string
|
||||||
@ -30,6 +31,7 @@ func (self *SyncCommands) PushCmdObj(task gocui.Task, opts PushOpts) (oscommands
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := NewGitCmd("push").
|
cmdArgs := NewGitCmd("push").
|
||||||
|
ArgIf(opts.Force, "--force").
|
||||||
ArgIf(opts.ForceWithLease, "--force-with-lease").
|
ArgIf(opts.ForceWithLease, "--force-with-lease").
|
||||||
ArgIf(opts.SetUpstream, "--set-upstream").
|
ArgIf(opts.SetUpstream, "--set-upstream").
|
||||||
ArgIf(opts.UpstreamRemote != "", opts.UpstreamRemote).
|
ArgIf(opts.UpstreamRemote != "", opts.UpstreamRemote).
|
||||||
|
@ -32,6 +32,14 @@ func TestSyncPush(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
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",
|
testName: "Push with force disabled, upstream supplied",
|
||||||
opts: PushOpts{
|
opts: PushOpts{
|
||||||
|
@ -179,6 +179,7 @@ func (self *SyncController) pullWithLock(task gocui.Task, opts PullFilesOptions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
type pushOpts struct {
|
type pushOpts struct {
|
||||||
|
force bool
|
||||||
forceWithLease bool
|
forceWithLease bool
|
||||||
upstreamRemote string
|
upstreamRemote string
|
||||||
upstreamBranch string
|
upstreamBranch string
|
||||||
@ -197,13 +198,14 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
|
|||||||
err := self.c.Git().Sync.Push(
|
err := self.c.Git().Sync.Push(
|
||||||
task,
|
task,
|
||||||
git_commands.PushOpts{
|
git_commands.PushOpts{
|
||||||
|
Force: opts.force,
|
||||||
ForceWithLease: opts.forceWithLease,
|
ForceWithLease: opts.forceWithLease,
|
||||||
UpstreamRemote: opts.upstreamRemote,
|
UpstreamRemote: opts.upstreamRemote,
|
||||||
UpstreamBranch: opts.upstreamBranch,
|
UpstreamBranch: opts.upstreamBranch,
|
||||||
SetUpstream: opts.setUpstream,
|
SetUpstream: opts.setUpstream,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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 {
|
if opts.remoteBranchStoredLocally {
|
||||||
return errors.New(self.c.Tr.UpdatesRejected)
|
return errors.New(self.c.Tr.UpdatesRejected)
|
||||||
}
|
}
|
||||||
@ -217,7 +219,7 @@ func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts)
|
|||||||
Prompt: self.forcePushPrompt(),
|
Prompt: self.forcePushPrompt(),
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
newOpts := opts
|
newOpts := opts
|
||||||
newOpts.forceWithLease = true
|
newOpts.force = true
|
||||||
|
|
||||||
return self.pushAux(currentBranch, newOpts)
|
return self.pushAux(currentBranch, newOpts)
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user