1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-15 11:56:37 +02:00

5554 Commits

Author SHA1 Message Date
stk
61313e5dfa Add .gitattributes file
This tells git to checkout all .md and .json files with Unix line feeds,
even on Windows. This shouldn't be a problem for working with these
files on Windows, as all modern text editors and IDEs should be capable
of editing Unix files transparently; but it makes it possible to run
`go generate ./...` on Windows, which assumes Unix line feeds in a few
places.
2024-07-01 08:36:57 +02:00
stk
94a1c27916 Normalize line endings of docs/README.md
For some reason this was checked in with CRLF line endings; change it to
just LF, like all other text files.
2024-07-01 08:36:57 +02:00
Stefan Haller
6da4f9a787
Fix running lazygit with a language other than English on Windows (#3705)
On Windows, trying to use lazygit with a language other than English
would result in the error message `open translations\ja.json: file does
not exist`.
2024-07-01 08:36:38 +02:00
stk
398ceb1dd9 Fix loading translation set json files on Windows
It seems that the embed.FS always uses foreward slashes, even on
Windows.

This not only affected generating the cheatsheets, but also loading a
translation file in production.
2024-06-30 10:41:48 +02:00
Stefan Haller
6788825ed3
Make opening git difftool more consistent (#3691)
The default shortcut to open git difftool (`ctrl+t`) is not available on
the "Local Branches" window. It is available when selecting a commit
from a local branch, a remote branch, or a tag from the "Local Branches"
window.

This is inconsistent since branches or tags are also commits, the
shortcut should also work on them directly.

This commit remedies this inconsistency by allowing the use of the
shortcut directly on a branch or a tag. The shortcut works both in the
"standard" mode and the "diffing" mode.
2024-06-30 10:32:51 +02:00
T.
2335772db6 Make opening git difftool more consistent
The default shortcut to open git difftool (ctrl+t) is not available on
the "Local Branches" window. It is available when selecting a commit
from a local branch, a remote branch, or a tag from the "Local Branches"
window.

This is inconsistent since branches or tags are also commits, the
shortcut should also work on them directly.

This commit remedies this inconsistency by allowing the use of the
shortcut directly on a branch or a tag. The shortcut works both in the
"standard" mode and the "diffing" mode.
2024-06-30 10:27:28 +02:00
Jesse Duffield
1285554cb2
Add Squash merge (#3566)
- **PR Description**

Hello,

This PR add merge --squash. A PR already exist
https://github.com/jesseduffield/lazygit/pull/3130, but the author
abandoned it, so I remake it.
I modified to fit most of the comment made except this one
https://github.com/jesseduffield/lazygit/pull/3130/files#r1404808121. I
didn't find an existing example and thus didn't know to modify the code
to fit it to the new way of doing things.

There's still the choice box to commit or not to do as discussed
https://github.com/jesseduffield/lazygit/pull/3130#issuecomment-2112324990.
I'll do it when I have time, I first need to read the code to see how it
really works.

Also only english has been made for now. 


![image](https://github.com/jesseduffield/lazygit/assets/94681915/f648ca13-3d16-4703-a074-a83fe9a1eb0f)


- **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))
* [x] Docs (specifically `docs/Config.md`) 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
-->
2024-06-30 11:05:09 +10:00
Noah
232be05785 feat: squash merge 2024-06-30 11:01:03 +10:00
Stefan Haller
8990026358
Make commit author length configurable, take 2 (#3688)
- **PR Description**

This reverts #3625, and instead adds two new config keys
`commitAuthorShortLength` and `commitAuthorLongLength` for achieving the
same thing, but with more flexibility.

- **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))
* [x] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-29 11:31:52 +02:00
Stefan Haller
bd782f16dd Provide two config keys for configuring the author length in commits view
One is for the normal view, the other for the expanded view.
2024-06-29 11:28:44 +02:00
Stefan Haller
7be82d4713 Revert "Add user config gui.commitAuthorFormat (#3625)"
This reverts commit 3af545daf7cf6458e8efd324012047ce688f08e6, reversing
changes made to 629b7ba1b8f634c26adad43ffe44ed601d652f0c.

We changed our mind about this and want to provide different options for
achieving the same thing, but with more flexibility.
2024-06-29 11:28:00 +02:00
Stefan Haller
5dbdbd8425
Turn off the highlight of the suggestions panel when it loses focus (#3696)
- **PR Description**

The highlight is normally turned off in HandleFocusLost, but that's not
called when using ReplaceContext (and changing this would be a lot of
work, it seems), so turn it off manually for now.

For a moment I considered whether we want to show the new inactive
highlight when switching from suggestions to the prompt (actually this
did happen on master), but I decided against it for several reasons:
- it's not quite the right concept (the suggestions view is not the
"parent" context of the prompt),
- there's no benefit from seeing one of the suggestions selected (and
the selection would change arbitrarily when changing the filter string)
- there would be visual problems when the suggestions become empty, in
which case we would still highlight the first empty row (which you can
only see if you set the gui.theme.inactiveViewSelectedLineBgColor config
to some color). Now this could be considered a bug in the focus
management of the suggestions panel, but it doesn't seem worth fixing
this; the problem goes away by turning off the highlight.
2024-06-29 11:27:26 +02:00
Stefan Haller
9b73b68f95 Turn off the highlight of the suggestions panel when it loses focus
The highlight is normally turned off in HandleFocusLost, but that's not called
when using ReplaceContext (and changing this would be a lot of work, it seems),
so turn it off manually here for now.
2024-06-29 11:24:08 +02:00
Stefan Haller
c3715d0f86 Extract helper function SuggestionsController.switchToConfirmation
This fixes the minor issue that the subtitle of the suggestions view wasn't
emptied when hitting "e" to edit a custom command.
2024-06-29 11:24:08 +02:00
Stefan Haller
696b8ba457
Always reapply filters on filtered views when model changes, even inactive ones (#3697)
- **PR Description**

A filtered view would show stale data when the model changes but the
view is inactive. I think this could only happen when changing some git
state outside of lazygit; for example, when creating a new branch while
the branches panel has a filter set, but doesn't have the focus. (See
the added test for an example.)
2024-06-29 11:23:38 +02:00
Stefan Haller
e205c6ba7f Always reapply filters on filtered views, even inactive ones 2024-06-28 08:23:27 +02:00
Stefan Haller
c6df856079 Add test demonstrating a problem with updating the filter when the model changes
We only update the filter when the filtered view has the focus.
2024-06-28 08:23:27 +02:00
Stefan Haller
26c3e0d333
Stagger popup panels (#3694)
- **PR Description**

Sometimes we open a popup panel on top of another one; an example is the
`<c-o>` menu in the commit message editor, or the "add co-author" prompt
that appears on top of the commit message panel. We just added a new one
in #3676, which is the confirmation that appears when pasting a commit
message over an existing one.

Currently, these panels are sized and positioned independently of each
other, which looks ugly and makes it hard to see what's going on:
<img width="720" alt="image"
src="https://github.com/jesseduffield/lazygit/assets/1225667/6d84fc85-fadb-4f03-a973-868bc29d79f5">

Improve this by offsetting the new panel a bit down and to the right
from the one below it:
<img width="750" alt="image"
src="https://github.com/jesseduffield/lazygit/assets/1225667/c0c39f88-356b-4add-b335-4db2e54496ed">

Along the way we clean up the code a bit and fix a few minor issues; see
the individual commit messages for details.

- **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))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-28 08:17:36 +02:00
Stefan Haller
4b6479b25f Stagger popup panels
When opening a popup panel on top of another one, offset the new one a little
bit down and to the right.
2024-06-28 08:14:07 +02:00
Stefan Haller
1ab1fb3599 Resize all open popup panels in layout, not just the topmost one
Probably not the most import feature in the world, but when resizing the
terminal window while multiple popup panels were open at the same time, we would
only resize the topmost one.

