1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-06 03:53:59 +02:00
Commit Graph

2130 Commits

Author SHA1 Message Date
Aaron Hoffman
15d5261933 Support range select removing files from a commit 2024-02-13 09:10:15 -06:00
Stefan Haller
bc6616d511 Disallow cherry-picking merge commits 2024-02-10 11:27:28 +01:00
Stefan Haller
2c82b3f8dd Disallow cherry-picking update-ref todos 2024-02-10 11:27:28 +01:00
Stefan Haller
dc40fb5267 Cleanup: remove unused method 2024-02-10 11:05:09 +01:00
molejnik88
ee173ff7c9 Clear cherry-picked commits after pasting
It can be tedious after each cherry-pick opearation to clear the
selection by pressing escape in order for lazygit to stop displaying
info about copied commits. Also, it seems to be a rare case to
cherry-pick commits to more than one destination.

The simplest solution to address this issue is to clear the selection
upon paste.

The only exception is a merge conflict. Initially, I wanted to clear
selected commits in this scenario too. During a discussion we found out
that it may be convenient to have the copied commits still around.
Aborting the rebase and pasting the commits in the middle of a branch
can be a valid use case.
2024-01-30 09:21:12 +11:00
Stefan Haller
b133318b40 Add command to squash all fixups in the current branch
To do that, change the "Apply fixup commits" command to show a menu with the two
choices "in current branch" and "above the selected commit"; we make "in current
branch" the default, as it's the more useful one most of the time, even though
it is a breaking change for those who are used to "shift-S enter" meaning
"squash above selected".
2024-01-29 09:37:47 +01:00
Stefan Haller
c66667c8c1 Fix main view refresh after adding the first file to a custom patch
This broke with 240948b.
2024-01-28 09:49:56 +01:00
Aaron Hoffman
510f9a1ae1 Support selecting file range in patch builder
test: add move_range_to_index

test: add toggle_range
2024-01-28 12:00:47 +11:00
Jesse Duffield
e1aa68a7bd Warn users when attempting to cherry pick with old key
I wrote this feature and even I sometimes use the wrong key so I want
to make this very clear to users so that there's no confusion
2024-01-28 11:48:21 +11:00
Jesse Duffield
bd7fabef1f Reduce the chance of race condition with list cursor
Before this commit, we had pkg/integration/tests/submodule/add.go
failing with a panic. I'm pretty sure the issue is this: we're now
calling quite a few GetDisabledReason calls on each layout() call,
and if a background thread happens to update a model slice while
we're doing this, we can end up with a selection index that's now
out of bounds because it hasn't been clamped to match the new list
length.

Specifically, here we had the selected index being -1 (the list starts
empty and somehow the value is -1 in this case) and then the list
gets a new submodule so the length is now 1, but the list cursor
doesn't know about this so remains on the old value. Then we confirm
the length is greater than zero and try to get the selected submodule
and get an out of bounds error.

This commit fixes the issue by clamping the selected index whenever
we get the length of the list so that it stays in-sync. This is not
a perfect solution because the length can change at any time, but
it seems to reliably fix the test, and using mutexes didn't seem to
make a difference.

Note that we're swapping the order of IFileTree and IListCursor in
the file tree view model to ensure that the list cursor's Len()
method is called (which performs the clamping).

Also, comment from the PR:
This 'trait' pattern we're using is convenient but can lead to awkward
situations. In this case we have both the list view model and the
(embedded) list cursor with a Len() method. The list cursor Len()
method just calls the list view model Len() method. But I wanted
to make it that the list view model now calls ClampSelection() on the
list cursor whenever it obtains the length. This will cause an
infinite loop because ClampSelection() internally calls Len()
(which calls the list view model's Len() method which in turn
calls ClampSelection() again, etc).

The only reason we were passing the list view model into the list
cursor was to supply the length method, so now we're just doing
that directly, and letting the list view model delegate the Len()
call to the list cursor, which now itself calls ClampSelection.
2024-01-28 09:20:52 +11:00
Jesse Duffield
1a38d515d7 Display more keybindings on-screen 2024-01-28 08:33:13 +11:00
Jesse Duffield
0f9d9e13d1 Show mode-specific keybinding suggestions
As part of making lazygit more discoverable, there are certain keys which you almost certainly
need to press when you're in a given mode e.g. 'v' to paste commits when cherry-picking. This
commit prominently shows these keybinding suggestions alongside the others in the option view.

I'm using the same colours for these keybindings as is associated with the mode elsewhere e.g.
yellow for rebasing and cyan for cherry-picking. The cherry-picking one is a bit weird because
we also use cyan text to show loaders and app status at the bottom left so it may be confusing,
but I haven't personally found it awkward from having tested it out myself.

