1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-21 04:25:53 +03:00

216 Commits

Author SHA1 Message Date
Chris McDonnell
d39f883b4e Migrate to only doing marshalling twice, and compare via deep copy 2025-02-27 17:05:31 -05:00
Stefan Haller
87c3e75811 Use indentation of 2 when rewriting auto-migrated config file
This seems to be what most people use when indenting yaml files, and it seems to
make more sense than the default of 4.

We also use it the example config in Config.md.
2025-02-23 11:32:12 +01:00
Stefan Haller
e5137b86cf Add a tabWidth parameter to WrapViewLinesToWidth to match gocui 2025-02-20 09:13:56 +01:00
Chris McDonnell
2fa4ee2cac feat: Support multiple commit prefixes
This implementation, unlike that proposed in https://github.com/jesseduffield/lazygit/pull/4253
keeps the yaml schema easy, and does a migration from the single
elements to a sequence of elements.
2025-02-17 19:58:31 +01:00
Stefan Haller
20d0b4316d Only avoid the blank line at end of view if view is not editable
For editable views it is important to actually show the blank line so that we
can put the cursor there for typing.

This fixes problems with adding blank lines at the end of longer commit
messages.
2025-01-20 17:52:53 +01:00
Stefan Haller
ae53059ed2 Bump gocui
This updates gocui to include https://github.com/jesseduffield/gocui/pull/68 and
https://github.com/jesseduffield/gocui/pull/69, which changes views to not have
an extra blank line at the end when content ending in a newline character is
written to them. This makes text views more consistent with list views, which
don't have a blank line after the last list entry either.
2025-01-07 17:34:30 +01:00
Stefan Haller
b7444b9a49 Return arrays with line indices from WrapViewLinesToWidth
This makes it easy to convert an original line index to a wrapped line index, or
vice versa.
2024-12-23 12:24:09 +01:00
Stefan Haller
5d3b3c6656 Extract helper function
This doesn't improve the code much in the current state, but we'll add some more
code to this helper function in the next commit, which makes it worth it.
2024-12-23 12:24:09 +01:00
Stefan Haller
65a28c4c3b Convert tabs to spaces in WrapViewLinesToWidth
We haven't needed this before since we were only using the function for text in
confirmations and menus, which is unlikely to contain tabs. We are going to use
it for patches in the staging view though, which often do.
2024-12-23 12:24:09 +01:00
Stefan Haller
1f2cb35cc9 Refactor: move wrapMessageToWidth to utils/lines.go
to make it more generally usable by clients other than ConfirmationHelper, which
we will do later in this branch. Rename it to WrapViewLinesToWidth while we're
at it.

Add tests; in particular, add a sanity check that we wrap lines the same way as
gocui does. The tests that are added here are the same ones as in gocui for its
lineWrap function, but we'll extend them a bit in later commits in this branch.
2024-12-23 12:24:09 +01:00
Stefan Haller
a9ef69b9c7 Fix moving a commit across a branch boundary in a stack
See the previous commit for a detailed explanation.
2024-12-23 12:18:48 +01:00
Stefan Haller
83356d441f Fix moving a commit across an exec todo 2024-12-23 12:18:48 +01:00
Stefan Haller
49c50fc95c Add tests for moving across an exec todo
These don't work correctly yet, they move it one too far.
2024-12-23 12:18:48 +01:00
Stefan Haller
b719dc4d8e Add tests for moving a commit across an update-ref todo
This works correctly, we just didn't have test coverage for it.
2024-12-23 12:18:48 +01:00
Stefan Haller
078445db63 Allow deleting a merge commit
For non-merge commits we change "pick" to "drop" when we delete them. We do this
so that we can use the same code for dropping a commit no matter whether we are
in an interactive rebase or not. (If we aren't, we could just as well delete the
pick line from the todo list instead of setting it to "drop", but if we are, it
is better to keep the line around so that the user can change it back to "pick"
if they change their mind.)

However, merge commits can't be changed to "drop", so we have to delete them
from the todo file. We add a new daemon instruction that does this.

We still don't allow deleting a merge commit from within an interactive rebase.
The reason is that we don't show the "label" and "reset" todos in lazygit, so
deleting a merge commit would leave the commits from the branch that is being
merged in the list as "pick" commits, with no indication that they are going to
be dropped because they are on a different branch, and the merge commit that
would have brought them in is gone. This could be very confusing.
2024-12-23 12:12:45 +01:00
Stefan Haller
64eb3d560b Simplify finding rebase todos
One of the comments we are deleting here said:

  // Comparing just the hash is not enough; we need to compare both the
  // action and the hash, as the hash could appear multiple times (e.g. in a
  // pick and later in a merge).

