1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-06-20 01:19:23 +02:00
Commit Graph

7240 Commits

Author SHA1 Message Date
Stefan Haller 5b829a6721 Add unit tests for WorkingTreeDiscard{All,Unstaged}DirChanges
We have integration tests for this functionality, but those only test the
behavior, not the performance. In these unit tests you can see that we make
individual calls to git checkout and git reset for each file, which is very slow
when there are lots of files.
2026-03-27 14:34:47 +01:00
Stefan Haller 4aa455e4eb Cleanup: better check for which files are removed
Previously it would only check that *if* removeFile was called, the passed
argument was the expected one; but it didn't check whether it was called at all.
Improve this by recording the file names that are removed, and checking them at
the end of each scenario.

This is going to be even more important for the tests that we are about to add
in the next commit, because for those there can be several calls to removeFile
in a single scenario.
2026-03-27 14:34:47 +01:00
Stefan Haller 4a8ab6f64e Cleanup: simplify by using lo.FilterMap instead of separate calls to Filter and Map 2026-03-27 14:34:47 +01:00
Stefan Haller 706a6c0474 Cleanup: use oscommands.RemoveFile rather than plain os.Remove
This makes it mockable for tests, and is consistent with other uses in this
file.
2026-03-27 14:34:47 +01:00
Stefan Haller d241ec4ee1 Fix searching commits or main view after switching repos (#5424)
When switching to a different repo, and then back to the original one,
searching would no longer work. The reason is that our contexts set
callbacks on their views; when switching to a different repo we
instantiate a new set of contexts, so they will overwrite the views'
callbacks with their new ones, but when switching back to the original
repo, we reuse the old contexts because they are still in memory, but
they won't set their callbacks again since they only do this on
construction.

To fix this, replace the view-local callbacks with a global one on the
gui that takes the view as an argument, so that the callback can look up
the associated context dynamically.
2026-03-27 14:30:31 +01:00
Stefan Haller 3eb5841b83 Fix searching commits or main view after switching repos
When switching to a different repo, and then back to the original one, searching
would no longer work. The reason is that our contexts set callbacks on their
views; when switching to a different repo we instantiate a new set of contexts,
so they will overwrite the views' callbacks with their new ones, but when
switching back to the original repo, we reuse the old contexts because they are
still in memory, but they won't set their callbacks again since they only do
this on construction.

To fix this, replace the view-local callbacks with a global one on the gui that
takes the view as an argument, so that the callback can look up the associated
context dynamically.
2026-03-27 14:26:20 +01:00
Stefan Haller 587a8bbf4f Remove go-git dependency (#5420)
Remove our dependency on go-git, which was including a ton of
third-party code for very little benefit.

In addition, this fixes the problem that lazygit wouldn't show any
branches or remotes for certain types of malformatted .git/config files,
e.g. when there's a config section like `[branch ""]`, `[remote ""]`, or
`[-remote "xyz"]`; see #3901 and #5112.
2026-03-27 14:13:03 +01:00
Stefan Haller 9d6064408c Remove go-git dependency 2026-03-27 14:08:08 +01:00
Stefan Haller a930f74397 Remove go-git repo from GitCommon
It is no longer used now.
2026-03-27 14:08:07 +01:00
Stefan Haller 6f9d234116 Remove go-git repo from ConfigCommands 2026-03-27 14:08:07 +01:00
Stefan Haller 1da87b9a7c Don't use go-git to parse branches
As with the previous commit, the code to parse `git config --get-regex` output
on our end isn't so bad.
2026-03-27 14:04:51 +01:00
Stefan Haller 23f973496f Don't use go-git to parse remotes
It only takes a few lines of code to parse remotes on our end from the output of
`git config --get-regexp`.
2026-03-27 14:00:58 +01:00
Stefan Haller d864edb0c3 Add support for clicking on arrows in the file list to expand/collapse directories (#5365)
### PR Description
This PR adds support for clicking on arrows in the file changes list
view, so that a mouse can be used to expand/collapse directories. This
enhancement was raised here as issue #5088.
2026-03-25 20:58:49 +01:00
blakemckeany ee3bb06b2a Add support for clicking on arrows in the file list to expand/collapse directories
Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
2026-03-25 17:08:35 +01:00
blakemckeany 4567840198 Add GetOnClick to HasKeybindings
Can be used for doing additional click handling in list views.

Like the GetOnDoubleClick hook we should try to find a better design for this
than putting it in HasKeybindings and BaseContext, since it is only used by list
contexts.

Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
2026-03-25 17:08:02 +01:00
blakemckeany 61b72cef38 Add GetVisualDepth method to FileTree/CommitFileTree 2026-03-25 16:41:12 +01:00
Stefan Haller fe5df2334b Document some of the methods of HasKeybindings
We have some documentation for the corresponding setters in IBaseContext, but
that's part of the controller infrastructure and not client facing. For somebody
implementing a new view, this is where they will probably look for what methods
they can override.
2026-03-25 16:41:10 +01:00
Stefan Haller 72bff90822 Rename GetOnClick (et al) to GetOnDoubleClick
When this was originally introduced, it handled single clicks on a list entry
(treating them similar to a double-click by checking whether the click was on
the selected entry). Arguably it should have been called OnDoubleClick back then
already; but when we later changed it to do actual double-click detection (see
37197b8e9a), we should have renamed the methods.
2026-03-25 14:58:53 +01:00
Stefan Haller dcfdf4084e Fix the expanded layout of the branches panel (half and full screen modes) (#5413)
If the showDivergenceFromBaseBranch config is not none, the expanded
branches panel would no longer show the remote branch and subject; the
reason was that we padded the name all the way to the right edge of the
view so that the divergence information is right-aligned.

To fix this, we simply don't right-align the divergence in half or full
screen mode. This is a bit unfortunate, but it's hard to do any better,
because we don't know the width of our column in advance. One thing I
tried is to make the divergence a separate column in that case (with an
explicit right-alignment set on it via getColumnAlignments; however,
this makes it harder to properly truncate the name when the window is
too narrow.
2026-03-23 17:31:10 +01:00
Stefan Haller d9487bf31c Fix the expanded layout of the branches panel (half and full screen modes)
If the showDivergenceFromBaseBranch config is not none, the expanded branches
panel would no longer show the remote branch and subject; the reason was that we
padded the name all the way to the right edge of the view so that the divergence
information is right-aligned.

To fix this, we simply don't right-align the divergence in half or full screen
mode. This is a bit unfortunate, but it's hard to do any better, because we
don't know the width of our column in advance. One thing I tried is to make the
divergence a separate column in that case (with an explicit right-alignment set
on it via getColumnAlignments; however, this makes it harder to properly
truncate the name when the window is too narrow.
2026-03-23 17:25:41 +01:00
Stefan Haller 24158aa6d0 Add a note about AI to CONTRIBUTING.md (#5404) 2026-03-23 14:22:19 +01:00
Stefan Haller 0093059949 Add a note about AI to CONTRIBUTING.md 2026-03-22 11:30:22 +01:00
Stefan Haller ec7d6b479a Fix staging only some lines of a block of consecutive changes (#5396)
Given a block of consecutive changed lines, staging only some of those
changes didn't always work. Consider the following scenario:
```diff
@@ -1,5 +1,5 @@
 a
-b
-c
-d
+b'
+c'
+d'
 e
```
Trying to stage only the change to "d" worked already as expected, but
staging either "b" or "c" didn't; the order of the deleted and added
lines in staged changes were wrong. We don't solve the "c" case in this
PR, as it's probably uncommon enough so that it doesn't matter too much,
and it seems to be quite a bit harder than the other two (and git gui
doesn't support it either, for the record). But we fix the "b" case
here, which is probably the most common one.

Fixes #5103.
2026-03-20 08:23:19 +01:00
Stefan Haller e1e042fb66 Revert test workaround
Now that the bug with selecting the next stageable line is fixed, we can go back
to the original, simpler way of expressing the test.
2026-03-19 16:57:53 +01:00
Stefan Haller 6bfcab3d89 Fix selection after staging an added line
In some cases, staging an added line could result in the previous deleted line
to become selected, rather than the next added line.
2026-03-19 16:57:53 +01:00
Stefan Haller 8fbc70bf84 Fix staging only some lines of a block of consecutive changes
This fixes the problem; a consequence of this change is that given the following
scenario:

@@ -1,3 +1,3 @@
 1
-2
+2b
 3

staging only the line `+2b` will put it *before* the unchanged `2` line, rather
than after it as you might expect (the changed unit tests demonstrate this).
Since this should be a pretty uncommon scenario, I guess it is an ok compromise.

As you can see in the changed tests, while the behavior of what gets staged is
fixed now, it doesn't always correctly select the next line to stage. We'll
address this in the next commit.
2026-03-19 16:57:53 +01:00
Stefan Haller b8ed4faf9b Add test for how the selection advances after staging lines
This is currently working correctly, but will break with the next commit; we'll
fix this again afterwards.
2026-03-19 16:44:55 +01:00
Stefan Haller 7929519ccf Add regression test for staging a single added line
This is a pretty special case (see comment in the test for details). It is
working correctly, but I almost broke it during development, so it's good to
cover it with a test.
2026-03-19 16:44:55 +01:00
Stefan Haller b95bfeb164 Add test demonstrating problem with staging only some changed lines
Given a block of consecutive changed lines, trying to stage only some of them
doesn't work correctly in all cases:

- if the staged lines are the last lines in the block of changes, it already
  works
- when staging some changes in the middle of the block, it doesn't work as
  desired, but we also don't try to fix this case in this branch, because it's
  harder to do, and not as common as the other two
- staging the first lines of the block doesn't work as desired, and we will fix
  that in this branch.
2026-03-19 16:44:55 +01:00
Stefan Haller 2f6d20275a Update docs and schema for release (#5353) v0.60.0 2026-03-09 20:49:23 +01:00
Stefan Haller f63f82bd4d Update docs and schema for release 2026-03-09 19:53:24 +01:00
Stefan Haller 487df128e2 Update translations from Crowdin (#5352) 2026-03-09 19:52:33 +01:00
Stefan Haller 327c76ffbb Update translations from Crowdin 2026-03-09 19:49:46 +01:00
Stefan Haller 43fa7a499e Fix diff display of custom pagers after screen mode change (#5349)
We need to re-render the main view after a screen mode change, in case a
custom pager is being used and its output depends on the window width.
2026-03-09 19:44:37 +01:00
Stefan Haller 5b23f80398 Re-render main view when changing screen mode
This is needed for diffs in case a custom pager is used and its output depends
on the window width (e.g. the horizontal lines in delta).
2026-03-09 19:42:28 +01:00
Stefan Haller 46c53ea34f Cleanup: use CurrentSide() instead of private currentSidePanel
They both do the same.
2026-03-09 19:42:28 +01:00
Stefan Haller b05e33df89 Show worktree name next to branch in branches list (#5340)
### PR Description

When a branch is checked out by another worktree, show the worktree name
in the label, e.g. "(worktree cosmos2)" instead of just "(worktree)", so
you can immediately see which worktree holds it.
2026-03-09 11:58:28 +01:00
Ruud Kamphuis 6ad56d5852 Show worktree name next to branch in branches list
When a branch is checked out by another worktree, show the worktree
name in the label, e.g. "(worktree cosmos2)" instead of just
"(worktree)", so you can immediately see which worktree holds it.
2026-03-09 11:34:34 +01:00
Stefan Haller 4c7323b255 README.md: Update Sponsors (#5228)
Automated changes by
[create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action
2026-03-08 17:56:24 +01:00
github-actions[bot] bce1ca58bd README.md: Update Sponsors 2026-03-08 16:53:40 +00:00
Stefan Haller 7ec8c9c0d1 Enable { and } to change diff context size in branches and tags panels in diffing mode (#5258)
When looking at a diff in diffing mode in the branches or tags panels
(e.g. after pressing `W` on a branch and then selecting a different
branch to diff it against the first one) it wasn't possible to change
the diff context size using `{` and `}`, or the rename threshold using
`(` and `)`.

Fixes #5254.
2026-03-08 17:53:30 +01:00
Stefan Haller 9dd121dfa3 Enable { and } to change diff context size in branches and tags panels in diffing mode
Actually, we simply enable them in any panel, even those that can never show a
diff. Since the commands show a toast, that's enough feedback to understand what
happened; the change will take effect the next time you switch to a panel that
does show diffs.

Same for ( and ) to change the rename threshold.
2026-03-08 17:51:00 +01:00
Stefan Haller 17e7044d7c Properly disable clicks in inactive views behind popups (#5313)
We did already have code to prevent clicks in inactive views behind a
popup, but it wasn't good enough. This PR fixes two problems:
- if the previously focused view (behind the panel) was a list view, it
would look like the click would select a different row, because gocui
would still set the view's cursor position, which is used to draw the
highlighted row
- it was still possible to click on tab headers, and this would dismiss
the panel

Fixes #5256.
2026-03-08 17:39:51 +01:00
Stefan Haller b955002d17 Use new ShouldHandleMouseEvent hook to prevent clicks in views behind panels
This fixes two problems:
- if the previously focused view (behind the panel) was a list view, it would
  look like the click would select a different row, because gocui would still
  set the view's cursor position, which is used to draw the highlighted row
- it was still possible to click on tab headers, and this would dismiss the
  panel
2026-03-08 17:32:09 +01:00
Stefan Haller ab86b42eec Bump gocui 2026-03-08 17:31:57 +01:00
Stefan Haller 4d08c8149e Fix off-by-one error when calculating popup panel dimensions (#5312)
The symptom of the bug was that confirmation panels with wrapped text
were one character too wide, which could sometimes result in them being
one line too heigh. One concrete example is the "Discard file changes"
confirmation that appears when pressing `d` in the commit files panel.
2026-03-08 17:27:52 +01:00
Stefan Haller da065b5b63 Add comments
I got confused when I investigated the bug that was fixed in the previous
commit, so hopefully these will be helpful for the next person reading this
code.
2026-03-08 17:24:26 +01:00
Stefan Haller bcfb4e11c0 Fix off-by-one error when calculating popup panel dimensions
The symptom of the bug was that confirmation panels with wrapped text were one
character too wide, which could sometimes result in them being one line too
heigh. One concrete example is the "Discard file changes" confirmation that
appears when pressing `d` in the commit files panel.

I got very confused when investigating this bug, and the reason is that
getPopupPanelDimensionsAux took two parameters panelWidth and panelHeight, but
the second was actually contentHeight. Rename it to contentHeight, and change
the first one to also be the content width rather than the panel width. This is
easier for clients, and less confusing.
2026-03-08 17:24:26 +01:00
Stefan Haller d8f87c6919 Add backward cycling support for log view (using <shift>-a on status page) (#5346)
This commit implements the ability to cycle backward through different
all branches log visualization modes, complementing the existing forward
cycling functionality. Users can now press 'A' (Shift+a) to cycle in
reverse through the available log graph views, improving navigation
efficiency when they overshoot their desired view.
2026-03-08 17:09:31 +01:00
Zak Siddiqui 7d32e45f73 Add backward cycling support for all branches log view
This commit implements the ability to cycle backward through different
all branches log visualization modes, complementing the existing forward
cycling functionality. Users can now press 'A' (Shift+a) to cycle in
reverse through the available log graph views, improving navigation
efficiency when they overshoot their desired view.

Changes:
- Added RotateAllBranchesLogIdxBackward() method to BranchCommands for
  backward rotation through log command candidates
- Introduced AllBranchesLogGraphReverse keybinding configuration with
  default key 'A' (uppercase)
- Implemented switchToOrRotateAllBranchesLogsBackward() handler in
  StatusController that mirrors forward cycling logic
- Added English translation for "Show/cycle all branch logs (reverse)"

The implementation uses modulo arithmetic with proper handling of
negative indices to ensure seamless backward cycling through the
available log visualization options.
2026-03-08 17:06:17 +01:00