lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Initial delay for autoFetch not applied to recent repositories

Open gwolves opened this issue 2 years ago • 2 comments

Describe the bug I suspect this line is intended to introduce an initial delay before autoFetch for recently used repositories: https://github.com/jesseduffield/lazygit/blob/c3cf48cc4976e45bff901cecc0686287c1ad2fbc/pkg/gui/background.go#L81-L83

However, since time.After returns a channel, the correct implementation should be:

 if !isNew { 
 	<-time.After(time.Duration(userConfig.Refresher.FetchInterval) * time.Second) 
 } 

As a result, there is no initial delay before autoFetch starts.

To Reproduce Steps to reproduce the behavior:

  1. Open LazyGit on a recently used repository.
  2. Observe that autoFetch runs immediately.

Expected behavior The first autoFetch should occur after refresher.fetchInterval, assuming my interpretation is correct.

Screenshots If applicable, add screenshots to help explain your problem.

Version info: commit=, build date=, build source=nix, version=0.44.1, os=darwin, arch=arm64, git version=2.46.0 git version 2.46.0

Additional context Add any other context about the problem here.

gwolves avatar Nov 28 '24 09:11 gwolves

Thanks for pointing this out, but actually there's a lot more wrong with this code, and it only happens to do the right thing by accident (or what I personally think is the right thing, anyway). For example, IsNewRepo is always false in this function. The reason is the only code that sets it (updateRecentRepoList) runs later.

Given that, it's a good thing that we have the time.After bug. I totally want the first fetch to run immediately after startup, actually independent of whether it's a repo that I had previously open. The use case is that when I begin working in the morning, and I open a repo for the first time this day, I want it to immediately fetch what my coworkers have pushed since yesterday; there's no reason to wait for the auto-fetch interval to pass.

Another bug in this code is the handling of "exit status 128"; this code never runs for two reasons: first because it's guarded by isNew, which is always false, and second because git's error message actually contains exit code: 128. The error message that would be shown by this code says Lazygit can't use "git fetch" in a private repo; use 'f' in the files panel to run "git fetch" manually. I'm not sure what "private repo" is supposed to mean in this context; I get this error when I fetch in a repo that has a remote which is offline or doesn't exist any more. I don't want this to stop auto-fetching, so I'm glad we have this bug that prevents it from happening.

In my opinion, all this logic around background fetching should be removed. Here's a PR: #4084.

stefanhaller avatar Nov 28 '24 11:11 stefanhaller

Fixed by #4084.

stefanhaller avatar Dec 01 '24 10:12 stefanhaller