Previously we would render these options whenever a new context was activated, but now that we
need to re-render options whenever a mode changes, I'm instead rendering them on each screen
re-render (i.e. in the layout function). Given how cheap it is to render this text, I think
it's fine performance-wise.
2024-01-28 08:33:13 +11:00
Jesse Duffield
c07b3fad64 Ensure file view length is never returned as -1
This was causing issues when obtaining selected items
2024-01-28 08:33:13 +11:00
Jesse Duffield
7bddf53223 Improve keybinding descriptions
This adds a bunch of tooltips to keybindings and updates some keybinding descriptions (i.e. labels).

It's in preparation for displaying more keybindings on-screen (in the bottom right of the screen),
and so due in part to laziness it shortens some descriptions so that we don't need to manage both
a short and long description (for on-screen vs in-menu). Nonetheless I've added a ShortDescription
field for when we do want to have both a short and long description.

You'll notice that some keybindings I deemed unworthy of the options view have longer descriptions,
because I could get away with it.
2024-01-28 08:12:01 +11:00
Stefan Haller
f9876c9742 Keep same selection range when quick-starting an interactive rebase
This is useful if you want to move a range of commits, so you select them, and
then realize it's better to do it in an interactive rebase. Pressing 'i'
preserves the range now.
2024-01-26 11:18:13 +01:00
Stefan Haller
f226a277bf Rename MinMax to SortRange 2024-01-26 11:18:06 +01:00
Luka Markušić
efb6524fa0 Add shortcuts for filtering files by status
- 's' for showing only staged files
- 'u' for showing only unstaged files
- 'r' for resetting the filter
2024-01-26 20:53:16 +11:00
Stefan Haller
7fb5266027 Use inline status for fetching remotes 2024-01-26 08:29:04 +01:00
Stefan Haller
12500be554 Pass absolute file paths to all editor commands
This helps work around bugs in editors that may get confused about relative
paths (like nvim-remote, see https://github.com/neovim/neovim/issues/18519), and
shouldn't have any negative effect on others.
2024-01-25 08:56:10 +01:00
Jesse Duffield
269ef7f250 Support range select for staging/discarding files
As part of this, you must now press enter on a merge conflict file
to focus the merge view; you can no longer press space and if you do
it will raise an error.
2024-01-25 11:34:59 +11:00
Jesse Duffield
798225d9e1 Move file discard action into files controller
It's better just having all the keybindings in one file especially when you want to
share code
2024-01-24 20:51:00 +11:00
Stefan Haller
e72c759541 Make range selections created with the mouse non-sticky
I prefer this because I almost never use sticky range selections. Also, this
fixes the issue that just clicking a line in a diff (without dragging) already
creates a range selection. It still does, technically, but it's no longer a
problem because a non-sticky one-line range selection behaves the same as a
non-range selection.
2024-01-24 08:22:55 +01:00
Jesse Duffield
41d5f4dbb5 Disallow updating non-standard TODO lines when rebasing 2024-01-23 17:23:56 +11:00
Jesse Duffield
f0de880136 Support range select in rebase actions 2024-01-23 17:23:56 +11:00
Jesse Duffield
a5f3515ad8 Set groundwork for better disabled reasons with range select
Something dumb that we're currently doing is expecting list items
to define an ID method which returns a string. We use that when copying
items to clipboard with ctrl+o and when getting a ref name for diffing.

This commit gets us a little deeper into that hole by explicitly requiring
list items to implement that method so that we can easily use the new
helper functions in list_controller_trait.go.

In future we need to just remove the whole ID thing entirely but I'm too
lazy to do that right now.
2024-01-23 13:03:37 +11:00
Stefan Haller
36134006c5 Add config setting to suppress showing file icons 2024-01-22 08:40:03 +01:00
Jesse Duffield
c2218133bc
Show file names in default colour (#3081)
Fixes https://github.com/jesseduffield/lazygit/issues/3077

Show unstaged file names in default colour

Previously, we had the following rules:
* file names were in red when unstaged or partially staged
* directory names were in red if unstaged, yellow if partially staged,
and
  green if fully staged

Red text on a black background can be hard to read, so instead I'm
changing it
so that unstaged files have their names in the default text colour.
I'm also making it so that partially staged files are in yellow, just
like how
partially staged directories are yellow (same deal with the commit files
view
when adding to a custom patch).

So the new rules are:
* unstaged files/directories use the default colour
* partially staged files/directories are in yellow
* fully staged files/directories are in green

I've also done a refactor on the code clean up some dead code from when
the file tree
outline was drawn with box characters, and I've made it so that the
indentation in
each line is handled inside the function that draws the line rather than
in the recursive
parent function. This makes it easier to experiment with things like
showing the file
status characters on the left edge of the view (admittedly after
experimenting with it,
I decided I didn't like it). Apologies for having a refactor and a
functional change
in the one commit but by the time I was done, I couldn't be bothered
going back and
retroactively splitting it into two halves.
2024-01-22 13:40:19 +11:00
Jesse Duffield
7c3d8921b7 Show unstaged file names in default colour
Previously, we had the following rules:
* file names were in red when unstaged or partially staged
* directory names were in red if unstaged, yellow if partially staged, and
  green if fully staged

Red text on a black background can be hard to read, so instead I'm changing it
so that unstaged files have their names in the default text colour.
I'm also making it so that partially staged files are in yellow, just like how
partially staged directories are yellow (same deal with the commit files view
when adding to a custom patch).

So the new rules are:
* unstaged files/directories use the default colour
* partially staged files/directories are in yellow
* fully staged files/directories are in green

I've also done a refactor on the code clean up some dead code from when the file tree
outline was drawn with box characters, and I've made it so that the indentation in
each line is handled inside the function that draws the line rather than in the recursive
parent function. This makes it easier to experiment with things like showing the file
status characters on the left edge of the view (admittedly after experimenting with it,
I decided I didn't like it). Apologies for having a refactor and a functional change
in the one commit but by the time I was done, I couldn't be bothered going back and
retroactively splitting it into two halves.
2024-01-22 13:31:05 +11:00
Stefan Haller
2c9b4770bc Keep same branch selected when refreshing branches
This wasn't necessary before, because the only available branch sorting option
was by recency, so the sort order couldn't change except by checking out
branches. Now, you can sort by committer date, so the branch order can change by
fetching; in this case it's important to keep the same branch selected. One
important use case is to rebase the checked-out branch onto master; you select
master, press "f" to fetch it (this can now change its position in the list),
and then press "r" to rebase. To make this work smoothly it's important to keep
master selected after pressing "f".
2024-01-19 09:25:07 +01:00
Jesse Duffield
ab3004bcd5 Show unacknowledged toast message upon integration test failure
Often if a test fails and there's an unaknowledged toast message, that message will
explain why the test failed. Given that we don't display toast messages in
integration tests when they run (for reasons I can't recall right now), we need to
log it as part of the error message.
2024-01-19 10:50:49 +11:00
Jesse Duffield
1ea0c270df Disable range-select in menu and suggestions view
We don't need it there so no need to enable it.

I'm leaving the disabled reason checks there, even though they're now redundant,
because they're only one-liners and they communicate intent.
2024-01-19 10:50:49 +11:00
Jesse Duffield
51fb82d6bf Enforce single-item selection in various actions
We want to show an error when the user tries to invoke an action that expects only
a single item to be selected.

We're using the GetDisabledReason field to enforce this (as well as DisabledReason
on menu items).

I've created a ListControllerTrait to store some shared convenience functions for this.
2024-01-19 10:50:49 +11:00
Jesse Duffield
280b4d60f8 Support select range for cherry pick
This requires us to change the 'v' keybinding for paste to something else,
now that 'v' is used globally for toggling range select. So I'm using
'shift+v' and I'm likewise changing 'c' to 'shift+c' for copying, so
that they're consistent.

We will need to clearly communicate this change in keybindings.
2024-01-19 10:50:49 +11:00
Jesse Duffield
54bd94ad24 Add SetSelection function for list contexts and use it in most places
The only time we should call SetSelectedLineIdx is when we are happy for a
select range to be retained which means things like moving the selected line
index to top top/bottom or up/down a page as the user navigates.

But in every other case we should now call SetSelection because that will
set the selected index and cancel the range which is almost always what we
want.
2024-01-19 10:47:21 +11:00
Jesse Duffield
8840c1a2b7 Remove 'v' menu keys
We can no longer use this because 'v' is globally reserved for range select.
Conveniently it was the first item in the menu anyway for both of these.
2024-01-19 10:47:21 +11:00
Jesse Duffield
d08fafb1c4 Clear range select upon pressing 'escape'
This is the highest priority of the escape actions because it's the thing you're
most likely to want to do upon hitting escape if you have a range selected.

Applying this to the staging/patch-building views is tricky: if we want this logic
for when a range of lines is selected, we'll also need to apply it when a hunk
is selected too. I still think it's worth it though: I've often accidentally
escaped from the staging view when trying to cancel a range selection.
2024-01-19 10:47:21 +11:00
Jesse Duffield
f3eb180f75 Standardise display of range selection across views
We're not fully standardising here: different contexts can store their range state however
they like. What we are standardising on is that now the view is always responsible for
highlighting the selected lines, meaning the context/controller needs to tell the view
where the range start is.

Two convenient benefits from this change:
1) we no longer need bespoke code in integration tests for asserting on selected lines because
we can just ask the view
2) line selection in staging/patch-building/merge-conflicts views now look the same as in
list views i.e. the highlight applies to the whole line (including trailing space)

I also noticed a bug with merge conflicts not rendering the selection on focus though I suspect
it wasn't a bug with any real consequences when the view wasn't displaying the selection.

I'm going to scrap the selectedRangeBgColor config and just let it use the single line
background color. Hopefully nobody cares, but there's really no need for an extra config.
2024-01-19 10:47:21 +11:00
Jesse Duffield
c0c3aac02e Support non-sticky range selection in patch explorer views 2024-01-19 10:47:21 +11:00
Jesse Duffield
24a4302c52 Add range selection ability on list contexts
This adds range select ability in two ways:
1) Sticky: like what we already have with the staging view i.e. press v then use arrow keys
2) Non-sticky: where you just use shift+up/down to expand the range

