1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-02 23:27:32 +02:00

6435 Commits

Author SHA1 Message Date
Stefan Haller
9caed72fc9 [SQUASHED] fixup-upwards 2025-05-11 14:03:40 +02:00
Stefan Haller
5d30409f33
Add an alternate keybinding (default <c-s>) for ConfirmInEditor (#4532)
- **PR Description**

The default binding for ConfirmInEditor is <a-enter>, which has two
problems:
- some terminal emulators don't support it, including the default
terminal on Mac (Terminal.app)
- on Windows it is bound to toggling full-screen

Ideally we would use `<c-enter>` instead (and Command-Enter on Mac), but
neither is possible without https://github.com/gdamore/tcell/issues/671,
so for the time being add an alternate keybinding which works
everywhere.

Show both bindings in the footer of the commit description panel if they
are both non-null. While we're at it, fix the footer for the case where
either or both of the keybindings are set to `<disabled>`.

And finally, change "commit" to "submit" in that footer; we use the same
panel also for creating tags, in which case "commit" is not quite right.
2025-05-11 14:01:27 +02:00
Stefan Haller
450239d5c8 Add an alternate keybinding (default <c-s>) for ConfirmInEditor
The default binding for ConfirmInEditor is <a-enter>, which has two problems:
- some terminal emulators don't support it, including the default terminal on
  Mac (Terminal.app)
- on Windows it is bound to toggling full-screen

Ideally we would use <c-enter> instead (and Command-Enter on Mac), but neither
is possible without https://github.com/gdamore/tcell/issues/671, so for the time
being add an alternate keybinding which works everywhere.

Show both bindings in the footer of the commit description panel if they are
both non-null. While we're at it, fix the footer for the case where either or
both of the keybindings are set to <disabled>.

And finally, change "commit" to "submit" in that footer; we use the same panel
also for creating tags, in which case "commit" is not quite right.
2025-05-11 13:59:22 +02:00
Stefan Haller
c3081ef02e
Make '>' first jump to the beginning of the branch, and only then to the first commit (#4544)
- **PR Description**

In longer branches there's often the need to jump to the beginning of
the branch, e.g. in order to re-review all commits from the beginning.
There's no easy way to do this in lazygit.

In this PR I overload the "go to bottom" key (`>`) to jump to the first
commit of the current branch if the selection is above it, and only then
jump to the very bottom. I like that we don't need to introduce a new
key binding for this.
2025-05-11 13:59:02 +02:00
Stefan Haller
636b94cf22 Make '>' first jump to the beginning of the branch, and only then to the first commit 2025-05-11 13:55:43 +02:00
Stefan Haller
1a880f916c Remove unused keybinding handler
It's never called, the binding ListController.HandleGotoBottom wins.

The functionality of loading more commits is implemented by GetOnFocus, and this
way it works not only for '>', but also for other navigation keys like page
down.
2025-05-11 13:55:43 +02:00
Stefan Haller
a27db87fb6
Add custom patch command "Move patch into new commit before the original commit" (#4552)
- **PR Description**

This is often useful to extract preparatory refactoring commits from a
bigger one. It works best when selecting only entire hunks or even
entire files; if partial hunks are in the patch, you are likely to get
conflicts.

Along the way, fix rewording merge commits. (Not because I find this
super important, but just because I came across the code while working
on this.)

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [x] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2025-05-11 13:55:19 +02:00
Stefan Haller
f6d13330dd Add custom patch command "Move patch into new commit before the original commit"
This is often useful to extract preparatory refactoring commits from a bigger
one.
2025-05-10 18:57:28 +02:00
Stefan Haller
5321101276 Use 'break' instead of 'edit' for BeginInteractiveRebaseForCommit with merge commit
BeginInteractiveRebaseForCommit is used for all the patch commands, and for
rewording. It works by setting the commit we want to stop at to 'edit'; this
doesn't work for merge commits. This wasn't a problem for the patch commands so
far, because you typically don't use custom patches with merge commits (although
we don't prevent this; maybe we should?).

However, it was a problem when you tried to reword a merge commit; this
previously failed with an error, as the test added in the previous commit
demonstrated.

Also, we want to add a new patch command that has to stop *before* the selected
commit (pull patch to new commit before the original one), and this wouldn't
work for the first commit in a feature branch, because it would have to set the
last commit before that to 'edit', which isn't possible if that's a merge (which
is likely).

To fix all this, use a 'break' before the selected commit if the commit is a
merge. It is important that we only do it in that case and not always, otherwise
we would break the new regression tests that were added a few commits ago.
2025-05-10 18:44:31 +02:00
Stefan Haller
50b2aa5843 Add test for rewording a merge commit
This currently fails with an error.
2025-05-10 18:19:35 +02:00
Stefan Haller
b02441cdca Regression test for moving custom patch to new commit from last commit of a stacked branch
I almost broke this during the development of this branch, so add a test to
guard against that. The point here is that the stack remains intact, i.e. the
newly created commit is the last commit of the lower branch, and thus shows the
"*".
2025-05-10 18:19:35 +02:00
Stefan Haller
0c0f95168c Regression test for renaming the last commit of a stacked branch
I almost broke this during the development of this branch, so add a test to
guard against that. The point here is that the stack remains intact, i.e. the
renamed commit is the head of the lower branch, and thus shows the "*".
2025-05-10 18:19:09 +02:00
Stefan Haller
200b34ff28 Shorten commit hash in custom patch menu 2025-05-10 18:15:42 +02:00
Stefan Haller
144565ee03 Cleanup: remove unnecessary setup steps 2025-05-10 18:15:42 +02:00
Stefan Haller
ef1da6f704
reword documentation for git.autoForwardBranches (#4545)
- **PR Description**

The wording "lazygit will automatically forward branches to their
upstream after fetching" could be interpreted to mean that lazygit
automatically pushes branches, rather than operating locally. Edited to
make the behavior more clear.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [ ] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [x] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc

<!--
Be sure to name your PR with an imperative e.g. 'Add worktrees view'
see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for
examples
-->
2025-05-09 08:48:02 +02:00
sean simonsen
4e497eef8a
reword documentation for git.autoForwardBranches 2025-05-08 16:37:26 -04:00
Stefan Haller
e6bd9d0ae6
Migrate deprecated AllBranchesLogCmd to AllBranchesLogCmds (#4345)
- **PR Description**

Fixes https://github.com/jesseduffield/lazygit/issues/3961

Their issue where the default `allBranchesLogCmd` default remains
present is because we just do a `lo.Uniq(lo.WithoutEmpty())` on the
combined list of `allBranchesLogCmd` and `allBranchesLogCmds`.

At the point of this code, it is not possible to tell whether the value
present in `allBranchesLogCmd` is user-provided or not. We have already
merged the config with the default config, so the user not setting
anything, and the user explicitly setting "Yes, I want the default", are
indistinguishable.

Based on that bug report, I'm assuming that users that have not set
anything for `allBranchesLogCmd`, but _have_ set something for
`allBranchesLogCmds`, just want the list they have specified in the
plural version. Some users have likely figured out they can explicitly
set `allBranchesLogCmd: ""` to get this behavior, but most would not.

To achieve this desired behavior, I figure it is easiest to just migrate
all user config to `allBranchesLogCmds`. If they have explicitly set a
non-empty value in `allBranchesLogCmd`, it will be pulled over. If they
set an empty string, it will be excluded.

- **Please check if the PR fulfills these requirements**

* [X] Cheatsheets are up-to-date (run `go generate ./...`)
* [X] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [X] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [X] Docs have been updated if necessary
* [X] You've read through your own file changes for silly mistakes etc
2025-05-07 10:12:36 +02:00
Chris McDonnell
1028f8efb8 Migrate deprecated AllBranchesLogCmd to AllBranchesLogCmds
This solves https://github.com/jesseduffield/lazygit/issues/3961 because
we no longer have a combination of the default and the user defined
list. We just have the user defined list.
2025-05-06 23:33:17 -04:00
Stefan Haller
c16c9f982f
Clean up utils package (#4538)
- **PR Description**

The utils package is a bit of a heterogeneous bag of miscellaneous
things at different abstraction levels right now; ideally it should only
contain low-level utilities similar to the helpers in utils/slice.go.
Further cleanup is possible here, e.g. something like rebase_todo.go
shouldn't be in this utils package. This PR doesn't address that,
however.

The goal of this PR is just to make it possible to import utils from any
other package. Previously it wasn't possible to import it from config,
because some of the stuff in utils depended on the config package. So
here we move only those things to better places. See the individual
commit messages for details.
2025-05-06 13:07:30 +02:00
Stefan Haller
252dda5220 Move Loader to presentation package
It is very gui specific and shouldn't be in a low-level utils package.
2025-05-06 09:52:53 +02:00
Stefan Haller
a6a68778ea Move NewDummyCommon to pkg/common
It's too special for a utils package, and it als makes sense to put it right
next to the thing that it is a dummy for.
2025-05-06 09:43:26 +02:00
Stefan Haller
223978eb82
Clean up the configuration of where a custom command's output goes (#4525)
- **PR Description**

Previously, custom commands had a `stream` field that was overloaded
with two meanings: 1) it made the command's output appear in the log
view, and 2) it used a pty for running the command. It makes sense to be
able to configure these independently, so add a separate `pty` field
(although that's probably rarely needed in practice).

Also, the `stream` and `showOutput` fields were conflicting; they could
be used together, but when setting them both to true, the popup would
always show "empty output", so this doesn't make sense. Combine them
both into a single `output` property with the possible values "none",
"log", or "popup".

We still have some more redundancy here, for example pty is only used
when output is set to "log", and neither output nor pty are used when
subprocess is true. But I stopped there, because I think this is already
an improvement over the previous state.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [x] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [x] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2025-05-05 17:49:21 +02:00
Stefan Haller
e8d365f1aa Add breaking change notice about 'stream: true' being converted to not use a pty any more 2025-05-01 16:09:10 +02:00
Stefan Haller
a9f9dee30d Combine customCommand's subprocess, stream, and showOutput fields into a single output enum 2025-05-01 15:46:06 +02:00
Stefan Haller
5f4be3bfb7 Add yaml_utils.RemoveKey
Co-authored-by: Chris McDonnell <c.a.mcdonn@gmail.com>
2025-05-01 15:21:37 +02:00
Stefan Haller
02611dad7c Remove unused function UpdateYamlValue 2025-05-01 15:21:37 +02:00
Stefan Haller
a199ed1396 Add separate UsePty flag for CmdObj
This decouples StreamOutput from whether a PTY is used. In most cases we just
want to see the output in the log window, but don't have to use a PTY, e.g. for
the bisect commands.

This has the implication that custom commands that are using "stream: true" no
longer use a PTY. In most cases that's probably a good thing, but we're going to
add a separate pty config for those who really wanted this.
2025-05-01 15:21:37 +02:00
Stefan Haller
8cf617b683 Rename getCmdHandler to getCmdHandlerPty, and add getCmdHandlerNonPty
getCmdHandlerNonPty is defined for all platforms.
2025-05-01 15:21:37 +02:00
Stefan Haller
a400ef0079 Remove ICmdObj interface
It is only implemented by *CmdObj, so use that directly in client code.
2025-05-01 15:21:37 +02:00
Stefan Haller
4e3d09e9d8 Validate custom commands in sub menus 2025-05-01 15:21:27 +02:00
Stefan Haller
e295477951 Add test demonstrating missing validation for custom commands in sub menus
We only validate the commands at top level right now.
2025-04-30 17:41:49 +02:00
Stefan Haller
7137196788 Add comments in tests to explain what they test
Looking at these again, I needed a moment to remember what they do, so make this
more obvious to help future readers.
2025-04-30 17:31:58 +02:00
Stefan Haller
66caa25dcd
Reduce memory consumption of graph (pipe sets) (#4498)
- **PR Description**

As a followup to #2533, reduce the memory consumption some more by
optimizing the storage of the pipe sets used for the commit graph.

Some coarse measurements (taken by opening the respective repo, typing
`4 >`, and waiting for all commits to be loaded, and then reading the
Memory column in Activity Monitor):

|               | master  | this PR |
| ------------- | ------- | ------- |
| git           | 2.5 GB  | 1.0 GB  |
| our work repo | 2.3 GB  | 1.3 GB  |
| linux kernel  | 94.8 GB | 38.0 GB |

It's still not really usable for the linux kernel, but for all other
repos that I come across in my daily use of lazygit, it works quite well
now.
v0.50.0
2025-04-29 14:59:42 +02:00
Stefan Haller
6ca627d9d7 Store fromPos/toPos as 16-bit ints, and reorder fields for better packing
Hopefully, graphs will never get wider than 32768 characters. (They would get
kind of hard to navigate if they did...)

This reduces the size of the Pipe struct from 48 to 32 bytes, which makes a
significant difference when there are many millions of instances.
2025-04-29 14:57:15 +02:00
Stefan Haller
e63abf89db Store TextStyle in Pipe struct as pointer
The instances are held by the AuthorStyle cache.
2025-04-29 14:57:15 +02:00
Stefan Haller
28aa26f30a Store Pipe objects by value in slice of Pipes
This saves some memory at the cost of a slight performance increase (I suppose
reallocting the slice when adding new Pipes is slightly more expensive now).

Performance of the BenchmarkRenderCommitGraph benchmark is 130μs before, 175μs
after. I'm guessing this is still acceptable.
2025-04-29 14:57:15 +02:00
Stefan Haller
18e5b0a650 Simplify equalHashes
Now that all hashes that we deal with are stored in the same pool, we can simply
compare their addresses.
2025-04-29 14:57:15 +02:00
Stefan Haller
13c21365c0 Store fromHash/toHash in Pipe struct as pointers
Now that commit hashes are stored in a pool and referenced by pointer by the
commits, we can use those same pointers in the pipes.
2025-04-29 14:57:15 +02:00
Stefan Haller
8d834e2eab Pack the models.Commit struct a little tighter
Change the base type of some of our enums from int to uint8, and reorder fields
for better packing. This reduces the size of models.Commit from 152 to 132 bytes
on my machine.

This doesn't improve overall memory usage significantly, but why not save a
little bit of memory if it's easy.
2025-04-29 14:57:15 +02:00
Stefan Haller
722cc85508 Store Commit.Parents in the pool too
We need to pass %P instead of %p in the format string of the git log command, so
that the parent hashes have the full length and can be shared with the real
hashes.
2025-04-29 14:57:15 +02:00
Stefan Haller
0f1f455edb Make Commit.Parents a getter for an unexported parents field
This is exactly the same as what we did for Hash earlier. And for the same
reason: we want to turn the parents field into a slice of pointers.
2025-04-29 14:57:15 +02:00
Stefan Haller
e27bc15bbd Store Commit.Hash by pointer (kept in a pool of hashes)
This in itself is not an improvement, because hashes are unique (they are shared
between real commits and rebase todos, but there are so few of those that it
doesn't matter). However, it becomes an improvement once we also store parent
hashes in the same pool; but the real motivation for this change is to also
reuse the hash pointers in Pipe objects later in the branch. This will be a big
win because in a merge-heavy git repo there are many more Pipe instances than
commits.
2025-04-29 14:57:15 +02:00
Stefan Haller
1037371a44 Make Commit.Hash a getter for an unexported hash field
This is in preparation for turning the hash into pointer to a string.
2025-04-29 14:57:15 +02:00
Stefan Haller
97aa7a04e6 Rewrite generateCommits to avoid write access to commit.Parents
We want to unexport Parents in a later commit.
2025-04-29 14:57:15 +02:00
Stefan Haller
5844ec6eb2 Cleanup: use IsMerge instead of counting Parents 2025-04-29 14:57:15 +02:00
Stefan Haller
cb0c8f39bf Simplify code and fix comment
The "// merge commit" comment was plain wrong, this is any commit that has a
parent, merge or not. The "else if" condition was unnecessary, a plain "else"
would have been enough. But the code in the two blocks was almost identical, so
extract the one thing that was different and unify it.

And while we're at it, use IsFirstCommit() instead of counting parents.
2025-04-29 14:57:15 +02:00
Stefan Haller
5b109b2dd6 Fix confusing variable name
These are not the expected commits.
2025-04-29 14:57:15 +02:00
Stefan Haller
9d202cf9ea Remove unused function 2025-04-29 14:57:15 +02:00
Stefan Haller
4cfa6e0c98 Modernize benchmarks
See https://go.dev/blog/testing-b-loop
2025-04-29 14:57:15 +02:00
Stefan Haller
14eb4c29ca Bump git-todo-parser 2025-04-29 14:57:15 +02:00