Commit Graph
136 Commits
Author SHA1 Message Date
Stefan HallerandClaude Opus 4.7 b76c1072ff Offer direnv .envrc approval from inside lazygit
When a user switches into a repo whose .envrc hasn't been approved with
`direnv allow`, the previous behavior was to drop a "blocked" error
popup and leave the user to fix it externally. That meant opening a
terminal, running `direnv allow`, and then either restarting lazygit or
switching repos and back to refresh the env — easy to get wrong, easy
to forget.

When `direnv export json` exits non-zero, follow up with `direnv status
--json` to ask direnv whether the current directory has a not-yet-
allowed .envrc, and if so, get its path. Then show a confirmation popup
with the .envrc contents inline so the user can read what they're
approving. Confirming runs `direnv allow <path>` and re-runs the load
so the new env reaches subprocesses immediately; cancelling leaves the
env unloaded (the same state as before this commit when direnv refused
to load the .envrc).

Using `direnv status --json` instead of parsing the "is blocked"
stderr line means we rely on direnv's structured output rather than
its human-readable error format, which is more stable across versions
and avoids assumptions about output formatting.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-04 09:05:01 +02:00
Stefan HallerandClaude Opus 4.7 bb8955f2de Load direnv environment when switching repos
When a user opens a repo from the recent-repos menu or jumps between
worktrees inside lazygit, only the env vars present at process startup
reach subprocesses. That breaks pre-commit hooks and other tools whose
dependencies are pulled in by a per-repo .envrc — users were left with
read-only operations because the env their shell would normally load via
direnv never made it into lazygit's git invocations.

Shell out to `direnv export json` after each chdir and apply the JSON
delta via os.Setenv/Unsetenv. direnv tracks the previous load in its own
DIRENV_DIFF env var, so the delta also unloads vars from the old repo
when entering one without a matching .envrc. If direnv isn't on PATH the
call is a no-op, so users who don't use direnv pay nothing and users who
do need no config to opt in. Any stderr direnv emits (loading messages,
"blocked .envrc" errors, etc.) goes to the command log.

The integration test puts a fake direnv on PATH and asserts that a value
it exports reaches a custom command after switching repos. Wiring this
up needed runner.go to support `{{actualPath}}` placeholders in
ExtraEnvVars, mirroring the existing support for ExtraCmdArgs, so the
test can prepend a fixture-relative directory to PATH.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-04 09:05:01 +02:00
Stefan Haller 2601556189 Dedupe the recent-repos fallback in setupRepo
The for-loop here was a verbatim copy of openRecentRepo, so call that instead.
2026-06-04 09:05:01 +02:00
Stefan Haller 685dfc87a4 Cleanup: drop unneeded variable 2026-06-04 09:05:01 +02:00
Stefan Haller 05b27c390d Make the minimum required git version a placeholder in the error text
This way we don't have to update the text and all translations every time we
bump the version.

Remove the year from the error text, it's cumbersome to update and I don't find
it very important to have in the message.

Also remove the invitation to file an issue; I don't find it very likely that we
are going to relax the minimum git requirement again.
2025-07-28 13:10:25 +02:00
Stefan Haller e27422f894 Bump minimum required git version to 2.32
The version choice is a little arbitrary, but see discussion at
https://github.com/jesseduffield/lazygit/pull/4559#issuecomment-2876201680.

The main reason why I'm updating the version now is that versions before 2.27
had a bug with branch sorting, where sorting by -committerdate (which will be
our default soon) would sort branches that point at the same commit in reverse
alphabetical order rather than alphabetical order. While this is only slightly
annoying but not a huge deal for users, it makes maintaining our integration
tests across versions very hard. So I wanted to update to at least 2.27 to get
around this problem, and went with 2.32 after the discussion linked to above.

