1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

2485 Commits

Author SHA1 Message Date
hasecilu
8b90cca521 Use HEX colors on file icons instead of C256 colors 2025-01-02 15:36:27 +11:00
Sebastian Flügge
f4c8287143 Allow to switch branches in Commit View
When the user checks out a commit which has a local branch ref attached
to it, they can select between checking out the branch or checking out
the commit as detached head.
2025-01-01 14:55:12 +01:00
Stefan Haller
3a30211099 Don't preserve commit message when it's unchanged from initial message
Sometimes we populate the commit message panel with a pre-created commit
message. The two cases where this happens is:
- you type `w` to commit, in which case we put the skipHookPrefix in the subject
- you have a commitPrefix pattern, in which case we match it against the branch
  name and populate the subject with the replacement string if it matches

In either case, if you have a preserved commit message, we use that.

Now, when you use either of these and then cancel, we preserve that initial,
unchanged message and reuse it the next time you commit. This has two problems:
it strips spaces, which is a problem for the commitPrefix patterns, which often
end with a space. And also, when you change your config to experiment with
commitPrefix patterns, the change seemingly doesn't take effect, which can be
very confusing.

To fix both of these problems, only preserve the commit message when it is not
identical to the initial message.
2024-12-23 12:28:52 +01:00
Stefan Haller
15288b7bf4 Add user config to enable line wrapping in the staging view
It is enabled by default, because I think it's often helpful, and rarely in the
way. I bet most user won't even notice.
2024-12-23 12:24:09 +01:00
Stefan Haller
2828fb94fb Rewrap patch when view width changes
This makes it so that when the staging view is resized, we keep the same patch
line selected (as opposed to the same view line, which may correspond to a
different patch line after resizing). It doesn't seem like a terribly important
feature for resizing the window, but it is essential when initially entering the
staging view: we select the first line of the first hunk in this case, but we do
that before layout runs. At layout time the view is then split into
unstaged/staged changes, and if this split is horizontal, the view gets narrower
and may be wrapped in a different way. With this commit we ensure that the first
line of the first hunk is still selected after that.
2024-12-23 12:24:09 +01:00
Stefan Haller
5213a9de32 Handle wrapped lines in patch explorer state
So far, lines in the view corresponded 1:1 to lines in the patch. Once we turn
on wrapping for the staging view (which we don't do yet), this is no longer
true, so we need to convert from view lines to patch lines or vice versa all
over the place.
2024-12-23 12:24:09 +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
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
2b49865d0d Fix: set state to nil when patch building view loses focus
This is also what we do in the staging controller, and it makes it so that when
you exit the patch building view and then enter it again (for another file, or
the same one) we select the first hunk again.
2024-12-23 12:24:09 +01:00
Stefan Haller
da47498066 Cleanup: remove unused log parameter of patch_exploring.NewState 2024-12-23 12:24:09 +01:00
Stefan Haller
2f1564d288 Cleanup: remove unused method RangeStartLineIdx 2024-12-23 12:24:09 +01:00
Stefan Haller
3610f13418 Fix several bugs in wrapMessageToWidth
This corresponds to the following fixes in gocui's lineWrap function:
- https://github.com/jesseduffield/gocui/pull/67/commits/86cf561ef493
- https://github.com/jesseduffield/gocui/pull/67/commits/24746d5cd6ee
- https://github.com/jesseduffield/gocui/pull/67/commits/4b97941c4ec6
2024-12-23 12:24:09 +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
d5f2fb6003 Disable dropping merge commits if it's not a single selection 2024-12-23 12:12:45 +01:00
Stefan Haller
bd0d9ef259 Disable fixup/squash for merge commits 2024-12-23 12:12:45 +01:00
Stefan Haller
75d2fb1df2 Disable moving merge commits
Not much of a change in behavior, because moving merge commits was already not
possible. However, it failed with a cryptic error message ("Todo fa1afe1 not
found in git-rebase-todo"), so disable it properly instead.
2024-12-23 12:12:45 +01:00
Samuel Dominguez
4268701606 reorder keybinds to main/down, main/up, secondary/down, secondary/up 2024-12-17 16:57:23 +00:00
Samuel Dominguez
799827ee0e remove duplicate secondary MouseWheelUp keybind 2024-12-17 14:00:21 +00:00
johannaschwarz
f455f99705 Add user config gui.showNumstatInFilesView
When enabled, it adds "+n -m" after each file in the Files panel to show how
many lines were added and deleted, as with `git diff --numstat` on the command
line.
2024-12-08 12:09:47 +01:00
phanirithvij
6da42b07cd add missing default sort order in commits panel
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
2024-12-03 09:56:53 +05:30
Stefan Haller
5cca4c7063 Cleanup: move adding --ignore-all-space arg to DiffCmdObj
It is needed by both call sites of this function. This has the added benefit
that the argument doesn't unnecessarily show up in the status view when diffing
mode is on.
2024-12-01 13:01:15 +01:00
Stefan Haller
debfe1a21f Improve editing a commit
In 67b8ef449c we changed the "edit" command to insert a "break" after the
selected commit, rather than setting the selected todo to "edit". The reason for
doing this was that it now works for merge commits too.

Back then, I claimed "In most cases the behavior is exactly the same as before."
Unfortunately that's not true, there are two reasons why the previous behavior
was better (both are demonstrated by tests earlier in this branch):
- when editing the last commit of a branch in the middle of a stack of branches,
  we are now missing the update-ref todo after it, which means that amending the
  commit breaks the stack
- it breaks auto-amending (see the added test earlier in this branch for an
  explanation)

For these reasons, we are going back to the previous approach of setting the
selected commit to "edit" whenever possible, i.e. unless it's a merge commit.

The only scenario where this could still be a problem is when you have a stack
of branches, and the last commit of one of the branches in the stack is a merge
commit, and you try to edit that. In my experience with stacked branches this is
very unlikely, in almost all cases my stacked branches are linear.
2024-12-01 11:05:45 +01:00
Stefan Haller
d84986880e Extract helper methods
We'll reuse them in the next commit.
2024-12-01 11:05:45 +01:00
Stefan Haller
c1b4201726 Allow deleting a range selection of branches
We allow deleting remote branches (or local and remote branches) only if *all*
selected branches have one.

We show the a warning about force-deleting as soon as at least one of the
selected branches is not fully merged.

The added test only tests a few of the most interesting cases; I didn't try to
cover the whole space of possible combinations, that would have been too much.
2024-12-01 10:59:54 +01:00
Stefan Haller
92bce7de43 Pass a remote branch to ConfirmDeleteRemote
Since we want to select multiselections, this will make it easier to pass a
slice of remote branches. It does require that for the case of the local
branches panel we need to synthesize a RemoteBranch object from the selected
local branch, but that's not hard.
2024-12-01 10:59:54 +01:00
Stefan Haller
e98cc4d016 Extract variables
Besides being a useful cleanup on its own, it will make it easier to support a
multiselection of branches.
2024-12-01 10:59:54 +01:00
Stefan Haller
24e98d1792 Fix mouse wheel scrolling of custom patch view
Mouse wheel scrolling of the custom patch view worked *unless* a file (as
opposed to a directory) is selected in the commit files view. The reason was an
obvious typo in the AttachControllers call.
2024-12-01 10:48:27 +01:00
Stefan Haller
b07109de4d Remove unused field gui.IsNewRepo 2024-12-01 10:44:26 +01:00
Stefan Haller
59303981f9 Simplify startBackgroundFetch
This code had a lot of logic that (fortunately) didn't work because it was
buggy:

- it was supposed to wait for the auto-fetch delay before fetching for the first
  time in case we start with a repo that we had open in a previous session (i.e.
  that appears in the recent repos list). This code actually ran always, not
  just for known repos, because the IsNewRepo flag is only set later, after this
  function runs. Fortunately, the code didn't work, because time.After starts a
  timer but doesn't wait for it (to do that, it would have to be
  `<-time.After`).
- if the first fetch fails with error 128, it was supposed to show an error
  message and not start the background fetch loop. Fortunately, this didn't work
  because 1) it was guarded by isNew which is always false here, and 2) because
  git's error message in this case is actually "exit code: 128", not "exit
  status 128" (maybe this has changed in git at some point).

