Skip to content
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 possible crash when deleting a branch while filtering is active #4195

Merged

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

Fix #4179.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Copy link

codacy-production bot commented Jan 21, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for a0aa7a11 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a0aa7a1) Report Missing Report Missing Report Missing
Head commit (ff4ae4a) 52637 45590 86.61%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4195) 33 33 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@jesseduffield
Copy link
Owner

nice, makes sense

@stefanhaller stefanhaller force-pushed the fix-crash-when-deleting-branch-while-filter-is-active branch from 9bd4ce7 to c20badb Compare February 3, 2025 09:27
@stefanhaller stefanhaller marked this pull request as ready for review February 3, 2025 09:30
@stefanhaller
Copy link
Collaborator Author

@jesseduffield Finally got around to adding a test, so this is ready now. (I verified that the test crashes when reverting the fix.)

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one

The code that tries to reselect the same branch again uses GetItems, which in
case of filtering is the filtered list. After replacing the branches slice with
a new one, the filtered list is no longer up to date, so we must reapply the
filter before working with it. It so happens that refreshView does that, so
simply call that before setting the selection again; I don't think the order
matters in this case. Otherwise we'd have to insert another call to
ReApplyFilter before the call to GetItems, which we can avoid this way.

Note that this doesn't actually make anything work better in the case of
deleting a branch, since we can't reselect the deleted branch anyway of course.
But it avoids a possible crash if the branch that was deleted was the last one
in the unfiltered list.
@stefanhaller stefanhaller force-pushed the fix-crash-when-deleting-branch-while-filter-is-active branch from c20badb to ff4ae4a Compare February 7, 2025 08:34
@stefanhaller stefanhaller merged commit 0b52429 into master Feb 7, 2025
15 checks passed
@stefanhaller stefanhaller deleted the fix-crash-when-deleting-branch-while-filter-is-active branch February 7, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on deleting a branch in combination with filtering
2 participants