1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-03 00:57:52 +02:00
Commit Graph

4253 Commits

Author SHA1 Message Date
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
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
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
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
ca05a2ccea Enable revive linter, and fix a bunch of warnings
I took the set of enabled checks from revive's recommended configuration [1],
and removed some that I didn't like. There might be other useful checks in
revive that we might want to enable, but this is a nice improvement already.

The bulk of the changes here are removing unnecessary else statements after
returns, but there are a few others too.

[1] https://github.com/mgechev/revive?tab=readme-ov-file#recommended-configuration
2025-06-30 19:13:20 +02:00
7aa426fa71 Enable errorlint linter, and fix warnings 2025-06-30 18:30:11 +02:00
0471dbaa84 Enable intrange linter, and fix warnings 2025-06-30 18:30:11 +02:00
1e92d8b7f3 Enable nolintlint linter, and fix warnings 2025-06-30 18:30:11 +02:00
92093ce56a Fix warning QF1003: could use tagged switch 2025-06-30 18:30:11 +02:00
c7d0aaa786 Fix warning QF1004: could use strings.ReplaceAll instead 2025-06-30 18:30:11 +02:00
4604227238 Make stashEntryFromLine a free-standing function
It doesn't use the receiver at all, so doesn't have to be a method.

This fixes ST1016: methods on the same type should have the same receiver name.
2025-06-30 18:30:11 +02:00
b7aecf5f17 Fix warning ST1016: methods on the same type should have the same receiver name 2025-06-30 18:30:11 +02:00
8c574f888c Fix warning ST1016: methods on the same type should have the same receiver name
Most methods use gui as a receiver name (120 of them), so switch the few that
use self over to that too.
2025-06-30 18:30:11 +02:00
e5b09f34e0 Show tag information for selected tag 2025-06-30 16:12:33 +02:00
b12b1040c3 Add IsAnnotated field to models.Tag struct 2025-06-30 16:12:33 +02:00
03abdfcfe2 Fix the CurrentBranchName function
The function would return "head/branchname" when there was either a tag or a
remote with the same name.

While fixing this we slightly change the semantic of the function (and of
determineCheckedOutBranchName, which calls it): for a detached head it now
returns an empty string rather than the commit hash. I actually think this is
better.
2025-06-30 16:08:03 +02:00
f95ac6780f Cleanup: turn around error condition
It is a common go convention for the "happy path" to be as little indented as
possible.
2025-06-30 16:08:03 +02:00
61815c10e7 Add a test showing undesired branch icon at head commit
The icon will appear when there's a tag with the same name as the current branch
(that's what we're testing here), or even when there's a remote with the same
name. I'm not adding a test for this latter case, but this was actually how I
discovered the issue.
2025-06-30 16:08:03 +02:00
9e05e4d810 fix: show GPG error before entering commit editor
Closes #4611
2025-06-30 08:35:52 +02:00
b5c2524d75 Add credential prompts for PKCS11-based SSH keys 2025-06-20 08:23:59 +02:00
b5c284db39 Fix DEFAULT_REMOTE_ICON character code
Unicode characters with code longer than 4 digits should be written as
`\Uffffffff` (8 digits)

Fixes #4652
2025-06-20 00:03:53 +02:00
206283d1f7 Fix moving a custom patch from the very first commit of the history to a later commit
This would crash with an index-out-of-range error.

I double-checked that all other callers of PrepareInteractiveRebaseCommand
already call getBaseHashOrRoot, so this was the only one that was broken.

I decided not to add a test for this as the scenario is not a very common one.
2025-06-19 18:43:17 +02:00
fd270768e8 Instantiate other mutexes by value
Like in the previous commit, this is preferred because the fields don't need to
be initialized this way.
2025-06-19 18:39:46 +02:00
5ee5d42511 Instantiate Mutexes's fields by value
Instead, pass the entire Mutexes struct by pointer to controllers.

This is better because Mutexes now has a zero value and doesn't need to be
initialized.
2025-06-19 18:39:46 +02:00
80bbdf41fb add bold style for border 2025-06-15 16:28:20 +02:00
265557afa2 Add unambigious refs/ prefix to all stash references
Pretty basic fix, didn't seem to have any complications.
I only added the refs/ prefix to the FullRefName() method
to align with other similar methods, and to make this change
not impact any user facing modals.

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

Also adds a test demonstrating that the stash show behavior is now fixed
2025-06-15 16:14:59 +02:00
708b30ab8a Add option to disable warning when amending last commit 2025-06-13 16:34:05 +02:00
c752f3529b Remove the pick vs. pull hack
Previously we would call pullFiles() from the pick() handler if we were not in a
rebase, assuming that the default keybinding for both is "p". This needn't be
the case of course, if the user has remapped one or the other.

The consequence of this was that swapping the keybindings for "pullFiles" and
"pushFiles" would work in all panels except the Commits panel (unless "pick" was
also remapped in the same way).

Fix this by using the new AllowFurtherDispatching mechanism of DisabledReasons
to pass the keybinding on to the next handler.
2025-06-05 13:20:39 +02:00
3e26be9845 Optionally pass disabled commands on to next handler
If a DisabledReason has its AllowFurtherDispatching flag set, it is returned as
a ErrKeybindingNotHandled error, instead of shown as a toast right away. This
allows gocui to continue to dispatch the keybinding, and we can unwrap the error
at the other end (in our global ErrorHandler) and display it then.

