1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00
Commit Graph

6719 Commits

Author SHA1 Message Date
bc936e8d1b Extract helper function for integration test
We are going to reuse it in two other tests that we are going to add in the next
commit.
2025-07-27 12:48:38 +02:00
6976d38586 Inline the OutsideFilterMode guard into every binding
The reason for doing this is that we want to remove the guard from some of
these, but we don't want to change the order.
2025-07-27 12:48:38 +02:00
96480edb01 Show [0] keybinding in main view title (#4754)
- **PR Description**

Show the `[0]` keybinding in the title of the main view, to make it more
discoverable.

Also, move it to the "global" section of the keybindings menu.

And several minor fixes and cleanups, see individual commits for
details.

Fixes #4738.
2025-07-27 12:29:50 +02:00
0cfe42b43f Show the key for focusing the main view ("[0]" by default) in the main view title prefix
We show it only if the "showPanelJumps" config is on, although the
focus-main-view command is not technically part of the panel jump keys; but it
looks similar.
2025-07-27 12:28:06 +02:00
72a8e8194d Fix display of panel jump keys for disabled bindings 2025-07-27 12:27:56 +02:00
b9f4c43695 Allow focusing the main view for the status panel
I left this out originally because it's not needed for the status "dashboard"
view (except on really tiny screens); however, it *is* useful after pressing `a`
to show the all branches log, and even more so for people who use the
"statusPanelView: allBranchesLog" config. And it doesn't really hurt for the
dashboard view either, so just enable it always rather than making a distinction
which view we are showing.
2025-07-27 12:27:35 +02:00
837efd95e2 Move the "Focus main view" command to the global section of the keybindings menu 2025-07-27 12:25:16 +02:00
96a6e659a6 Make LabelFromKey return an empty string for unset keys
It previously returned "\x00", which is probably not intended, but happened to
work.
2025-07-27 12:25:16 +02:00
7fe96e9aee Include commands without keybinding in options menu
This is not a behavior change, we already include these in the menu, but that's
because of a bug that we will fix in the next commit.

I find it useful to see these commands, especially for rarely-used custom
commands that you don't want to waste a keybinding on.
2025-07-27 12:25:16 +02:00
2bd6881f60 Don't use hunk mode for added or deleted files even when useHunkModeInStagingView config is on (#4758)
- **PR Description**

When entering staging (or patch building) for an added or deleted file,
it doesn't make sense to use hunk mode, because pressing space would
stage/unstage the entire file, and if the user wanted to do that, they
would have pressed space in the Files panel. So always use line mode for
added/deleted files by default, even if the useHunkModeInStagingView
user config is on.
2025-07-27 12:23:45 +02:00
c5acad777d Don't use hunk mode for added or deleted files
When entering staging (or patch building) for an added or deleted file, it
doesn't make sense to use hunk mode, because pressing space would stage/unstage
the entire file, and if the user wanted to do that, they would have pressed
space in the Files panel. So always use line mode for added/deleted files by
default, even if the useHunkModeInStagingView user config is on.
2025-07-27 12:10:25 +02:00
fc3b725424 Add a test case for a deleted file to TestParseAndFormatPlain
Not because it's terribly important to test here (doesn't hurt though), but
because it will be useful in the next commit for a new test we're adding there.
2025-07-27 12:10:25 +02:00
16231a150c Show diff for renamed file when filtering by path (#4750)
- **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.
2025-07-27 12:09:06 +02:00
a1aeedd5d5 Fix showing range diff across a rename when filtering by path
We need to pass the union of filter paths at both ends of the range.
2025-07-27 12:05:41 +02:00
e716617a82 Add test for range diff across rename
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.
2025-07-27 12:05:41 +02:00
0f7f1a56df Fix showing diffs for renamed file when filtering by path
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.
2025-07-27 12:05:41 +02:00
88dae1d8b9 Refactor commit loading and reflog commit loading to extract shared code
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.
2025-07-27 12:05:41 +02:00
e7c33a7a65 Always append -- to git show command
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.
2025-07-27 12:05:41 +02:00
33a4fdf0ee Remove unnecessary setSubCommits indirection
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.
2025-07-27 12:05:41 +02:00
e1d728ee5e Fix showing only filtered reflog entries when filtering by path
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.
2025-07-27 12:05:41 +02:00
934276ac40 Use the non-filtered reflog for undoing
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.
2025-07-27 12:05:41 +02:00
d99ceb91ee Don't get reflog commits twice unnecessarily in filtering mode
I can only guess what happened here: in aa750c0819, 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 8822c409e2), 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.
2025-07-27 12:05:41 +02:00
92b5bad29d Cleanup: simplify git arguments for reflog loading
The combination of --abbrev=40 and %h can be shortened to %H.
2025-07-27 12:05:41 +02:00
8515c74722 Add test that demonstrates problem with showing filtered history of file 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.
2025-07-27 12:05:41 +02:00
b8dfba8b3d Several small fixes to filtering mode (by path or author) (#4749)
- Refresh views properly when entering/exiting filtering mode
- Fix filtering of stashes
2025-07-27 12:05:18 +02:00
ec82e7c1e7 Make stash filtering work when filtering on a folder 2025-07-27 12:03:06 +02:00
09cbaf2cba Make stash loading work in filtering mode
This broke with the introduction of the age in the stashes list in bc330b8ff3
(which was included in 0.41, so 12 minor versions ago).

This makes it work again when filtering by file, but it still doesn't work when
filtering by folder (and never has). We'll fix that next.
2025-07-27 12:03:06 +02:00
0dfa078653 Revert "chore: use null char as a stash entries divider during loading"
This was not a good idea, and it seems it has never been tested: the --name-only
and -z options don't work well together. Specifically, -z seems to simply cancel
--name-only.

This is not enough to make it work, we'll need more fixes in the next commit.

This reverts commit 50044dd5e0.
2025-07-27 12:03:06 +02:00
ea84d5ee96 Add integration test for filtering the stashes list by file path
The test shows that it doesn't work, the list is empty both when filtering by
file and by folder.

I could have added test cases for these to the unit tests in
stash_loader_test.go instead, but I don't find tests that need to mock git's
output very valuable, so I opted for an integration test even though it takes
much longer to run.
2025-07-27 12:03:06 +02:00
5e65e8e0ea Refresh all affected scopes when entering/exiting filtering
Since filtering switches to half-screen mode in the local commits panel, most
people probably didn't notice, but we do also filter those other views. So when
leaving half-screen mode (but not filtering), you could switch to sub-commits or
stashes, and those would show the filtered view only after the next refresh
(e.g. after a background fetch). It's worse when leaving filtering, because this
goes back to normal screen mode, and you would often see an empty stashes panel
after that (until the next background fetch), which is quite confusing.

I also find it questionable to always switch focus to the commits panel when
entering filtering. If it is initiated from subcommits, reflog, or stashes,
maybe we want to stay there. I'm not changing this now since I'm unsure how much
people rely on the current behavior.
2025-07-27 12:03:06 +02:00
5307999874 Allow passing SUB_COMMITS scope to Refresh when no subcommits view is showing
We don't currently do this, but will in the next commit; it's a reasonable thing
to want to do, and it shouldn't crash.
2025-07-27 12:03:06 +02:00
e5c39d5401 Fix visual regression when exiting filtering mode
When exiting filtering mode while the focus is not in the local commits panel,
the call to HandleFocus would render the selection in the commits panel as if
the panel had the focus.

The call to HandleFocus was introduced recently in 4981419ba9 in an attempt to
rerender the main view correctly, but it should only have been called when local
commits is the focused context. But instead, we can use PostRefreshUpdate, which
handles this distinction.
2025-07-27 12:03:06 +02:00
143d4760fd Use a better way of pinning the version of golangci-lint (#4733)
- **PR Description**

Instead of requiring the user to install the right version of the tool
in their .bin folder, create a shim that automatically runs the right
version of the tool. This has several benefits:
- it works out of the box with no setup required (the tool will be
automatically downloaded and compiled the first time it is used)
- no work needed for developers when we bump the golangci-lint version
- it works in working copies that are used in different environments
(e.g. locally on a Mac, or inside a dev container)

Approach suggested by @kyu08.
2025-07-18 18:31:34 +02:00
37d5aeea8b Remove unnecessary golangci-lint install step from dev-container Dockerfile 2025-07-18 15:36:43 +02:00
c8a1e894e0 Remove unused script lint.sh 2025-07-18 15:33:23 +02:00
38fc107f94 Use a better way of pinning the version of golangci-lint
Instead of requiring the user to install the right version of the tool in their
.bin folder, create a shim that automatically runs the right version of the
tool. This has several benefits:
- it works out of the box with no setup required (the tool will be automatically
  downloaded and compiled the first time it is used)
- no work needed for developers when we bump the golangci-lint version
- it works in working copies that are used in different environments (e.g.
  locally on a Mac, or inside a dev container)

Co-authored-by: kyu08 <49891479+kyu08@users.noreply.github.com>
2025-07-18 15:33:23 +02:00
d159b28dc0 Support Alt+Backspace for word deletion in text areas (#4741)
- **PR Description**
Add support for Alt+Backspace (Option+Backspace on macOS) to delete
entire words in text input areas, matching common text editor behavior.
2025-07-17 19:20:52 +02:00
69567063f4 Support Alt+Backspace for word deletion in text areas
Add support for Alt+Backspace (Option+Backspace on macOS) to delete
entire words in text input areas, matching common text editor behavior.
2025-07-17 19:13:25 +02:00
1210a645ef Fix amending commits whose commit message is empty (#4732)
- **PR Description**

When the commit message is empty, the `--amend` command will produce an error.
Solution: Add the `--allow-empty-message` option.
2025-07-14 18:00:12 +02:00
0451a16510 Fix --amend when the commit message is empty 2025-07-14 17:58:31 +02:00
9625ee8a59 Add confirmation for nuking the working tree (#4727)
- **PR Description**

This is a small PR that extends the logic added in
https://github.com/jesseduffield/lazygit/pull/4704

There were many reports of users accidentally resetting the working tree
using the reset commands and a nice change was added by @stefanhaller to
prompt for confirmation on those actions but the "Nuke working tree"
option was not covered by the PR.

I believe this one is actually one of the most important options to
prompt because it's by default the first one on the list. I myself
triggered it once when trying to discard a single file while unknowingly
having caps-lock enabled as I thought I was confirming the single file
discard option.
2025-07-13 15:01:22 +02:00
238fdd573c Add confirmation for nuking the working tree 2025-07-13 14:04:14 +02:00
1795cb9315 Add new command "Checkout previous branch" (#4728)
## **PR Description**
I added a new feature to checkout to the last branch.
I think it would be convenient to be able to checkout to the last branch
with just one key stroke(`-`) in some cases, such as when switching
between multiple branches during code review.

Off course, I know that you can same thing by entering `"-"` to the text
input of "Checkout by name" or using custom command but I think `git
checkout -` is occasional use case. So I feel this feature can be a part
of default features.

Another advantage of this feature is that you can checkout to the last
branch regardless of cursor position.
Being able to switch branches without worrying about cursor position
reduces stress I think.
2025-07-12 18:20:11 +02:00
d41668f565 Fix last branch to previous branch in TranslationSet.CheckoutByNameTooltip 2025-07-12 18:17:45 +02:00
c75d92f270 Update cheatsheets and schema 2025-07-12 18:17:45 +02:00
5b1292006d Add new command "Checkout previous branch" 2025-07-12 18:17:25 +02:00
7d92260050 Fix commit searching during rebase or in divergence from upstream view (#4730)
- **PR Description**

Fix search results being off by two lines during a rebase or in the
divergence from upstream view.
2025-07-12 17:36:26 +02:00
2b41a27d92 Fix search results being off by two lines during rebase or in divergence view
We forgot to convert the model indices to view indices in searchModelCommits.
This needs to be done for search results to be highlighted correctly in the
"divergence from upstream" view, which adds "--- Remote/Local ---" entries, and
during a rebase, where we have "--- Pending rebase todos ---" and "--- Commits
---" which offset view indices from model indices.
2025-07-12 17:30:36 +02:00
dd47ef7354 Make prepareConversionArrays a little more concurrency safe
I have seen cases where during a rebase (two nonModelItems) all entries in
viewIndicesByModelIndex beyond the second nonModelItem were off by 4 rather than
2 as I would expect. The only explanation I have for this is that the function
was called concurrently.

Improve this by working on a local variable and only assign to self at the end;
this is not a real fix for the concurrency issue of course, but it makes it much
less likely to be a problem in practice.
2025-07-12 17:25:35 +02:00
228d4428ca Improve mouse handling of suggestions panel (#4726)
- **PR Description**

In prompts with a suggestions panel (e.g. the "Execute shell command"
window, or the "Filter by path" panel), you can now
- scroll the list of suggestions with the mouse wheel even when the
  focus is in the edit field
- click in the suggestions list or in the edit field to switch focus
  between them
- double-click a suggestion to trigger it
2025-07-11 11:26:39 +02:00