The choice of which versions to run integration tests on is pretty arbitrary
too, I just picked some at random which are about 5 to 6 minor versions apart.
2025-07-09 12:18:57 +02:00
Stefan Haller 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
Stefan Haller ad813503fb Bump minimum required git version to 2.22
Versions older than 2.22 have issues with "git cherry-pick --continue" and
"git cherry-pick --skip" that are difficult to work around.
2025-04-09 10:40:52 +02:00
Stefan Haller 2499a6c8a3 Initialize translation set after reading user config
This allows having per-repo config files with different languages per repo. Now
granted, this is not an important use case that we need to support; however, the
goal is to eventually make all configs hot-reloadable (as opposed to loading
them only once at startup), so this is one step in that direction.
2024-08-18 10:24:52 +02:00
Stefan Haller f98b57aa5e Change direct access to Common.UserConfig to a getter
This will allow us to turn the field into an atomic.Value for safe concurrent
access.
2024-08-18 10:24:52 +02:00
ppoum ef4fd70f9c Ignore GetRepoPaths error when launching 2024-08-03 10:02:47 -04:00
John Whitley 7a670964cd Optimize number of early calls to GetRepoPaths
This change reduces the number of calls during application startup to
one, calling GetRepoPaths() earlier than previously and plumbing the
repoPaths struct around to achieve this end.
2024-07-06 12:09:48 -07: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
Stefan Haller 18c5780485 Add AppState to common.Common 2023-09-04 17:48:39 +02:00
Jesse Duffield e33fe37a99 Standardise on using lo for slice functions
We've been sometimes using lo and sometimes using my slices package, and we need to pick one
for consistency. Lo is more extensive and better maintained so we're going with that.

My slices package was a superset of go's own slices package so in some places I've just used
the official one (the methods were just wrappers anyway).

I've also moved the remaining methods into the utils package.
2023-07-30 18:51:23 +10:00
Jesse Duffield 7b302d8c29 Write unit tests with the help of afero
Afero is a package that lets you mock out a filesystem with an in-memory filesystem.
It allows us to easily create the files required for a given test without worrying about
a cleanup step or different tests tripping on eachother when run in parallel.

Later on I'll standardise on using afero over the vanilla os package
2023-07-30 18:35:36 +10:00
Jesse Duffield d4eae73a68 Do not quote initial branch arg when creating repo
Also, we shouldn't pass the initial branch arg if it's empty.
2023-07-11 17:18:58 +10:00
Jesse Duffield c92e687d3b Fix focus issue when opening recent-repos menu at launch
I don't know why we were setting the initial context to CurrentSideContext
and not just CurrentContext in the first place. If there is no current context
in either case it'll default to the files context. So the only issue is if
we anticipated that some random context would be focused and we didn't want to
activate that. But I can't think of any situation where that would happen.
2023-06-07 18:27:18 +10:00
Jesse Duffield e0ecc9e835 Allow global logging when developing
I'll be honest, for all I know logging should be global in general: it is
a pain to pass a logger to any struct that needs it. But smart people on the
internet tell me otherwise, and I do like the idea of not having any global
variables lying around.

Nonetheless, I often need to log things when locally debugging and that's a
different kind of logging than the kind you would include in the actual
released binary. For example if I want to log something from gocui, I would
rather not have gocui depend on lazygit's logging setup.
2023-05-25 18:31:32 +10:00
Jesse Duffield 63dc07fded Construct arg vector manually rather than parse string
By constructing an arg vector manually, we no longer need to quote arguments

Mandate that args must be passed when building a command

Now you need to provide an args array when building a command.
There are a handful of places where we need to deal with a string,
such as with user-defined custom commands, and for those we now require
that at the callsite they use str.ToArgv to do that. I don't want
to provide a method out of the box for it because I want to discourage its
use.