This allows having keybindings for the same key at the local and global levels,
and they will continue to be dispatched even if the first one returns a
DisabledReason. It is opt-in, so we only use it for cases where we know that a
local and a global handler share the same (default) keybinding.
2025-06-05 13:20:38 +02:00
37b118f4fb Cleanup: restructure code for clarity
There was no reason to declare a variable for disabledReason, assign it inside
the "if binding.GetDisabledReason != nil" statement, and then check its value
again after that if statement. Move all that code inside the first if statement
to make the control flow easier to understand.
2025-06-05 13:20:38 +02:00
9e64f7dd66 Bump gocui and adapt lazygit code
Adaptions are for this gocui commit:

Cleanup: remove Is* error functions

- Use errors.Is instead of quality comparisons. This is better because it
  matches wrapped errors as well, which we will need later in this branch.
- Inline the errors.Is calls at the call sites. This is idiomatic go, we don't
  need helper functions for this.

See https://go.dev/blog/go1.13-errors for more about this.
2025-06-05 13:20:38 +02:00
f185e1a5e3 Fix wrong inactive highlight when switching between repos
When switching between repos, each repo might have a different focused panel; in
this case, the previously focused panel would show the "inactive" highlight. By
default this is only bold text, so it's barely noticeable, but it becomes more
pronounced when setting e.g.

gui:
  theme:
    inactiveViewSelectedLineBgColor:
      - "#666666"

I noticed this especially when entering or leaving submodules; for example,
enter a submodule by pressing enter in the Files panel, then switch to the
Commits panel in the submodule, then press Esc to go back to the parent repo.
This would put the focus back into the Files panel, but keep the inactive
highlight in the Commits panel.
2025-06-05 12:58:38 +02:00
706891e92b Add integration test for resetting to upstream branch with duplicate name 2025-06-04 20:43:01 +02:00
fa238809ae Use full refname instead of short to prevent disambiguation with tag
In the unlikely scenario that you have a remote branch on `origin` called
`foo`, and a local tag called `origin/foo`, git changes the behavior of
the previous command such that it produces

```
$ git for-each-ref --sort=refname --format=%(refname:short) refs/remotes

origin/branch1
remotes/origin/foo
```

with `remotes/` prepended. Presumably this is to disambiguate it from
the local tag `origin/foo`. Unfortunately, this breaks the existing
behavior of this function, so the remote branch is never shown.

By changing the command, we now get
```
$ git for-each-ref --sort=refname --format=%(refname) refs/remotes

refs/remotes/origin/branch1
refs/remotes/origin/foo
```

This allows easy parsing based on the `/`, and none of the code outside
this function has to change.

----

We previously were not showing remote HEADs for modern git versions
based on how they were formatted from "%(refname:short)".
We have decided that this is a feature, not a bug, so we are building
that into the code here.
2025-06-04 20:43:01 +02:00
737a99b1c8 Add integration tests showing resetting to duplicate named tags and branches 2025-06-04 20:43:01 +02:00
122d6e5f0d Add FullRefName to all reset menus 2025-06-04 20:43:01 +02:00
bb6c883761 Print default option when prompting to create a new git repo 2025-06-04 08:15:21 +02:00
d60fe437ef Replace literal with ConfigFilename constant
Signed-off-by: Mateusz Łoskot <mateusz@loskot.net>
2025-05-31 02:28:39 +02:00
fdf9726c37 Use branchPrefix on moving commits to a new branch
Signed-off-by: Elias Assaf <elyas51000@gmail.com>
2025-05-29 22:39:26 +02:00
816d0c0820 Add a function to suggest a branch name based on branchPrefix
Moving the getter of the suggested branch name to a separate function
allows us to reuse it in situations where we are not calling the regular
create new branch function, such as move commits to a new branch

Signed-off-by: Elias Assaf <elyas51000@gmail.com>
2025-05-29 21:07:22 +03:00
fce4816a0d Fix branch selection jumping back on background fetch
When refreshing the branches list, we have code to keep the same branch selected
even when the refresh changes the sort order; this code remembers the selected
branch before the refresh, and then tries to select it again afterwards (looking
it up by name) if it is still there.

However, we stored the previously selected branch too early, before even
obtaining the branches list; if the user moved the selection between that point
and the end of the refresh, it would jump back. Fix this by remembering the
previous selection only at the last moment, right before assigning the new
branches slice.

We still have a race condition here between the UI code that manages the
selection as the user presses arrow keys, and the background thread doing the
refresh that reads and restores the selection; however, the race was there
before, and we make it neither better nor worse with this PR. It doesn't seem to
be a problem in practice.
2025-05-29 14:41:59 +02:00
d5bd30474c Kill background fetch when it requests a passphrase
Previously we would enter a newline at the password prompt, which would cause
the fetch to fail. The problem with this was that if you have many remotes, the
fetch would sometimes hang for some reason; I don't totally understand how that
happened, but I guess the many ssh processes requesting passwords would somehow
interfere with each other. Avoid this by simply killing the git fetch process
the moment it requests the first password.
2025-05-29 14:36:01 +02:00