mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
Rename Force to ForceWithLease
This describes better what it is, and we're going to add the regular --force in the next commit. No change in behavior in this commit.
This commit is contained in:
parent
aac2535104
commit
e93617b1de
@ -18,7 +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
|
||||||
UpstreamRemote string
|
UpstreamRemote string
|
||||||
UpstreamBranch string
|
UpstreamBranch string
|
||||||
SetUpstream bool
|
SetUpstream bool
|
||||||
@ -30,7 +30,7 @@ func (self *SyncCommands) PushCmdObj(task gocui.Task, opts PushOpts) (oscommands
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := NewGitCmd("push").
|
cmdArgs := NewGitCmd("push").
|
||||||
ArgIf(opts.Force, "--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).
|
||||||
ArgIf(opts.UpstreamBranch != "", opts.UpstreamBranch).
|
ArgIf(opts.UpstreamBranch != "", opts.UpstreamBranch).
|
||||||
|
@ -18,15 +18,15 @@ func TestSyncPush(t *testing.T) {
|
|||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
testName: "Push with force disabled",
|
testName: "Push with force disabled",
|
||||||
opts: PushOpts{Force: false},
|
opts: PushOpts{ForceWithLease: false},
|
||||||
test: func(cmdObj oscommands.ICmdObj, err error) {
|
test: func(cmdObj oscommands.ICmdObj, err error) {
|
||||||
assert.Equal(t, cmdObj.Args(), []string{"git", "push"})
|
assert.Equal(t, cmdObj.Args(), []string{"git", "push"})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Push with force enabled",
|
testName: "Push with force-with-lease enabled",
|
||||||
opts: PushOpts{Force: true},
|
opts: PushOpts{ForceWithLease: true},
|
||||||
test: func(cmdObj oscommands.ICmdObj, err error) {
|
test: func(cmdObj oscommands.ICmdObj, err error) {
|
||||||
assert.Equal(t, cmdObj.Args(), []string{"git", "push", "--force-with-lease"})
|
assert.Equal(t, cmdObj.Args(), []string{"git", "push", "--force-with-lease"})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -35,7 +35,7 @@ func TestSyncPush(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testName: "Push with force disabled, upstream supplied",
|
testName: "Push with force disabled, upstream supplied",
|
||||||
opts: PushOpts{
|
opts: PushOpts{
|
||||||
Force: false,
|
ForceWithLease: false,
|
||||||
UpstreamRemote: "origin",
|
UpstreamRemote: "origin",
|
||||||
UpstreamBranch: "master",
|
UpstreamBranch: "master",
|
||||||
},
|
},
|
||||||
@ -47,7 +47,7 @@ func TestSyncPush(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testName: "Push with force disabled, setting upstream",
|
testName: "Push with force disabled, setting upstream",
|
||||||
opts: PushOpts{
|
opts: PushOpts{
|
||||||
Force: false,
|
ForceWithLease: false,
|
||||||
UpstreamRemote: "origin",
|
UpstreamRemote: "origin",
|
||||||
UpstreamBranch: "master",
|
UpstreamBranch: "master",
|
||||||
SetUpstream: true,
|
SetUpstream: true,
|
||||||
@ -58,9 +58,9 @@ func TestSyncPush(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Push with force enabled, setting upstream",
|
testName: "Push with force-with-lease enabled, setting upstream",
|
||||||
opts: PushOpts{
|
opts: PushOpts{
|
||||||
Force: true,
|
ForceWithLease: true,
|
||||||
UpstreamRemote: "origin",
|
UpstreamRemote: "origin",
|
||||||
UpstreamBranch: "master",
|
UpstreamBranch: "master",
|
||||||
SetUpstream: true,
|
SetUpstream: true,
|
||||||
@ -73,7 +73,7 @@ func TestSyncPush(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testName: "Push with remote branch but no origin",
|
testName: "Push with remote branch but no origin",
|
||||||
opts: PushOpts{
|
opts: PushOpts{
|
||||||
Force: true,
|
ForceWithLease: true,
|
||||||
UpstreamRemote: "",
|
UpstreamRemote: "",
|
||||||
UpstreamBranch: "master",
|
UpstreamBranch: "master",
|
||||||
SetUpstream: true,
|
SetUpstream: true,
|
||||||
|
@ -179,7 +179,7 @@ func (self *SyncController) pullWithLock(task gocui.Task, opts PullFilesOptions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
type pushOpts struct {
|
type pushOpts struct {
|
||||||
force bool
|
forceWithLease bool
|
||||||
upstreamRemote string
|
upstreamRemote string
|
||||||
upstreamBranch string
|
upstreamBranch string
|
||||||
setUpstream bool
|
setUpstream bool
|
||||||
@ -197,13 +197,13 @@ 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,
|
||||||
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.force && strings.Contains(err.Error(), "Updates were rejected") {
|
if !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 +217,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.force = true
|
newOpts.forceWithLease = true
|
||||||
|
|
||||||
return self.pushAux(currentBranch, newOpts)
|
return self.pushAux(currentBranch, newOpts)
|
||||||
},
|
},
|
||||||
@ -240,7 +240,7 @@ func (self *SyncController) requestToForcePush(currentBranch *models.Branch, opt
|
|||||||
Title: self.c.Tr.ForcePush,
|
Title: self.c.Tr.ForcePush,
|
||||||
Prompt: self.forcePushPrompt(),
|
Prompt: self.forcePushPrompt(),
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
opts.force = true
|
opts.forceWithLease = true
|
||||||
return self.pushAux(currentBranch, opts)
|
return self.pushAux(currentBranch, opts)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user