For some reason we were invoking a command through a shell when amending a
commit, and I don't believe we needed to do that as there was nothing user-
supplied about the command. So I've switched to using a regular command out-
side the shell there
2023-05-23 19:49:19 +10:00
Jesse Duffield 8edad826ca Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the
gui package purely for the sake of better encapsulation
2023-04-30 13:19:52 +10:00
Stefan Haller bb856ad7c6 Bump minimum required git version to 2.20
We need this because the next commit is going to make use of the "break"
interactive rebase instruction, which was added in 2.20.
2023-02-19 10:20:14 +01:00
Ryooooooga cd9111837e feat: add GitVersion struct 2022-12-30 20:01:14 +09:00
Ryooooooga 41222f07ed chore(gui): remove unused gitConfig 2022-12-30 20:01:14 +09:00
nullishamy 956372cf8a Run gofumpt 2022-08-18 18:26:34 +01:00
nullishamyandGitHub 21a4522a51 Merge branch 'master' into feat/detect-bare-repo 2022-08-15 14:00:34 +01:00
nullishamy 154bd975a6 Apply refactoring suggestions 2022-08-15 13:59:34 +01:00
Jesse DuffieldandGitHub 4aea005f26 Merge pull request #2098 from Ryooooooga/feature/not-a-repository-quit 2022-08-14 17:37:07 +10:00
Jesse Duffield ba96baee32 move code from main into app package to allow test to be injected 2022-08-13 13:55:08 +10:00
Jesse Duffield d890238c7b move input and assert into integration tests package 2022-08-13 13:52:13 +10:00
Jesse Duffield 46ae55f91e introduce gui adapter 2022-08-13 13:51:56 +10:00
Ryooooooga 8b371ada73 feat(config): add notARepository: quit 2022-08-08 18:11:58 +09:00
nullishamy 0b4f9f8c76 Refactor branching logic 2022-08-01 21:58:00 +01:00
nullishamy a658cd4076 Factor out opening of recent repos 2022-08-01 20:05:35 +01:00
nullishamy 69718fb557 Factor out redundant statement 2022-08-01 19:39:39 +01:00
nullishamy b9b2f58bc8 Format, bug fixes 2022-08-01 17:41:20 +01:00
nullishamy 2866827ca8 Apply suggestions from code review 2022-08-01 17:05:16 +01:00
nullishamyandGitHub 9987e65c35 Merge branch 'master' into feat/detect-bare-repo 2022-08-01 03:14:49 +01:00
Luka Markušić 9c6239df3d Worktrees should not be filtered out
But non-git directories should
2022-07-30 17:03:30 +02:00
nullishamy 41b54d742f Check for bare repositories 2022-07-29 23:55:34 +01:00
Luka Markušić f1efa02640 Ask for initial branch name 2022-06-30 13:53:58 +02:00
Jesse DuffieldandGitHub 32c0b39dbd Merge pull request #1950 from HiromasaNojima/add_subcommand_into_specific_layout_directly 2022-06-11 11:51:14 +10:00
Jesse Duffield b1e4968d0b allow opening lazygit to a specific panel 2022-06-11 11:23:56 +10:00
Luka MarkušićandJesse Duffield a955dbcfd7 Validate recent repo before blindly opening it 2022-06-11 09:42:51 +10:00
Luka MarkušićandJesse Duffield 658a6b239b Fix parsing of 'y/n' when starting in non-repo 2022-06-11 09:42:51 +10:00
Jesse DuffieldandGitHub 499d51ecf6 Merge pull request #1931 from mark2185/fix-non-existant-recent-repo 2022-05-18 22:22:28 +10:00
Ryooooooga 9693afd671 fix: fix lint error 2022-05-18 20:34:35 +09:00
Luka Markušić 1de5ca3511 Don't panic when there are no valid git repos 2022-05-17 07:28:52 +02:00
Jesse Duffield cd5b041b0f clearer separation of concerns when bootstrapping application 2022-05-07 16:02:04 +10:00
RyoooooogaandJesse Duffield 86c259623c feat: fix permission problem of temp dirs 2022-04-02 08:48:38 +11:00