1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02:00
Commit Graph

6589 Commits

Author SHA1 Message Date
9e5c44d30d README.md: Update Sponsors 2025-07-04 17:46:47 +00:00
bc4b50f817 Add user config to use hunk mode by default when entering staging view (#4685)
- **PR Description**

As of #4684, hunk mode has become so useful that I prefer it over line
mode now. This PR adds a config that lets you use hunk mode by default
in the staging view.

I'm not enabling this by default yet, although I do think it's the more
useful mode for most people. The biggest issue that I still have with
this is that _if_ you need to switch to line mode for some reason, then
it's very non-obvious how to do that. New users might not find out at
all, and think that lazygit doesn't allow staging individual lines.
2025-07-04 19:46:36 +02:00
0a73123a66 Escape out of hunk mode only if it was turned on by the user
If hunk mode is on by default because of the config, then it's annoying for
escape to go to line mode.
2025-07-04 19:41:40 +02:00
2961c991a4 Add user config to use hunk mode by default when entering staging view 2025-07-04 19:41:40 +02:00
a6001dc76e Cleanup: rename a badly named function
We used the term "change line" to mean "a line that was added or deleted", but
it sounded like a verb in the function name.
2025-07-04 19:41:39 +02:00
9f23b89e90 Improve hunk selection mode in staging view (#4684)
- **PR Description**

Hunk selection mode is one of the features that many people don't know
about, because it is not very discoverable. You can switch to it from
line selection mode by pressing `a` in the staging view.

The problem with this mode is that it selects entire hunks, where hunks
are defined to be sections of the diff starting with `@@`. Very often,
hunks consist of multiple distinct blocks of changes, separated by
context lines. For example, with the default diff context size of 3 it
takes at least 6 unchanged lines between blocks of changes for them to
be separated into distinct hunks; if there are 5 or less unchanged lines
between them, they are grouped into one hunk. And of course, if you
increase the diff context size by pressing `}`, you will get even fewer
hunks.

Now, most of the time I want to navigate between the individual blocks
of changes in a diff, regardless of how git groups them into hunks.
That's what this PR does: when pressing `a`, the selection is extended
to just the current group of changes, separated by context lines; you
can easily stage it by pressing space, and the selection will move on to
the next block of changes. Actual hunks no longer play a role here.
Also, in line selection mode the right/left arrow keys now move between
blocks of changes rather than actual hunks.

I find this new behavior so useful that I almost always switch to hunk
mode right away after entering the staging view. It saves a lot of
keystrokes, since it is very rare that I want to select only some lines
of a block of adjacent changes. This makes me wonder whether we should
enable hunk mode by default when entering staging, but that's going to
be another PR.
2025-07-04 19:37:48 +02:00
a6096f4702 In hunk staging mode, select blocks of changes rather than actual hunks
Also, pressing right or left arrow moves between blocks of changes rather than
actual hunks. I find this to be much more useful.
2025-07-04 19:31:35 +02:00
08ad8a0b2d Don't generate test list before running integration test
It's annoyingly slow, and there is a separate task for generating the list if
needed.

Also, clear the terminal before running the test; this makes it easier to see
the results of the last test run.
2025-07-04 18:26:45 +02:00
3ea4cf0b63 Update translations from Crowdin (#4686)
- **PR Description**

Update translations from Crowdin
2025-07-04 18:25:19 +02:00
9290c074f7 Update translations from Crowdin 2025-07-04 18:22:13 +02:00
ca06ce6100 Collapse selection after deleting a range of branches or stashes (#4661)
- **PR Description**

Fixes selection state persistence after deletion by resetting selection
mode.
Resolves [#4612](https://github.com/jesseduffield/lazygit/issues/4612)
2025-07-04 17:34:33 +02:00
bc0cddf03d Collapse selection after deleting a range of stashes 2025-07-04 17:28:29 +02:00
4b33efffbe Collapse selection after deleting a range of remote branches
We only want to do this when the function is called from the remote branches
panel. It can also be called with a selection of local branches in order to
delete their remote branches, but in this case the selection shouldn't be
collapsed because the local branches stay around.
2025-07-04 17:20:22 +02:00
80a614d330 Fix collapsing the range selection after deleting branches
We had code already that was supposed to do this, but it didn't work. It should
have used SetSelection() instead of SetSelectedLineIdx(); the latter doesn't
actually cancel a range selection.

Introduce a new function specifically for collapsing the range after deleting
multiple items, so that clients don't need two calls (we'll add a bunch more in
this branch).
2025-07-04 17:18:10 +02:00
61ff8a4da8 Move to next stageable line when adding a line to a custom patch (#4675)
- **PR Description**

While it's true that the behavior is a little different from the staging
panel, where the staged lines are actually removed from the view and in
many cases the selection stays more or less in the same place, it is
still very useful to move to the next stageable thing in the custom
patch building view too.

Also, we change the visualization of what's included in the patch to
mark only the + and - lines of the patch; for all other lines it doesn't
make a difference whether they are included.

And finally, we make it so that only + and - lines are considered when
pressing space; previously it would also look at selected context lines,
which doesn't make much sense. This improves the experience for mouse
users who like to generously select hunks by dragging across them,
including some context lines above and below.
2025-07-04 10:16:45 +02:00
039831a27a Move to next stageable line after adding a line to a custom patch
While it's true that the behavior is a little different from the staging panel,
where the staged lines are actually removed from the view and in many cases the
selection stays more or less in the same place, it is still very useful to move
to the next stageable thing in the custom patch building view too.
2025-07-04 10:14:35 +02:00
ce9fbe58b2 Toggle only added/deleted lines in patch building view
This improves the experience when selecting a hunk generously with the mouse, by
dragging over it including some context lines above and below. Previously we
would consider the "moving end" of the selection range for whether things need
to be added or removed, but this doesn't make sense if it's a context line. Now
we consider the first actual change line that is included in the range.
2025-07-04 10:14:35 +02:00
ef1a141347 Export PatchLine.isChange 2025-07-04 10:14:35 +02:00
42bbe965fa Render only + and - lines as included in a patch
It is confusing to get header lines, hunk headers, or context lines rendered as
being included in a custom patch, when including these makes no difference to
the patch.

This is only a visual change; internally, we still record these non-patch lines
as being included in the patch. It doesn't matter though; you can press space on
a header line and nothing happens.

It would probably be cleaner to only record + and - lines in the includedLines
array, but that would be a bit more work, and doesn't seem worth it.
2025-07-04 10:14:35 +02:00
a8e98593ea Auto-stash modified files when cherry-picking or reverting commits (#4683)
- **PR Description**

For cherry-picking, this used to work in earlier versions, but it broke
in #4443. For reverting, it was never supported.

Also, we add some minor improvements while we're at it, such as slightly
better names for the auto-stashes that are created for the various
operations (so that, if an auto-stash pop fails and the stash is kept
around, you can tell more easily what it was for). Also, we now adjust
the selection of the commits list after cherry-picking, so that the same
commit stays selected.
2025-07-04 10:13:52 +02:00
6b1cab7011 Auto-stash if necessary when reverting commits 2025-07-03 17:04:10 +02:00
dc795b5db7 Remove unnecessary refresh
CheckMergeOrRebase calls Refresh already. However, it does an async refresh by
default, so we must turn this into a sync refresh so that moving the selection
down by one works even for the very first commit in history. Also, we must add
an explicit call to FocusLine so that the view selection is in sync with the
model selection; previously this was taken care of by the PostRefreshUpdate call
that happens as part of a refresh.
2025-07-03 17:04:10 +02:00
0fc107c8c1 Adjust selection after cherry-picking commits
Keep the same commit selected, by moving the selection down by the number of
cherry-picked commits. We also do this when reverting commits, and it is
possible now that we use a sync waiting status.

We also need to turn the refresh that happens as part of CheckMergeOrRebase into
a sync one, so that the commits list is up to date and the new selection isn't
clamped.
2025-07-03 17:04:10 +02:00
09a4e0b209 Add selection assertions to cherry-pick tests
We are about to change the selection behavior when cherry-picking, and it's good
to have tests that document in what way it changes in the next commit.
2025-07-03 16:58:56 +02:00
6479c52fb2 Use sync waiting status for cherry-picking
This reduces flicker of the Files panel in the case that an auto-stash needs to
be made.
2025-07-03 16:58:56 +02:00
3f3e942f60 Auto-stash if necessary when cherry-picking commits 2025-07-03 16:58:56 +02:00
e7cb469fd0 Remove unused text StashPrefix 2025-07-03 16:56:30 +02:00
9511ed9d2c Use a better name for the auto-stash for moving a custom patch to index 2025-07-03 16:56:30 +02:00
2a7ce19b73 Use a better name for the auto-stash for creating a new branch
For the case of creating a new branch by moving commits to it, we were using the
current (old) branch name in the stash name; change this to use the new name
instead.
2025-07-03 16:56:30 +02:00
908975c758 Use a better name for the auto-stash for checking out a branch 2025-07-03 16:53:49 +02:00
a83fc5e343 Use a better name for the auto-stash for undo 2025-07-03 16:53:49 +02:00
2c206c374d Use abbreviated hash in undo confirmations 2025-07-03 16:53:49 +02:00
50785a2217 Exclude vendor directory from linting
It seems to be excluded already when you run the lint.sh script, but in VS Code
when setting Lint on Save to package it would still lint a file in gocui when
you save it, which is annoying. (Remove the other paths that were there before;
they seem to be unused, and they were added by the auto-migration.)

Unfortunately, gopls will still lint gocui files with its builtin staticcheck
linter, and I couldn't find a way to turn this off. This might be a reason to
turn off staticcheck in gopls (not sure yet).
2025-07-03 16:39:52 +02:00
91d8c25183 Fix applying custom patches to a dirty working tree (#4674)
- **PR Description**

Applying or reverting a custom patch when one of the files contained in
the patch had unstaged modifications in the working tree would fail with
the confusing error message "does not match index", regardless of
whether those modifications conflicted with the patch or not. You would
expect this to just work if there are no conflicts, or to get the usual
conflict markers if there are. It was possible to work around this by
manually staging those files, but few people knew about this. Fix this
by staging the files (after asking for confirmation).

Also, fix a minor problem where an auto-stash for the "move patch to
index" command was forgotten to be dropped.
2025-07-02 16:32:32 +02:00
3df894ec92 Stage affected unstaged files when applying or reverting a patch
Unlike moving a patch to the index, applying or reverting a patch didn't
auto-stash, which means that applying a patch when there's a modified (but
unstaged) file in the working tree would error out with the message "error:
file1: does not match index", regardless of whether those modifications conflict
with the patch or not.

To fix this, we *could* add auto-stashing like we do for the "move patch to
index" command. However, in this case we rather simply stage the affected files
(after asking for confirmation). This has a few advantages:

- it only changes the staging state of those files that are contained in the
patch (whereas auto-stashing always changes all files to unstaged)
- it doesn't unnecessarily show a confirmation if none of the modified files are
affected by the patch
- if the patch conflicts with the modified files, the conflicts were "backwards"
("ours" was the patch, "theirs" the modified file); it is more logical if "ours"
is the current state of the file, and "theirs" is the patch.

It's a little unfortunate that the behavior isn't exactly the same as for "move
patch to index", but for that one we do need the auto-stash because of the
rebase that runs behind the scenes.
2025-07-02 16:19:06 +02:00
c440a208a6 Add tests for applying a patch when there's a modified file
The tests show that this currently fails with the confusing error message "does
not match index", regardless of whether the patch conflicts with the
modifications or not. We'll improve this in the next commit.

I don't bother adding tests for reverting a patch, as the code is basically the
same as for apply.
2025-07-02 16:19:06 +02:00
32bd9e6029 Drop stash when successfully unstashing files after moving patch to index 2025-07-02 16:19:06 +02:00
823aa640b9 Add test for moving patch to index when there's a modified file
This is functionality that works already, we only add the test for more complete
test coverage. However, there's a detail problem, and the test demonstrates
this: we keep the stash even if there was no conflict. We'll fix this next.
2025-07-02 16:19:06 +02:00
00d043d743 Cleanup: implement AllFilesInPatch using lo.Keys
Curiously, the function was never called so far, but we're going to use it later
in this branch.
2025-07-02 16:19:06 +02:00
eebc39d3e9 Show stash name for selected stash (#4673)
- **PR Description**

In the Stash panel, show information about the selected stash above the
diff of the stash in the main view. This is useful for stash entries
with very long names that are not fully visible in the Stash panel.

Fixes #4662.
2025-07-02 16:18:11 +02:00
92c9eb614f Show stash title in main view for selected stash entry 2025-07-02 16:15:19 +02:00
ef16867ff1 Cleanup: add NewRunPtyTaskWithPrefix funxtion instead of setting Prefix manually
This is consistent with NewRunCommandTaskWithPrefix.
2025-07-02 16:15:19 +02:00
edcfce22f0 Change Refresh to not return an error (#4680)
- **PR Description**

Refresh is one of those functions that shouldn't require error handling
(similar to triggering a redraw of the UI, see
https://github.com/jesseduffield/lazygit/issues/3887).
2025-07-02 16:14:11 +02:00
c87661dbee Use async refresh rather than manual OnWorker call
This is exactly what async refresh is for.
2025-07-02 16:10:04 +02:00
d82852a909 Change Refresh to not return an error
Refresh is one of those functions that shouldn't require error handling (similar
to triggering a redraw of the UI, see
https://github.com/jesseduffield/lazygit/issues/3887).

As far as I see, the only reason why Refresh can currently return an error is
that the Then function returns one. The actual refresh errors, e.g. from the git
calls that are made to fetch data, are already logged and swallowed. Most of the
Then functions do only UI stuff such as selecting a list item, and always return
nil; there's only one that can return an error (updating the rebase todo file in
LocalCommitsController.startInteractiveRebaseWithEdit); it's not a critical
error if this fails, it is only used for setting rebase todo items to "edit"
when you start an interactive rebase by pressing 'e' on a range selection of
commits. We simply log this error instead of returning it.
2025-07-02 16:09:42 +02:00
2b1f150129 Some code cleanups to the "discard file changes from commit" feature (#4679)
- **PR Description**

I ran into these issues while reading the code.
2025-07-02 16:02:58 +02:00
5be97c6145 Remove another unnecessary refresh
This was added after this PR comment:
https://github.com/jesseduffield/lazygit/pull/3276#discussion_r1469077611

> Can we do a refresh after this reset so that the screen shows that the patch
> has been cancelled? That way, if we cancel on the next popup, the screen will
> be in a valid state.

I don't understand what "cancel on the next popup" means; there is no further
popup after this code.
2025-07-02 15:58:03 +02:00
80e20417a8 Remove unnecessary refresh
CheckMergeOrRebase already calls Refresh.
2025-07-02 15:58:03 +02:00
ee62878e6b Cleanup: remove pointless error handling
ForEachFile can't possibly return an error if the passed function doesn't return
one.
2025-07-02 15:47:48 +02:00
2a5970265d Fix formatting of a keyboard shortcut in the README.md (#4678)
- **PR Description**

This will format the `z` keyboard shortcut reference in this text in the
same way as all other keyboard shortcuts in the README.md file.
2025-07-02 15:28:48 +02:00