I don't remember what I was thinking when I wrote this code, but it's nonsense
of course. Maybe I was thinking that the hash that appears in a "merge" todo
would be the hash of the commit that is being merged in (which would then
actually appear in an earlier pick), but it isn't, it's the hash of the merge
commit itself (so that the rebase can reuse its commit message). Which means
that hashes are unique, no need to compare the action.
2024-12-23 12:12:45 +01:00
Stefan Haller
2823a7cff0 Make equalHash more correct
So far it didn't have to handle the case where one hash is empty and the other
isn't, but in the next commit we need that, so let's handle that case correctly.
There's enough logic in the function now that it's worth covering it with tests.
2024-12-23 12:12:45 +01:00
Stefan Haller
696e78fcc8 Fix ForEachLineInFile to not lose the last line if it doesn't end with a LF 2024-10-09 15:37:08 +02:00
Stefan Haller
72cf3efb1d Add test demonstrating problem with ForEachLineInFile
The function drops the last line if it doesn't end with a line feed.
2024-10-09 15:36:02 +02:00
Stefan Haller
ae610dcbb7 Extract helper function for easier testing 2024-10-09 15:08:01 +02:00
Stefan Haller
42c157a5e6 Add changeToFixup field to MoveFixupCommitDown 2024-09-15 11:19:39 +02:00
Stefan Haller
e675025411 Return nil columnPositions when not rendering anything
... instead of returning a slice with a single [0] element. This makes it easier
to check whether we have columnPositions.
2024-08-24 10:51:25 +02:00
Stefan Haller
b411897a5a Fix Decolorise to also strip hyperlinks
This is needed so that the information view is correctly aligned when we add
hyperlinks to it.
2024-08-24 10:36:01 +02:00
Stefan Haller
fd8e480363 Re-determine existing main branches if mainBranches config changed 2024-08-18 10:24:52 +02:00
Stefan Haller
f98b57aa5e Change direct access to Common.UserConfig to a getter
This will allow us to turn the field into an atomic.Value for safe concurrent
access.
2024-08-18 10:24:52 +02:00
Stefan Haller
98e5fd70fb Remove non-English translation sets, read them from JSON instead 2024-06-23 14:47:50 +02:00
Stefan Haller
26132cf5bd Use utils.StringWidth to optimize rendering performance
runewidth.StringWidth is an expensive call, even if the input string is pure
ASCII. Improve this by providing a wrapper that short-circuits the call to len
if the input is ASCII.

Benchmark results show that for non-ASCII strings it makes no noticable
difference, but for ASCII strings it provides a more than 200x speedup.

BenchmarkStringWidthAsciiOriginal-10            718135       1637 ns/op
BenchmarkStringWidthAsciiOptimized-10        159197538          7.545 ns/op
BenchmarkStringWidthNonAsciiOriginal-10         486290       2391 ns/op
BenchmarkStringWidthNonAsciiOptimized-10        502286       2383 ns/op
2024-06-23 13:10:48 +02:00
Stefan Haller
93af0016f7 Use actual ellipsis character instead of ... to truncate strings
Space is scarce in lazygit's UI, and using ... wastes a lot of it.
2024-06-23 12:25:28 +02:00
Jesse Duffield
fdff2dec79 Remove redundant variable dedeclarations
In go 1.22, loop variables are redeclared with each iteration of the
loop, rather than simple updated on each iteration. This means that we
no longer need to manually redeclare variables when they're closed over
by a function.
2024-05-19 16:38:21 +10:00
Stefan Haller
66d0ce841c Implement ScanLinesAndTruncateWhenLongerThanBuffer 2024-05-15 13:27:01 +02:00
ChengenH
dd6bfa1680 chore: use errors.New to replace fmt.Errorf with no parameters. 2024-04-24 16:21:34 +08:00
Stefan Haller
8b99a3c949 Drop update-ref commands at the top of the rebase-todo file
The rebase.updateRefs feature of git is very useful to rebase a stack of
branches and keep everything nicely stacked; however, it is usually in the way
when you make a copy of a branch and want to rebase it "away" from the original
branch in some way or other. For example, the original branch might sit on main,
and you want to rebase the copy onto devel to see if things still compile there.
Or you want to do some heavy history rewriting experiments on the copy, but keep
the original branch in case the experiments fail. Or you want to split a branch
in two because it contains two unrelated sets of changes; so you make a copy,
and drop half of the commits from the copy, then check out the original branch
and drop the other half of the commits from it.

