mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-27 22:38:09 +02:00
Allow multiple fetch commands (or fetch and pull) to run concurrently (#3202)
This commit is contained in:
@@ -221,9 +221,9 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteract
|
|||||||
Arg("--interactive").
|
Arg("--interactive").
|
||||||
Arg("--autostash").
|
Arg("--autostash").
|
||||||
Arg("--keep-empty").
|
Arg("--keep-empty").
|
||||||
ArgIf(opts.keepCommitsThatBecomeEmpty && !self.version.IsOlderThan(2, 26, 0), "--empty=keep").
|
ArgIf(opts.keepCommitsThatBecomeEmpty && self.version.IsAtLeast(2, 26, 0), "--empty=keep").
|
||||||
Arg("--no-autosquash").
|
Arg("--no-autosquash").
|
||||||
ArgIf(!self.version.IsOlderThan(2, 22, 0), "--rebase-merges").
|
ArgIf(self.version.IsAtLeast(2, 22, 0), "--rebase-merges").
|
||||||
ArgIf(opts.onto != "", "--onto", opts.onto).
|
ArgIf(opts.onto != "", "--onto", opts.onto).
|
||||||
Arg(opts.baseShaOrRoot).
|
Arg(opts.baseShaOrRoot).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|||||||
@@ -49,10 +49,16 @@ func (self *SyncCommands) Push(task gocui.Task, opts PushOpts) error {
|
|||||||
return cmdObj.Run()
|
return cmdObj.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SyncCommands) fetchCommandBuilder(fetchAll bool) *GitCommandBuilder {
|
||||||
|
return NewGitCmd("fetch").
|
||||||
|
ArgIf(fetchAll, "--all").
|
||||||
|
// avoid writing to .git/FETCH_HEAD; this allows running a pull
|
||||||
|
// concurrently without getting errors
|
||||||
|
ArgIf(self.version.IsAtLeast(2, 29, 0), "--no-write-fetch-head")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *SyncCommands) FetchCmdObj(task gocui.Task) oscommands.ICmdObj {
|
func (self *SyncCommands) FetchCmdObj(task gocui.Task) oscommands.ICmdObj {
|
||||||
cmdArgs := NewGitCmd("fetch").
|
cmdArgs := self.fetchCommandBuilder(self.UserConfig.Git.FetchAll).ToArgv()
|
||||||
ArgIf(self.UserConfig.Git.FetchAll, "--all").
|
|
||||||
ToArgv()
|
|
||||||
|
|
||||||
cmdObj := self.cmd.New(cmdArgs)
|
cmdObj := self.cmd.New(cmdArgs)
|
||||||
cmdObj.PromptOnCredentialRequest(task)
|
cmdObj.PromptOnCredentialRequest(task)
|
||||||
@@ -64,9 +70,7 @@ func (self *SyncCommands) Fetch(task gocui.Task) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SyncCommands) FetchBackgroundCmdObj() oscommands.ICmdObj {
|
func (self *SyncCommands) FetchBackgroundCmdObj() oscommands.ICmdObj {
|
||||||
cmdArgs := NewGitCmd("fetch").
|
cmdArgs := self.fetchCommandBuilder(self.UserConfig.Git.FetchAll).ToArgv()
|
||||||
ArgIf(self.UserConfig.Git.FetchAll, "--all").
|
|
||||||
ToArgv()
|
|
||||||
|
|
||||||
cmdObj := self.cmd.New(cmdArgs)
|
cmdObj := self.cmd.New(cmdArgs)
|
||||||
cmdObj.DontLog().FailOnCredentialRequest()
|
cmdObj.DontLog().FailOnCredentialRequest()
|
||||||
@@ -104,7 +108,7 @@ func (self *SyncCommands) FastForward(
|
|||||||
remoteName string,
|
remoteName string,
|
||||||
remoteBranchName string,
|
remoteBranchName string,
|
||||||
) error {
|
) error {
|
||||||
cmdArgs := NewGitCmd("fetch").
|
cmdArgs := self.fetchCommandBuilder(false).
|
||||||
Arg(remoteName).
|
Arg(remoteName).
|
||||||
Arg(remoteBranchName + ":" + branchName).
|
Arg(remoteBranchName + ":" + branchName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
@@ -113,7 +117,7 @@ func (self *SyncCommands) FastForward(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SyncCommands) FetchRemote(task gocui.Task, remoteName string) error {
|
func (self *SyncCommands) FetchRemote(task gocui.Task, remoteName string) error {
|
||||||
cmdArgs := NewGitCmd("fetch").
|
cmdArgs := self.fetchCommandBuilder(false).
|
||||||
Arg(remoteName).
|
Arg(remoteName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
|
|||||||
@@ -69,3 +69,11 @@ func (v *GitVersion) IsOlderThan(major, minor, patch int) bool {
|
|||||||
func (v *GitVersion) IsOlderThanVersion(version *GitVersion) bool {
|
func (v *GitVersion) IsOlderThanVersion(version *GitVersion) bool {
|
||||||
return v.IsOlderThan(version.Major, version.Minor, version.Patch)
|
return v.IsOlderThan(version.Major, version.Minor, version.Patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *GitVersion) IsAtLeast(major, minor, patch int) bool {
|
||||||
|
return !v.IsOlderThan(major, minor, patch)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *GitVersion) IsAtLeastVersion(version *GitVersion) bool {
|
||||||
|
return v.IsAtLeast(version.Major, version.Minor, version.Patch)
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,3 +45,12 @@ func TestGitVersionIsOlderThan(t *testing.T) {
|
|||||||
assert.True(t, (&GitVersion{2, 0, 1, ""}).IsOlderThan(2, 1, 0))
|
assert.True(t, (&GitVersion{2, 0, 1, ""}).IsOlderThan(2, 1, 0))
|
||||||
assert.True(t, (&GitVersion{2, 0, 1, ""}).IsOlderThan(3, 0, 0))
|
assert.True(t, (&GitVersion{2, 0, 1, ""}).IsOlderThan(3, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGitVersionIsAtLeast(t *testing.T) {
|
||||||
|
assert.True(t, (&GitVersion{2, 0, 0, ""}).IsAtLeast(1, 99, 99))
|
||||||
|
assert.True(t, (&GitVersion{2, 0, 0, ""}).IsAtLeast(2, 0, 0))
|
||||||
|
assert.True(t, (&GitVersion{2, 1, 0, ""}).IsAtLeast(2, 0, 9))
|
||||||
|
|
||||||
|
assert.False(t, (&GitVersion{2, 0, 1, ""}).IsAtLeast(2, 1, 0))
|
||||||
|
assert.False(t, (&GitVersion{2, 0, 1, ""}).IsAtLeast(3, 0, 0))
|
||||||
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func (self GitVersionRestriction) shouldRunOnVersion(version *git_commands.GitVe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Invalid git version string: " + self.from)
|
panic("Invalid git version string: " + self.from)
|
||||||
}
|
}
|
||||||
return !version.IsOlderThanVersion(from)
|
return version.IsAtLeastVersion(from)
|
||||||
}
|
}
|
||||||
if self.before != "" {
|
if self.before != "" {
|
||||||
before, err := git_commands.ParseGitVersion(self.before)
|
before, err := git_commands.ParseGitVersion(self.before)
|
||||||
|
|||||||
Reference in New Issue
Block a user