1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00
Commit Graph

5020 Commits

Author SHA1 Message Date
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
080aa78266
Do not include keybindings from another view in keybindings menu (#3220)
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.

- **PR Description**

- **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)
* [x] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] 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-01-15 20:17:33 +11: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
README-bot
d4a0ca35c7 Updated README.md 2024-01-15 03:45:52 +00:00
Jesse Duffield
f79305090b
Show Toast instead of error panel when invoking a disabled command (#3180)
- **PR Description**

Addresses #3116.

I'm not 100% sure I like the behavior, but I put it out there so that
others can test it and form an opinion. It not only affects keybindings,
but also invoking menu items (either with enter or with their key
binding): the menu now stays open in that case, which I think is
actually better.

There's a horrible hack for keeping the integration tests working, I
don't have a good idea how to fix that for real. Suggestions welcome.
2024-01-15 14:45:39 +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
37590a495c
Add 'Quick start interactive rebase' action (#3213)
- **PR Description**

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.

- **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-01-13 22:39:06 +11: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
23a98937b4 Update README to add backticks to key
Missed a spot when I originally wrote this
2024-01-13 12:57:49 +11:00
Jesse Duffield
a0b63090e0 Update codebase guide
I'm adding a couple more terms: Keybinding and Action, to keep things standardised
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
Jesse Duffield
e9962b98a7
Set working directory in lazygit test command (#3215)
We need to fetch our list of tests both outside of our test binary and
within. We need to get the list from within so that we can run the code
that drives the test and runs assertions. To get the list of tests we
need to know where the root of the lazygit repo is, given that the tests
live in files under that root.

So far, we've used this GetLazyRootDirectory() function for that, but it
assumes that we're not in a test directory (it just looks for the first
.git dir it can find). Because we didn't want to properly fix this
before, we've been setting the working directory of the test command to
the lazygit root, and using the --path CLI arg to override it when the
test itself ran. This was a terrible hack.

Now, we're passing the lazygit root directory as an env var to the
integration test, so that we can set the working directory to the actual
path of the test repo; removing the need to use the --path arg.

- **PR Description**

- **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-01-12 23:33:26 +11:00
Jesse Duffield
a1ce6029c1 Pass -f as single arg in integration test
For some bizarre reason `pkg/integration/tests/filter_by_path/cli_arg.go` is failing as of 8c716184 like so:

```
test_lazygit

  Usage:
    test_lazygit [git-arg]

  Positional Variables:
    git-arg   Panel to focus upon opening lazygit. Accepted values (based on git terminology): status, branch, log, stash. Ignored if --filter arg is passed.
  Flags:
    -h --help               Displays help with available flag, subcommand, and positional value parameters.
    -p --path               Path of git repo. (equivalent to --work-tree=<path> --git-dir=<path>/.git/)
    -f --filter             Path to filter on in `git log -- <path>`. When in filter mode, the commits, reflog, and stash are filtered based on the given path, and some operations are restricted
    -v --version            Print the current version
    -d --debug              Run in debug mode with logging (see --logs flag below). Use the LOG_LEVEL env var to set the log level (debug/info/warn/error) (default: false)
    -l --logs               Tail lazygit logs (intended to be used when `lazygit --debug` is called in a separate terminal tab)
    -c --config             Print the default config
    -cd --print-config-dir   Print the config directory
    -ucd --use-config-dir     override default config directory with provided directory
    -w --work-tree          equivalent of the --work-tree git argument
    -g --git-dir            equivalent of the --git-dir git argument
    -ucf --use-config-file    Comma separated list to custom config file(s)

Unknown arguments supplied:  filterFile
```

where the CLI args are:
```
([]string) (len=5 cap=5) {
 (string) (len=25) "/tmp/lazygit/test_lazygit",
 (string) (len=6) "-debug",
 (string) (len=108) "--use-config-dir=/Users/jesseduffieldduffield/repos/lazygit/test/_results/filter_by_path/cli_arg/used_config",
 (string) (len=2) "-f",
 (string) (len=10) "filterFile"
}
```

This appears to be a bug in flaggy itself. I've updated to the latest version but it still breaks. Bizarrely it works fine on CI and
only fails locally. Running lazygit locally with `lg -f pkg/gui/controllers/helpers/refresh_helper.go` it works fine. So I don't
know what's going on there. At any rate, I'm just going to get the test passing by passing `-f=filterFile` as a single argument.
2024-01-12 20:19:50 +11:00
Jesse Duffield
8c716184c1 Set working directory in lazygit test command
We need to fetch our list of tests both outside of our test binary and within. We need
to get the list from within so that we can run the code that drives the test and runs
assertions. To get the list of tests we need to know where the root of the lazygit repo
is, given that the tests live in files under that root.

So far, we've used this GetLazyRootDirectory() function for that, but it assumes that
we're not in a test directory (it just looks for the first .git dir it can find). Because
we didn't want to properly fix this before, we've been setting the working directory of
the test command to the lazygit root, and using the --path CLI arg to override it when
the test itself ran. This was a terrible hack.

Now, we're passing the lazygit root directory as an env var to the integration test, so
that we can set the working directory to the actual path of the test repo; removing the
need to use the --path arg.
2024-01-12 19:59:31 +11:00
Jesse Duffield
5c888a0b47 Update codebase guide
fixes a line that used an incorrect path
2024-01-11 09:57:05 +11:00
Jesse Duffield
498092a8ec
Add codebase guide (#3206)
- **PR Description**

After reading through some AI-generated lazygit docs, it occurred to me
that we should actually be documenting some of this stuff ourselves.

Contributors can feel free to add stuff to this guide if they think it
provides useful context.

- **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-01-11 09:50:51 +11:00
Jesse Duffield
caf6a3629d Add codebase guide 2024-01-11 09:43:38 +11:00
Stefan Haller
1ca96bbe5b
Fix keybindings for characters involving AltGr on Windows (#3194) 2024-01-10 09:42:30 +01:00
Stefan Haller
cb5d0bca1c Bump gocui
... and switch back from stefanhaller's tcell fork to the official tcell. This
basically reverts 7ccb871a45.
2024-01-10 09:39:25 +01:00
Stefan Haller
ef3d6f4a32
Support insteadOf URL rewriting when opening URLs in browser (#3177) 2024-01-10 09:29:26 +01:00
Stefan Haller
b470442a46 Obtain remote URL by calling "ls-remote --get-url" instead of using git config
This has the advantage that it still works when the user has configured aliases
using the insteadOf feature [1].

[1] https://git-scm.com/docs/git-config/2.42.0#Documentation/git-config.txt-urlltbasegtinsteadOf)
2024-01-10 09:24:23 +01:00
Stefan Haller
bf01c0b00e
Allow multiple fetch commands (or fetch and pull) to run concurrently (#3202) 2024-01-10 09:23:22 +01:00
Stefan Haller
76e39af76f Allow multiple fetch commands (or fetch and pull) to run concurrently
Git has a bug [1] whereby running multiple fetch commands at the same time
causes all of them to append their information to the .git/FETCH_HEAD file,
causing the next git pull that wants to use the information to become confused,
and show an error like "Cannot rebase onto multiple branches". This error would
occur when pressing "f" and "p" in quick succession in the files panel, but also
when pressing "p" while a background fetch happens to be running. One likely
situation for this is pressing "p" right after startup.

Since lazygit never uses the information written to .git/FETCH_HEAD, it's best
to avoid writing to it, which fixes the scenarios described above.

However, it doesn't fix the problem of repeatedly pressing "f" quickly on the
checked-out branch; since we call "git pull" in that case, the above fix doesn't
help there. We'll address this separately in another PR.

[1] See https://public-inbox.org/git/xmqqy1daffk8.fsf@gitster.g/ for more
information.
2024-01-10 09:18:38 +01:00
Stefan Haller
5b91cd0cc8 Extract a function fetchCommandBuilder 2024-01-10 09:18:38 +01:00
Stefan Haller
6255728e63 Add a method GitVersion.IsAtLeast 2024-01-10 09:18:38 +01:00
README-bot
b657fc4f0b Updated README.md 2024-01-10 08:17:42 +00:00
Stefan Haller
d294d51791
Add command to find base commit for creating a fixup (#3105) 2024-01-10 09:17:29 +01:00
Stefan Haller
b35f8776e1 Warn when there are hunks with only added lines
The algorithm works by blaming the deleted lines, so if a hunk contains only
added lines, we can only hope that it also belongs in the same commit. Warn the
user about this.

Note: the warning might be overly agressive, we'll have to see if this is
annoying. The reason is that it depends on the diff context size whether added
lines go into their own hunk or are grouped together with other added or deleted
lines into one hunk. However, our algorithm uses a diff context size of 0,
because that makes it easiest to parse the diff; this results in hunks having
only added lines more often than what the user sees. For example, moving a line
of code down by two lines will likely result in a single hunk for the user, but
in two hunks for our algorithm. On the other hand, being this strict makes the
warning consistent. We could consider using the user's diff context size in the
algorithm, but then it would depend on the current context size whether the
warning appears, which could be confusing. Plus, it would make the algorithm
quite a bit more complicated.
2024-01-10 09:11:40 +01:00
Stefan Haller
8ca78412ac Add command to find base commit for creating a fixup 2024-01-10 09:11:40 +01:00
Stefan Haller
33f933ba21
Add config setting for splitting window vertically in half screen mode (#3133) 2024-01-09 15:53:32 +01:00
Stefan Haller
d70dd5123d Add config setting for side panel location (left or top) in half screen mode 2024-01-09 15:45:26 +01:00
Stefan Haller
15da702140
Fix preserving the commit message when description contains blank lines (#3170) 2024-01-09 14:35:43 +01:00
Stefan Haller
cd50c79ae4 Preserve the commit message correctly even if the description has blank lines
There are two possible fixes for this bug, and they differ in behavior when
rewording a commit. The one I chose here always splits at the first line feed,
which means that for an improperly formatted commit message such as this one:

   This is a very long multi-line subject,
   which you shouldn't really use in git.

   And this is the body (we call it "description" in lazygit).

we split after the first line instead of after the first paragraph. This is
arguably not what the original author meant, but splitting after the first
paragraph doesn't really work well in lazygit, because we would try to put both
lines into the one-line subject field of the message panel, and you'd only see
the second and not even know that there are more.

The other potential fix would have been to join subject and description with two
line feeds instead of one in JoinCommitMessageAndDescription; this would have
fixed our bug in the same way, but would result in splitting the above message
after the second line instead of the first. I think that's worse, so I decided
for the first fix.

While we're at it, simplify the code a little bit; strings.Cut is documented to
return (s, "") when the separator is not found, so there's no need to do this on
our side.

We do have to trim spaces on the description now, to support the regular reword
case where subject and body are separated by a blank line.
2024-01-09 14:31:53 +01:00
Stefan Haller
3ebba5f32c Add test demonstrating a bug with preserving the commit message
SplitCommitMessageAndDescription splits at the first '\n\n' that it finds (if
there is one), which in this case is between the two paragraphs of the
description. This is wrong.
2024-01-09 14:31:53 +01:00
Stefan Haller
9a423c388d Remove unused function
I think this is a left-over from before we had the new commit message panel. It
no longer makes sense to add a newline to the commit subject.
2024-01-09 14:31:53 +01:00
Stefan Haller
daf9b8cfa9 Simplify GetCommitMessage
Use git log instead of git rev-list, this way we don't get a line "commit <sha>"
at the beginning that we then have to discard again.

The test TestGetCommitMsg is becoming a bit pointless now, since it just
compares that input and output are identical.
2024-01-09 14:31:53 +01:00
README-bot
b6a9220343 Updated README.md 2024-01-09 13:30:54 +00:00
Stefan Haller
aeb017e029
Add command to open git difftool (#3156) 2024-01-09 14:29:26 +01:00
Stefan Haller
a6174271aa Update cheat sheets and json schema 2024-01-09 14:27:33 +01:00
Stefan Haller
517e0f8248 Add command to open git difftool 2024-01-09 14:27:33 +01:00
Stefan Haller
c1cb95db6f Remove unused function 2024-01-09 14:24:14 +01:00
Stefan Haller
966e5f5337
Fix checking out a tag when there is a branch with the same name (#3179) 2024-01-09 14:23:08 +01:00
Stefan Haller
f244ec8251 Fix checking out a tag when a branch with the same name exists 2024-01-09 14:18:35 +01:00
Stefan Haller
2b97f0fb43 Add test demonstrating the problem
When there's a branch with the same name as the tag, the branch gets checked out
instead of the tag.
2024-01-09 14:18:35 +01:00