I find both of these undesirable. Whenever I open a repo I want an auto-fetch to
be triggered immediately to get my branch information up to date as quickly as
possible. And if the initial fetch fails (e.g. because one of my remotes is
offline or doesn't exist any more), then that's no reason not to start the
auto-fetch loop anyway.

So let's simplify the code to do what it did before, but with much fewer lines
of code.
2024-12-01 10:44:26 +01:00
Stefan Haller
f6f2a52dee Bump gocui and adapt lazygit code
Original commit message of the gocui change:

This fixes View.Size, Width and Height to be the correct (outer) size of a view
including its frame, and InnerSize/InnerWidth/InnerHeight to be the usable
client area exluding the frame. Previously, Size was actually the InnerSize (and
a lot of client code used it as such, so these need to be changed to InnerSize).
InnerSize, on the other hand, was *one* less than Size (not two, as you would
have expected), and in many cases this was made up for at call sites by adding 1
(e.g. in calcRealScrollbarStartEnd, parseInput, and many other places in the
lazygit code).

There are still some weird things left that I didn't address here:
- a view's lower-right coordinates (x1/y1) are one less than you would expect.
  For example, a view with a 2x2 client area like this:
    ╭──╮
    │ab│
    │cd│
    ╰──╯
  in the top-left corner of the screen (x0 and y0 both zero) has x1/xy at 3, not
  4 as would be more natural.
- a view without a frame has its coordinates extended by 1 on all sides; to
  illustrate, the same 2x2 view as before but without a frame, sitting in the
  top-left corder of the screen, has coordinates x0=-1, y0=-1, x1=2, y1=2. This
  is highly confusing and unexpected.

I left these as they are because they would be even more of a breaking change,
and also because they don't have quite as much of an impact on general app code.
2024-12-01 10:40:08 +01:00
Moritz Haase
949e131ebe pkg/gui: Allow user to select remote and branch when creating a PR
When creating a PR against a selected branch (via O = "create pull request
options"), the user will first be asked to select a remote (if there is more
than one). After that, the suggestion area is populated with all remote branches
at that origin - instead of all local ones. After all, creating a PR against a
branch that doesn't exist on the remote won't work.

Please note that for the "PR is not filed against 'origin' remote" use case
(e.g. when contributing via a fork that is 'origin' to a GitHub project that is
'upstream'), the opened URL will not be correct. This is not a regression and
will be fixed in an upcoming PR.

Fixes #1826.
2024-11-23 11:52:21 +11:00
LU Jialin
111407d9a6 use an unsigned_64 for DiffContextSize and add saturated add/subtract 2024-11-19 08:21:19 +11:00
Yaroslav Veremenko
fdeaf9cea0 Add new filter to only show tracked files in Files panel
This allows to hide all non-tracked files on large repos
2024-11-12 16:54:24 +11:00
Harris Greenstein
8da43af924 Add config option to disable tab switching with jump keys 2024-11-09 17:19:14 +11:00
Stefan Haller
f08b3e9e1d Cleanup: remove isFocused parameter from GetContentToRender and related methods
It became unused in f3eb180f75.
2024-10-18 22:46:48 +02:00
Stefan Haller
8f3e59b78e Don't render staging view when it loses focus
As far as I understand, this was needed back when the staging context was still
responsible for rendering its highlight (as opposed to the gocui view, as it is
today). It was necessary to call it with isFocused=false so that it removed the
highlight. The isFocused bool is no longer used today (and we'll remove it in
the next commit), so there's no need to render the view here any more.

This fixes flickering when leaving the staging view by pressing escape. The
reason is that in this case the patch state was already set to nil by the time
we get here, so we would render an empty view for a brief moment.

On top of that, it fixes unwanted scrolling to the top when leaving the staging
view. The reason for this is that we have code in layout that scrolls views up
if needed, e.g. because the window got taller or the view content got shorter
(added in #3839). This kicked in because we emptied the view, and scrolled it
all the way to the top, which we don't want.
2024-10-18 22:46:47 +02:00
Stefan Haller
eaf3bf0971 Change NewRenderStringWith{out}ScrollTask to reuse the task key of the existing task
This way it won't scroll to the top; we want this when entering the staging
panel or the patch building panel by clicking into the view, and also when
returning from these views by pressing escape. Note that there's a bug in this
latter case: the focused panel still scrolls to the top when hitting escape, we
will fix this in the next commit.

Change it in the same way for NewRenderStringWithScrollTask, just for
consistency, although it's not really necessary there. We use this function only
for focusing the merge conflict view, and in that case we already have an empty
task key before and after, so it doesn't change anything there.
2024-10-18 22:46:47 +02:00
Stefan Haller
a58770ee1b Fix pressing shift-down after clicking in diff view
When clicking in a single-file diff view to enter staging (or custom patch
editing, when coming from the commit files panel), and then pressing shift-down
or shift-up to select a range, it would move the selected line rather than
creating a range. Only on the next press would it start to select a range from
there.

This is very similar to the fix we made for pressing escape in 0e4d266a52.
2024-10-18 10:08:27 +02:00
Stefan Haller
286e5f4849 Fix clicking multiple times in an integration test
So far we only had tests that called Click() only once. If you have a test that
calls Click twice (we'll add one in the next commit), you'll notice that the
second click is interpreted as a drag because the mouse button wasn't released
in between. Fix this by sending a "mouse-up" event after the click.
2024-10-18 10:06:52 +02:00
Stefan Haller
85523402d6 Allow pasting commits more than once
After pasting commits once, we hide the cherry-picking status (as if it had been
reset), and no longer paint the copied commits with blue hashes; however, we
still allow pasting them again. This can be useful e.g. to backport a bugfix to
multiple major version release branches.
2024-10-13 16:55:54 +02:00
Stefan Haller
f473d23d65 Wrap an overly long line 2024-10-13 16:55:54 +02:00
Stefan Haller
59a937ee7a Get rid of error return value of PostRefreshUpdate and a few related ones
I missed these in https://github.com/jesseduffield/lazygit/pull/3890.
2024-10-13 16:55:54 +02:00
Stefan Haller
f71274b601 Add test to ensure that file icons are one rune
This should prevent errors like that from happening again.
2024-10-13 16:51:27 +02:00
Stefan Haller
f2fd435c05 Fix many file icons
The string literal "\uf0868" does *not* create a single rune with the code point
f0868, as was intended; instead, it creates two runes, one with the code point
f086, followed by the character '8'.
2024-10-13 16:51:27 +02:00
Stefan Haller
825f5c0a91 Use AutoRenderHyperLinks in confirmation view
This allows us to get rid of the underlineLinks function.
2024-09-28 12:04:51 +02:00
Stefan Haller
26e3a93fc3 Use AutoRenderHyperLinks in main views
This allows clicking on links in commit messages, for examples. It also affects
the status view, so we can get rid of the manual hyperlinking there.
2024-09-28 12:04:51 +02:00
Stefan Haller
1ceb5a6b37 Turn on AutoRenderHyperLinks in the Command Log panel
Some commands output hyperlinks, and it's useful to be able to click them.
2024-09-28 12:04:51 +02:00
Stefan Haller
1ab70ec645 Add a menu item to delete both local and remote branch at once 2024-09-28 11:23:21 +02:00
Stefan Haller
c712b1d0fe Better local branch delete confirmation
Currently we try to delete a branch normally, and if git returns an error and
its output contains the text "branch -D", then we prompt the user to force
delete, and try again using -D. Besides just being ugly, this has the
disadvantage that git's logic to decide whether a branch is merged is not very
good; it only considers a branch merged if it is either reachable from the
current head, or from its own upstream. In many cases I want to delete a branch
that has been merged to master, but I don't have master checked out, so the
current branch is really irrelevant, and it should rather (or in addition) check
whether the branch is reachable from one of the main branches. The problem is
that git doesn't know what those are.

But lazygit does, so make the check on our side, prompt the user if necessary,
and always use -D. This is both cleaner, and works better.

See this mailing list discussion for more:
https://lore.kernel.org/git/bf6308ce-3914-4b85-a04b-4a9716bac538@haller-berlin.de/
2024-09-28 11:19:32 +02:00
Stefan Haller
c4e5995cb9 Fix bug with deleting remote branch whose name doesn't match local branch 2024-09-28 11:19:32 +02:00