Skip to content

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

When filtering by file path for a file that was renamed at some point, we show all commits even before the rename, which is great; however when you selected a commit before the rename, the diff was empty. The commit for the rename itself would show the file as added rather than renamed.

This PR fixes that; along the way, we fix the filtered reflog display, which is supposed to filter by path like the commits view does, but this didn't work.

Fixes #4510.

@stefanhaller stefanhaller added the bug Something isn't working label Jul 17, 2025
Copy link

codacy-production bot commented Jul 17, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for b8dfba81 96.61%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (b8dfba8) Report Missing Report Missing Report Missing
Head commit (a1aeedd) 57100 49591 86.85%

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 (#4750) 236 228 96.61%

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

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.

@stefanhaller stefanhaller force-pushed the filtering-mode-fixes branch from 2c77422 to ec82e7c Compare July 27, 2025 10:03
Base automatically changed from filtering-mode-fixes to master July 27, 2025 10:05
…ile with renames

The test shows that selecting a commit before the rename shows an empty diff,
and selecting the rename itself shows an added file rather than a rename.
The combination of --abbrev=40 and %h can be shortened to %H.
I can only guess what happened here: in aa750c0, this code to manually load
the reflog commits was added, to make sorting branches by recency work when the
reflog is filtered by path. At that time we didn't have separate ReflogCommits
and FilteredReflogCommits models yet. Then, FilteredReflogCommits was introduced
(in 8822c40), probably for the very purpose of being able to get rid of this
again; but then it was forgotton to actually get rid of it.

The funny thing is that the introduction of FilteredReflogCommits happened in
the very next commit, 15 minutes later.
Using the filtered one is probably not a good idea. It didn't do much harm
because the split of ReflogCommits and FilteredReflogCommits doesn't really work
right now (FilteredReflogCommits is always the same as ReflogCommits, even in
filtering mode), but we'll fix this in the next commit.
Recycle reflog commits only for the non-filtered ones.

If we're not filtering, FilteredReflogCommits and ReflogCommits are the same. If
we then enter filtering and get reflog entries again, and pass a
lastReflogCommit, we'd recycle the previous FilteredReflogCommits, which are
unfiltered, so that's no good. Work around this by simply never using the
recycle mechanism when getting the filtered reflog commits.

We could do better by remembering what the last filter path or author was, and
only suppressing the recycling when it changed; but that's more complexity than
I want to add, so hopefully this is good enough.
I don't know why this function argument was added, but I don't like unnecessary
indirections, so I'm removing it as SubCommitsHelper has access to everything it
needs to do it itself.
It is good practice to use a -- argument even if no further arguments follow.
Doesn't really make a difference for this particular command though, I think.
These are very similar in that they call RunAndProcessLines on a git log command
and then process lines to create commits. Extract this into a common helper
function. At the moment this doesn't gain us much, but in the next commit we
will extend this helper function considerably with filter path logic, which
would otherwise have to be duplicated in both places.
When filtering for a file path we use the --follow option for "git log", so it
will follow renames of the file, which is great. However, if you then selected
one of the commits before a rename, you didn't see a diff, because we would pass
the original filter path to the "git show" call.

To fix this, call git log with the --name-status option when filtering by path,
so that each commit reports which file paths are touched in this commit;
remember these in the commit object, so that we can pass them to the "git show"
call later.

Be careful not to store too many such paths unnecessarily. When filtering by
folder rather than file, all these paths will necessarily be inside the original
filter path, so detect this and don't store them in this case.

There is some unfortunate code duplication between loading commits and loading
reflog commits, which I am too lazy to clean up right now.
When shift-selecting a range of commits across a file rename in
filtering-by-path mode, the diff currently shows an added file rather than a
renamed file. Add a test that demonstrates this, we'll fix this in the next
commit.
We need to pass the union of filter paths at both ends of the range.
@stefanhaller stefanhaller force-pushed the show-diff-for-renamed-file-when-filtering-by-path branch from 58e8faa to a1aeedd Compare July 27, 2025 10:06
@stefanhaller stefanhaller enabled auto-merge July 27, 2025 10:07
@stefanhaller stefanhaller merged commit 16231a1 into master Jul 27, 2025
13 checks passed
@stefanhaller stefanhaller deleted the show-diff-for-renamed-file-when-filtering-by-path branch July 27, 2025 10:09
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 4, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.53.0` -> `v0.54.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.54.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.54.0)