In all these cases, git's updateRefs feature insists on moving the original
branch along with the copy in the first rebase that you make on the copy. I
think this is a bug in git, it should create update-ref todos only for branches
that point into the middle of your branch (because only then do they form a
stack), not when they point at the head (because then it's a copy). I had a long
discussion about this on the git mailing list [1], but people either don't agree
or don't care enough.

So we fix this on our side: whenever we start a rebase for whatever reason, be
it interactive, non-interactive, or behind-the-scenes, we drop any update-ref
todos that are at the very top of the todo list, which fixes all the
above-mentioned scenarios nicely.

I will admit that there's one scenario where git's behavior is the desired one,
and the fix in this PR makes it worse: when you create a new branch off of an
existing one, with the intention of creating a stack of branches, but before you
make the first commit on the new branch you realize some problem with the first
branch (e.g. a commit that needs to be reworded or dropped). It this case you do
want both branches to be affected by the change. In my experience this scenario
is much rarer than the other ones that I described above, and it's also much
easier to recover from: just check out the other branch again and hard-reset it
to the rebased one.

[1]
https://public-inbox.org/git/354f9fed-567f-42c8-9da9-148a5e223022@haller-berlin.de/
2024-04-22 20:59:15 +02:00
Stefan Haller
7270dea48d Switch git-todo-parser from fsmiamoto original repo to stefanhaller's fork
Sometimes it takes a while to get PRs accepted upstream, and this blocks our
progress. Since I'm pretty much the only one making changes there anyway, it
makes sense to point to my fork directly.
2024-04-22 20:59:15 +02:00
Brandon
ef99e47d09 Fix amend to operation not working with non-HEAD merge commit 2024-04-22 08:48:59 -07:00
pikomonde
170c4ecb8c rename sha to hash 9, case: Sha 2024-04-12 08:33:47 +02:00
pikomonde
de1c495704 rename sha to hash 8, update some log and comment 2024-04-12 08:33:47 +02:00
pikomonde
05fb12b1d5 rename sha to hash 6, update short hash 2024-04-12 08:33:47 +02:00
pikomonde
9cf1ca10a2 rename sha to hash 5 2024-04-12 08:33:47 +02:00
pikomonde
13af335b37 rename sha to hash 3 2024-04-12 08:33:47 +02:00
pikomonde
e6ef1642fa rename sha to hash 2024-04-12 08:33:47 +02:00
Eng Zer Jun
f933a2f7ec
Replace min/max helpers with built-in min/max
We upgraded our minimum Go version to 1.21 in commit
57ac9c2189458a7f0e63c2e9cac8334694a3d545. We can now replace our
`utils.Min` and `utils.Max` functions with the built-in `min` and `max`.

Reference: https://go.dev/ref/spec#Min_and_max
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2024-04-07 23:24:10 +08:00
Artem Belyakov
f3dba743f0 Add SpinnerConfig
This new config section allows to customize frames and rate of
thespinner
2024-04-06 13:46:15 +02:00
Stefan Haller
84e82ea8b6 fixup! Introduce a yaml_utils.Walk function 2024-03-30 13:05:33 +01:00
Stefan Haller
4d8b8b647a Introduce a yaml_utils.Walk function 2024-03-29 17:55:06 +01:00
Stefan Haller
1fdcc29277 Fix deleting update-ref todos
It is a bad idea to read a git-rebase-todo file, remove some update-ref todos,
and write it back out behind git's back. This will cause git to actually remove
the branches referenced by those update-ref todos when the rebase is continued.

The reason is that git remembers the refs affected by update-ref todos at the
beginning of the rebase, and remembers information about them in the file
.git/rebase-merge/update-refs. Then, whenever the user performs a "git rebase
--edit-todo" command, it updates that file based on whether update-ref todos
were added or removed by that edit. If we rewrite the git-rebase-todo file
behind git's back, this updating doesn't happen.

Fix this by not updating the git-rebase-todo file directly in this case, but
performing a "git rebase --edit-todo" command where we set ourselves as the
editor and change the file in there. This makes git update the bookkeeping
information properly.

Ideally we would use this method for all cases where we change the
git-rebase-todo file (e.g. moving todos up/down, or changing the type of a
todo); this would be cleaner because we wouldn't mess with git's private
implementation details. I tried this, but unfortunately it isn't fast enough.
Right now, moving a todo up or down takes between 1 and 2ms on my machine;
changing it to do a "git rebase --edit-todo" slows it down to over 100ms, which
is unacceptable.
2024-03-26 22:29:56 +01:00
Stefan Haller
561afa9901 Rename FuzzySearch to FilterStrings
It isn't necessarily fuzzy any more.
2024-03-17 11:55:30 +01:00
Stefan Haller
a8797c7261 Default to substring filtering, add option to go back to fuzzy filtering
By default we now search for substrings; you can search for multiple substrings
by separating them with spaces. Add a config option gui.filterMode that can be
set to 'fuzzy' to switch back to the previous behavior.
2024-03-17 11:55:09 +01:00
Stefan Haller
a82e26d11e Don't sort the results of fuzzy.Find
It sorts them already, so it's unnecessary. In the next commit we use this same
code for substring searching too, and in that case we don't want to sort because
sorting is by Score, but we don't even fill in the score for substring
searching.
2024-03-17 07:57:19 +01:00
Stefan Haller
0608fc6471 Allow deleting update-ref todos 2024-03-16 22:01:13 +01:00
Stefan Haller
64a1a455d6 Extract a findTodo helper function
We will reuse it in the next commit.
2024-03-16 22:01:03 +01:00