The main reason for changing this is because it makes the next commit easier to
implement.
2024-06-28 08:14:07 +02:00
Stefan Haller
1d502d3245 Remove return value from ResizeCurrentPopupPanel
It always returned nil, so there's no point in returning an error.
2024-06-28 08:14:07 +02:00
Stefan Haller
bb01648521 Remove redundant calls to resize editable panels at creating time
The only purpose of this was to scroll the editable text correctly (see
https://github.com/jesseduffield/lazygit/pull/2146); now that gocui takes care
of that, we no longer need to do this.
2024-06-28 08:14:07 +02:00
Stefan Haller
32cfe7a5c3 Bump gocui 2024-06-28 08:14:05 +02:00
Stefan Haller
b795d91fa8 Remove redundant resizeConfirmationPanel() call at panel creating time
We resize the panel in layout, so there's no need to do that after creation.
2024-06-27 10:18:12 +02:00
Stefan Haller
ccc620e5fc Remove duplicate function
ResizeConfirmationPanel and resizeConfirmationPanel were identical, get rid of
one of them.
2024-06-27 10:14:00 +02:00
Stefan Haller
34d7afc0e9 Remove unused functions 2024-06-27 10:14:00 +02:00
Stefan Haller
22dc7fece9 Have only one of commit message and description on the context stack at a time
This is how we do it for confirmation with suggestions too, so be consistent. It
will make things easier later in this branch if we only have one context per
"panel" on the stack, even if the panel consists of two views.

Concretely this means:
- only push the message context onto the stack when opening the panel (this
  requires making the description view visible manually; we do the same for
  suggestions)
- when switching between message and description, use ReplaceContext rather than
  PushContext
2024-06-27 10:14:00 +02:00
Stefan Haller
c3d1a79a89 Fix clicking outside of the commit description panel or suggestions panel
We forgot to handle the "suggestions" and "commitDescription" view names.

Instead of listing all the names of views that can appear in popups though,
let's use the context kind for this, which feels more robust.

This is a change in behavior: previously, clicking outside of the search or
filter prompt would close the prompt, now it no longer does (because search has
a persistent popup kind, but it wasn't listed in the list of view names before).
2024-06-27 09:36:50 +02:00
Stefan Haller
63a523c2fc
Add command to paste commit message from clipboard (#3676)
- **PR Description**

Resolves #3672

Added an entry to the commit message menu called "Paste commit message from clipboard",
which splits the clipboard into subject and description and pastes both into their respective fields.

- **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))
* [x] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-27 08:36:52 +02:00
WaterLemons2k
d146d834c2 Add command to paste commit message from clipboard
Resolves #3672
2024-06-26 22:20:54 +02:00
Stefan Haller
68edfa20b4 Add function os.PasteFromClipboard
And a user config to override it with a custom command.
2024-06-26 22:20:54 +02:00
Stefan Haller
bfe9f233ac
Convert TranslationSets to json (#3649)
- **PR Description**

This lays the ground for translating lazygit's texts using a translation
system such as Crowdin, Weblate, or Poeditor.

See #3070.
2024-06-23 14:51:03 +02:00
Stefan Haller
741d9a26b6 Change script to write only the English translation set to JSON
We will have to do this regularly in order to upload it to Crowdin (or Weblate
or whatever translation system we are going to use).

Unlike the non-English JSON files, the en.json file is not committed to the git
repo.
2024-06-23 14:47:50 +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
b34de70c99 Remove all empty strings
I guess I could have coded this into the export script, but I was too lazy and
just did it manually in VS Code, which was easy enough.
2024-06-23 14:47:50 +02:00
Stefan Haller
1e123e2124 Convert the non-English translation sets to JSON files
We write a hacky, one-off script to do that. We need this script only once, so
we don't bother polishing it much. We'll re-purpose it later in the branch to
convert the English translation set to JSON; that is an operation that we need
to do regularly in the future.
2024-06-23 14:47:50 +02:00
Stefan Haller
02aeb6101c Remove unused struct 2024-06-23 14:47:50 +02:00
Stefan Haller
2ccd9980e3
Fix wrong highlight in staging panel when entering file with only staged changes (#3667)
Reproduction recipe:
1. stage all changes in a file by pressing space on it in the files panel
2. enter the staged changes panel by pressing enter
3. unstage one of the changes

This makes the unstaged changes panel visible, but keeps the focus in
the staged changes panel. However, the highlight in the unstaged changes
view becomes visible, as if it were focused.

Fixes #3664
2024-06-23 14:46:36 +02:00
Stefan Haller
db0a1586d9 Highlight inactive selection in bold
An inactive selection is one where the view is part of the context stack, but
not the active view. For example, the files view when you enter the staging
panel, or any view when you open a panel.
2024-06-23 14:43:13 +02:00
Stefan Haller
4e441127f3 Clear highlight in HandleFocusLost
Remove the old mechanism of clearing the highlight in Layout.

This fixes a problem with a wrong highlight showing up in the staging panel when
entering a file with only staged changes.

Reproduction recipe:
1. stage all changes in a file by pressing space on it in the files panel
2. enter the staged changes panel by pressing enter
3. unstage one of the changes
This makes the unstaged changes panel visible, but keeps the focus in the staged
changes panel. However, the highlight in the unstaged changes view becomes
visible, as if it were focused.

To explain why this happens, you need to know how the selection highlighting of
a view is turned on or off. It is turned on when it gains the focus, i.e. when
ActivateFocus is called on it, which in turn happens when PushContext is called.
It is turned off in Layout when gocui sees that the current view is no longer
the same as last time, in which case it calls onViewFocusLost on the previous
current view.

This mechanism only works reliably when there is at most one PushContext call
per event handler. If there is more than one, then the first one gets its
highlight turned on, then the second one, but since gocui has never seen the
first one as the active view in Layout, it doesn't get the highlight turned off
again even though it should.

And this happens in the above scenario. When pressing enter on a file with only
staged changes, we first push the staging context (in
FilesController.EnterFile), and then later we push the stagingSecondary context
when we realize we only have staged changes. This leaves the highlight of the
staging context on.
2024-06-23 13:21:49 +02:00
Stefan Haller
cf40a5b077
Improve render performance (#3686)
- **PR Description**

Fix a performance regression that I introduced with v0.41: when entering
or leaving staging mode for a file, or when switching from a file that
has only unstaged changes to one that has both staged and unstaged
changes, there was a noticeable lag of about 500ms on my machine. With
the improvements in this PR we get this back down to about 20ms.
2024-06-23 13:13:58 +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
a67eda39a5 Rerender fewer views when their width changes
In d5b4f7bb3e and 58a83b0862 we introduced a combined mechanism for rerendering
views when either their width changes (needed for the branches view which
truncates long branch names), or the screen mode (needed for those views that
display more information in half or full screen mode, e.g. the commits view).

This was a bad idea, because it unnecessarily rerenders too many views when just
their width changes, which causes a noticable lag. This is a problem, for
example, when selecting a file in the files panel that has only unstaged
changes, and then going to one that has both staged and unstaged changes; this
splits the main view, causing the side panels to become a bit narrower, and
rerendering all those views took almost 500ms on my machine. Another similar
example is entering or leaving staging mode.

Fix this by being more specific about which views need rerendering under what
conditions; this improves the time it takes to rerender in the above scenarios
from 450-500s down to about 20ms.

This reintroduces the code that was removed in 58a83b0862, but in a slightly
different way.
2024-06-23 13:10:48 +02:00
Stefan Haller
8e1464f720 Don't redraw remote branches view when its width changes
The rendering of remote branches is in no way dependent on the width of the view
(or the screen mode). Unlike in the local branches view, we don't truncate long
branch names here (because there's no more information after them).

This is an error introduced in d5b4f7bb3e.
2024-06-23 13:08:01 +02:00
Stefan Haller
a62a5089d6
Show current value in menus (#3628)
- **PR Description**

Some of our menus let you pick a value for some option (e.g. the sort
order menus for branches and commits). It's nice to see which one is the
current value when opening such a menu, so this PR implements that.

For menus that also have key bindings, the radio button goes between the
key and the label.

As an alternative, I considered selecting the current value when the
menu is opened; however, we currently have no menus where we select a
different entry than the first one, and it might be confusing for people
who are used to opening a menu and then pressing down-arrow a certain
number of times to get to a particular value.

- **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))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-23 12:56:08 +02:00
Stefan Haller
4967e5136e Show radio buttons in the show log graph and commit sort order menus 2024-06-23 12:53:15 +02:00
Stefan Haller
68c966567c Show radio buttons in the sort order menu for branches 2024-06-23 12:53:15 +02:00
Stefan Haller
20a4aeab6e Support showing checkboxes or radio buttons in menus
For checkboxes it probably doesn't really make sense to use them yet, because
we'd have to find a way how you can toggle them without closing the dialog; but
we already provide rendering for them to lay the ground.

But radio buttons can be used already, because for those it is ok to close the
dialog when choosing a different option (as long as there is only one grounp of
radio buttons in the panel, that is).
2024-06-23 12:53:15 +02:00
Stefan Haller
a5620ebe3a
Always show the "Discard unchanged changes" menu item (#3683)
Always show the "Discard unchanged changes" menu item in the Discard
menu, just strike it through if not applicable. This will hopefully help
with confusion about the meaning of "all" in the "Discard all changes"
entry; some people misunderstand this to mean all changes in the working
copy. Seeing the "Discard unstaged changes" item next to it hopefully
makes it clearer that "all" is meant in contrast to that.
2024-06-23 12:46:59 +02:00
Stefan Haller
1b245ef5f6 Always show the "Discard unchanged changes" menu item
Strike it through if not applicable. This will hopefully help with confusion
about the meaning of "all" in the "Discard all changes" entry; some people
misunderstand this to mean all changes in the working copy. Seeing the "Discard
unstaged changes" item next to it hopefully makes it clearer that "all" is meant
in contrast to that.
2024-06-23 12:43:34 +02:00