[Compare Source](jesseduffield/lazygit@v0.53.0...v0.54.0)

<!-- Release notes generated using configuration in .github/release.yml at v0.54.0 -->

Again we don't have any major new features this time (unless you count the support for alt-backspace for deleting words in the commit message editor, which is one of my favorite additions), but lots of smaller quality-of-life improvements and bug fixes. The most notable one is probably the fix for the stale index.lock problem, which was a very long-standing bug that seemed to affect some users much more than others for some reason.

#### What's Changed

##### Enhancements 🔥

- Add confirmation for hard reset by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4704
- Provide user config defaults for UI-changeable settings by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4717
- Improve mouse handling of suggestions panel by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4726
- Add new command "Checkout previous branch" by [@&#8203;kyu08](https://github.com/kyu08) in jesseduffield/lazygit#4728
- Add confirmation for nuking the working tree by [@&#8203;DawidPietrykowski](https://github.com/DawidPietrykowski) in jesseduffield/lazygit#4727
- Support Alt+Backspace for word deletion in text areas by [@&#8203;rtzll](https://github.com/rtzll) in jesseduffield/lazygit#4741
- Don't use hunk mode for added or deleted files even when useHunkModeInStagingView config is on by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4758
- Show \[0] keybinding in main view title by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4754
- Draw divergence from base branch right-aligned in branches view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4785
- Enable hunk staging mode by default by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4780

##### Fixes 🔧

- Fix scrolling hunk into view when selecting next hunk by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4709
- Fix stale main view content when entering/exiting filtering view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4719
- Detect double-clicks properly by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4725
- Fix commit searching during rebase or in divergence from upstream view by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4730
- Fix amending commits whose commit message is empty by [@&#8203;aidancz](https://github.com/aidancz) in jesseduffield/lazygit#4732
- Several small fixes to filtering mode (by path or author) by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4749
- Show diff for renamed file when filtering by path by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4750
- Allow rewording or dropping commits in filtering mode by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4756
- Fix index out of bounds panic when repository has massive tags by [@&#8203;chojs23](https://github.com/chojs23) in jesseduffield/lazygit#4776
- When pressing `a` to stage all files, don't include untracked files when showing only tracked files by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4779
- Fix commit hash colors when filtering by path or aythor by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4789
- Improve temp dir handling by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4784
- Terminate git processes more gracefully to avoid the stale index.lock problem by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4782

##### Maintenance ⚙️

- Raise sponsors MRs as a draft by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4694
- Update the peter-evans/create-pull-request action to v7 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4695
- Update release workflow by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4703
- Clean up the .gitignore file by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4706
- Remove unused code and texts by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4715
- Remove deprecated edit configs by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4716
- Bump minimum required git version to 2.32 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4718
- Use a better way of pinning the version of golangci-lint by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4733
- Make the minimum required git version a placeholder in the error text by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4778
- refactor: use slices.Equal to simplify code by [@&#8203;jishudashu](https://github.com/jishudashu) in jesseduffield/lazygit#4764

##### Docs 📖

- Fix broken markdown in auto-generated keybindings documentation by [@&#8203;KEY60228](https://github.com/KEY60228) in jesseduffield/lazygit#4690
- Remove the homebrew tap from the readme by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4705

##### I18n 🌎

- Update translations from Crowdin by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4791

##### Performance Improvements 📊

- Fix performance regression on startup in repos with many tags by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4777

#### New Contributors

- [@&#8203;KEY60228](https://github.com/KEY60228) made their first contribution in jesseduffield/lazygit#4690
- [@&#8203;DawidPietrykowski](https://github.com/DawidPietrykowski) made their first contribution in jesseduffield/lazygit#4727
- [@&#8203;rtzll](https://github.com/rtzll) made their first contribution in jesseduffield/lazygit#4741
- [@&#8203;chojs23](https://github.com/chojs23) made their first contribution in jesseduffield/lazygit#4776
- [@&#8203;jishudashu](https://github.com/jishudashu) made their first contribution in jesseduffield/lazygit#4764

**Full Changelog**: jesseduffield/lazygit@v0.53.0...v0.54.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS40Ni43IiwidXBkYXRlZEluVmVyIjoiNDEuNDYuNyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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.

File history filter doesn’t show commit details before the file was renamed
1 participant