-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition with reselecting the focused branch and rendering #4268
base: master
Are you sure you want to change the base?
Conversation
In ff4ae4a we changed the order of the calls to render before selecting the branch. This was done only to save an extra call to ReApplyFilter, which is done by refreshView; I claimed that the order of refreshView vs. SetSelectedLineIdx doesn't matter here. I guess I was wrong about that, it makes the integration test custom_commands/suggestions_preset.go flaky. To fix this, put the refreshView call back to where it was (after the SetSelectedLineIdx call), and instead insert an extra call to ReApplyFilter where necessary to fix the bug that ff4ae4a was trying to fix.
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@stefanhaller There could be a user facing problem caused by this, but I imagine it would be small. I normally only switch branches by hovering over them and hitting I just tried setting up my local build with the equivalent config to the flaky integration test:
and was unable to reproduce it right now on the If we do know a non-contrived flow that relies on this focusing behavior, it might be worth giving it a few reps to see if it gets a more unlucky roll of the dice for some reason. |
I suppose you are right. And the focussing behavior that we are talking about is not only needed when running a custom command that checks out a branch (I guess you could also checkout the branch on the command line in another terminal and then come back to lazygit), but also when the sort order of the branches list changes for some other reason. The commit message of 2c9b477 describes one such scenario that I actually find pretty important. I still don't understand what exactly went wrong, and I don't have time right now to dig deeper (will try tomorrow), but if the issue is that sometimes the call to SetSelectedLineIdx happened before the call to FocusLine, then that's only a visual problem, not a behavior problem. We are selecting the right branch after all, we might just not render it as selected. But invoking any command on the selected branch (including arrow up/down to select the prev/next) will work correctly because these are using the model selection. The reason why the test failed is because integration tests don't know anything about the model selection, they can only look at the view highlight. Ok, I did some testing with the following custom command: customCommands:
- key: a
command: git checkout -
context: localBranches Then, check out some branch, check out some other branch, and then keep pressing I observed that sometimes it keeps the same index selected, but only for a brief moment (like half a second or so), then the highlight jumps to the right branch. And I can see this both with this branch and with master, which confuses me quite a bit. I have to stop now, will continue tomorrow. |
In ff4ae4a we changed the order of the calls to render before selecting the branch. This was done only to save an extra call to ReApplyFilter, which is done by refreshView; I claimed that the order of refreshView vs. SetSelectedLineIdx doesn't matter here. I guess I was wrong about that, it makes the integration test custom_commands/suggestions_preset.go flaky. To fix this, put the refreshView call back to where it was (after the SetSelectedLineIdx call), and instead insert an extra call to ReApplyFilter where necessary to fix the bug that ff4ae4a was trying to fix.
I still don't think there was any user facing problem caused by this (@ChrisMcD1 correct me if I'm wrong), so I don't think we need to cut a 0.46.1 release with the fix (otherwise it would have been a regression in 0.46), and I only label it as
maintenance
because it only fixes CI.Fixes #4267.