summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-01-02 22:17:11 +0100
committerStefan Haller <stefan@haller-berlin.de>2024-01-10 09:18:38 +0100
commit76e39af76ff280a0bf184e9b7d4bf23577bfe902 (patch)
treead14c61cf0d3f29368bc3ecad40f8aa5560fd858 /pkg/commands
parent5b91cd0cc86a121f4ec96f9d5f7f35eb0ae810b9 (diff)
Allow multiple fetch commands (or fetch and pull) to run concurrently
Git has a bug [1] whereby running multiple fetch commands at the same time causes all of them to append their information to the .git/FETCH_HEAD file, causing the next git pull that wants to use the information to become confused, and show an error like "Cannot rebase onto multiple branches". This error would occur when pressing "f" and "p" in quick succession in the files panel, but also when pressing "p" while a background fetch happens to be running. One likely situation for this is pressing "p" right after startup. Since lazygit never uses the information written to .git/FETCH_HEAD, it's best to avoid writing to it, which fixes the scenarios described above. However, it doesn't fix the problem of repeatedly pressing "f" quickly on the checked-out branch; since we call "git pull" in that case, the above fix doesn't help there. We'll address this separately in another PR. [1] See https://public-inbox.org/git/xmqqy1daffk8.fsf@gitster.g/ for more information.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/sync.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/pkg/commands/git_commands/sync.go b/pkg/commands/git_commands/sync.go
index d049deb07..4ab1f336b 100644
--- a/pkg/commands/git_commands/sync.go
+++ b/pkg/commands/git_commands/sync.go
@@ -51,7 +51,10 @@ func (self *SyncCommands) Push(task gocui.Task, opts PushOpts) error {
func (self *SyncCommands) fetchCommandBuilder(fetchAll bool) *GitCommandBuilder {
return NewGitCmd("fetch").
- ArgIf(fetchAll, "--all")
+ 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 {