jesseduffield.lazygit/pkg/gui/controllers/helpers
Stefan Haller 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
..
amend_helper.go Allow passing refresh scope to WithGpgHandling 2025-03-24 08:41:58 +01:00
app_status_helper.go Fix the waiting status display for synchronous operations 2026-05-30 14:20:05 +02:00
bisect_helper.go Change Refresh to not return an error 2025-07-02 16:09:42 +02:00
branches_helper.go Refresh worktrees before auto-forwarding branches 2026-05-21 13:59:18 +02:00
cherry_pick_helper.go Clear cherry-pick buffer when copying after a paste 2026-05-09 14:02:42 +02:00
commits_helper.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
commits_helper_test.go Remove hard line breaks when rewording commits 2024-03-09 10:00:44 +01:00
confirmation_helper.go Add comments 2026-03-08 17:24:26 +01:00
credentials_helper.go chore: fix function name in comment 2025-12-06 18:28:58 +08:00
diff_helper.go Move the Ref interface from gui/types to models 2025-07-31 15:21:34 +02:00
files_helper.go Cleanup: remove unused interfaces for helpers 2025-04-08 16:08:25 +02:00
fixup_helper.go Ignore fixup commits for a found base commit when doing ctrl-f 2026-01-24 16:04:35 +01:00
fixup_helper_test.go Ignore fixup commits for a found base commit when doing ctrl-f 2026-01-24 16:04:35 +01:00
gpg_helper.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00
helpers.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
host_helper.go Cleanup: remove unused interfaces for helpers 2025-04-08 16:08:25 +02:00
inline_status_helper.go Improve performance of inline status spinner 2026-05-09 13:58:33 +02:00
menu_key.go Use a slice of keys for each binding 2026-05-25 15:18:18 +02:00
merge_and_rebase_helper.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
merge_conflicts_helper.go Cleanup: get rid of the variadic parameter of ContextMgr.Push 2025-04-08 16:08:25 +02:00
mode_helper.go Show context-specific labels for the global <esc> binding 2025-08-14 17:59:38 +02:00
patch_building_helper.go Cleanup: remove unnecessary function Label() 2026-04-30 22:14:26 +02:00
record_directory_helper.go split context common from helper common 2023-04-30 13:19:53 +10:00
refresh_helper.go Preserve empty Worktrees slice when worktree list fails to load 2026-05-21 13:57:46 +02:00
refresh_helper_test.go Support GitHub Enterprise for the pull-requests feature 2026-05-10 15:28:14 +02:00
refs_helper.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
repos_helper.go Load direnv environment when switching repos 2026-06-04 09:05:01 +02:00
search_helper.go Cleanup: remove unnecessary function Label() 2026-04-30 22:14:26 +02:00
signal_handling.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
signal_handling_windows.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
snake_helper.go Bump gocui and adapt lazygit code 2024-12-01 10:40:08 +01:00
staging_helper.go Add user config to use hunk mode by default when entering staging view 2025-07-04 19:41:40 +02:00
sub_commits_helper.go Scroll to top when showing subcommits 2026-03-27 14:55:02 +01:00
suggestions_helper.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00
suspend_resume_helper.go Implement suspending the app using ctrl-z 2025-08-14 20:41:46 +02:00
tags_helper.go Convert keybinding fields to Keybinding 2026-05-25 15:32:47 +02:00
update_helper.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00
upstream_helper.go Cleanup: remove unused interfaces for helpers 2025-04-08 16:08:25 +02:00
upstream_helper_test.go Standardise on using lo for slice functions 2023-07-30 18:51:23 +10:00
view_helper.go standardise helper args 2023-04-30 13:19:53 +10:00
window_arrangement_helper.go Allow customizing the window width/height thresholds for when to use portrait mode 2026-03-31 13:08:46 +02:00
window_arrangement_helper_test.go Allow customizing the window width/height thresholds for when to use portrait mode 2026-03-31 13:08:46 +02:00
window_helper.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00
working_tree_helper.go Rename Key to Keys in Binding, KeybindingsOpts, and MenuItem 2026-05-25 15:18:18 +02:00
worktree_helper.go Copy gocui files into lazygit repo under pkg/gocui 2026-04-30 14:29:08 +02:00