The state machine works like this:
(no range, press 'v') -> sticky range
(no range, press arrow) -> no range
(no range, press shift+arrow) -> nonsticky range
(sticky range, press 'v') -> no range
(sticky range, press arrow) -> sticky range
(sticky range, press shift+arrow) -> nonsticky range
(nonsticky range, press 'v') -> no range
(nonsticky range, press arrow) -> no range
(nonsticky range, press shift+arrow) -> nonsticky range
2024-01-19 10:47:21 +11:00
Stefan Haller
36e57d16bd Don't try to shorten branch names that are already 3 characters or less
This fixes a potential crash when the available width is very small and the
branch name is one to three characters long.
2024-01-15 13:27:49 +01:00
Jesse Duffield
fc8998e377 Do not include keybindings from another view in keybindings menu
Previously we included all navigation keybindings from all views in the keybindings menu, meaning
if you pressed enter on 'next page' in the commits view, you'd end up triggering the action
in the sub-commits view.
2024-01-15 20:08:11 +11:00
Stefan Haller
f133224683 Double the duration of error toasts
This gives users more time to read them.
2024-01-14 17:45:35 +01:00
Stefan Haller
83337d9fa8 Allow showing Disabled errors as error panel instead of toast 2024-01-14 17:45:35 +01:00
Stefan Haller
84e1d15079 Make DisabledReason a struct
This is a pure refactoring, no change in behavior yet. We'll add another field
to the struct in the next commit.
2024-01-14 17:45:35 +01:00
Stefan Haller
09a24ee97d Use ErrorToast instead of error panel when invoking a disabled command 2024-01-14 17:45:35 +01:00
Stefan Haller
99a3ccde71 Add ErrorToast function 2024-01-14 17:45:35 +01:00
Stefan Haller
8ca8a43968 Make it mandatory to acknowledge toasts in tests 2024-01-14 17:42:03 +01:00
Stefan Haller
9fa43394fe Make it possible to handle toasts in integration tests
Use it in two selected tests to demonstrate what it looks like.
2024-01-14 17:42:03 +01:00
Jesse Duffield
ee106f9af8 Do not perform IO work when getting disabled reason with local commits
Because we obtain disabled reasons after every action, we need to keep the code for doing so
super fast. As such, we should not be hitting the filesystem to get rebase state, instead
we should just get the cached state.

I feel like we should actually be using the cached state everywhere like we do with all
our other models if only for the sake of consistency.
2024-01-13 12:57:49 +11:00
Jesse Duffield
53a8bd2e3f Add ability to start an interactive rebase onto an appropriate base
A common issue I have is that I want to move a commit from the top of my branch
all the way down to the first commit on the branch. To do that, I need to navigate
down to the first commit on my branch, press 'e' to start an interactive rebase,
then navigate back up to the top of the branch, then move my commit back down to
the base. This is annoying.

Similarly annoying is moving the commit one-by-one without explicitly starting
an interactive rebase, because then each individual step is its own rebase which
takes a while in aggregate.

This PR allows you to press 'i' from the commits view to start an interactive
rebase from an 'appropriate' base. By appropriate, we mean that we want to start
from the HEAD and stop when we reach the first merge commit or commit on the main
branch. This may end up including more commits than you need, but it doesn't make
a difference.
2024-01-13 12:57:49 +11:00