misc

package
v0.63.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfirmOnQuit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Quitting with a confirm prompt",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().ConfirmOnQuit = true
	},
	SetupRepo: func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Press(keys.Universal.Quit)

		t.ExpectPopup().Confirmation().
			Title(Equals("")).
			Content(Contains("Are you sure you want to quit?")).
			Confirm()
	},
})
View Source
var CopyConfirmationMessageToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Copy the text of a confirmation popup to the clipboard",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
	},

	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("commit")
	},

	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("commit").IsSelected(),
			).
			Press(keys.Universal.Remove)

		t.ExpectPopup().Alert().
			Title(Equals("Drop commit")).
			Content(Equals("Are you sure you want to drop the selected commit(s)?")).
			Tap(func() {
				t.GlobalPress(keys.Universal.CopyToClipboard)
				t.ExpectToast(Equals("Message copied to clipboard"))
			}).
			Confirm()

		t.FileSystem().FileContent("clipboard",
			Equals("Are you sure you want to drop the selected commit(s)?"))
	},
})
View Source
var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Copy a branch name to the clipboard using custom clipboard command template",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
	},

	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-a")
	},

	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("branch-a").IsSelected(),
			).
			Press(keys.Universal.CopyToClipboard)

		t.ExpectToast(Equals("'branch-a' copied to clipboard"))

		t.FileSystem().FileContent("clipboard", Equals("branch-a"))
	},
})
View Source
var DirenvApprovesEnvrc = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Approving a blocked .envrc from the in-app popup loads its env",
	ExtraCmdArgs: []string{},
	ExtraEnvVars: map[string]string{
		"PATH": "{{actualPath}}/bin:" + os.Getenv("PATH"),
	},
	SetupConfig: func(cfg *config.AppConfig) {
		otherRepo, _ := filepath.Abs("../other")
		cfg.GetAppState().RecentRepos = []string{otherRepo}
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     config.Keybinding{"X"},
				Context: "files",
				Command: `echo "VAR=$LG_DIRENV_TEST" > output.txt`,
			},
		}
	},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial")
		shell.CloneNonBare("other")

		shell.CreateFile("../other/.envrc", "export LG_DIRENV_TEST=approved_value\n")

		shell.CreateFile("../bin/direnv", `#!/bin/sh
SENTINEL="$(dirname "$0")/.approved"
case "$1 $2" in
"allow "*)
    touch "$SENTINEL"
    exit 0
    ;;
"export json")
    if [ -f "$SENTINEL" ]; then
        echo '{"LG_DIRENV_TEST":"approved_value"}'
        echo "direnv: loading $PWD/.envrc" >&2
    else
        echo '{"LG_DIRENV_TEST":null}'
        echo "direnv: error $PWD/.envrc is blocked" >&2
        exit 1
    fi
    ;;
"status --json")
    if [ -f "$SENTINEL" ]; then
        printf '{"state":{"foundRC":{"allowed":0,"path":"%s/.envrc"}}}\n' "$PWD"
    else
        printf '{"state":{"foundRC":{"allowed":1,"path":"%s/.envrc"}}}\n' "$PWD"
    fi
    ;;
esac
`)
		shell.MakeExecutable("../bin/direnv")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.GlobalPress(keys.Universal.OpenRecentRepos)
		t.ExpectPopup().Menu().Title(Equals("Recent repositories")).
			Lines(
				Contains("other").IsSelected(),
				Contains("Cancel"),
			).
			Confirm()

		t.ExpectPopup().Confirmation().
			Title(Equals("Approve .envrc?")).
			Content(Contains("export LG_DIRENV_TEST=approved_value")).
			Confirm()

		t.Views().Files().
			Focus().
			Press(config.Keybinding{"X"}).
			NavigateToLine(Contains("output.txt"))
		t.Views().Main().Content(Contains("VAR=approved_value"))
	},
})

When the new repo's .envrc is blocked, lazygit offers the user a popup to approve it without leaving the app. Confirming runs `direnv allow` and re-runs the load so the env reaches subprocesses immediately.

View Source
var DirenvLoadedOnRepoSwitch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Switching repos applies direnv-loaded env vars to subprocesses",
	ExtraCmdArgs: []string{},
	ExtraEnvVars: map[string]string{

		"PATH": "{{actualPath}}/bin:" + os.Getenv("PATH"),
	},
	SetupConfig: func(cfg *config.AppConfig) {
		otherRepo, _ := filepath.Abs("../other")
		cfg.GetAppState().RecentRepos = []string{otherRepo}
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     config.Keybinding{"X"},
				Context: "files",
				Command: `echo "VAR=$LG_DIRENV_TEST" > output.txt`,
			},
		}
	},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial")
		shell.CloneNonBare("other")

		shell.CreateFile("../bin/direnv", `#!/bin/sh
echo '{"LG_DIRENV_TEST":"from_direnv"}'
echo "direnv: loading .envrc" >&2
`)
		shell.MakeExecutable("../bin/direnv")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.GlobalPress(keys.Universal.OpenRecentRepos)
		t.ExpectPopup().Menu().Title(Equals("Recent repositories")).
			Lines(
				Contains("other").IsSelected(),
				Contains("Cancel"),
			).
			Confirm()

		t.Views().Files().
			Focus().
			Press(config.Keybinding{"X"}).
			Lines(
				Contains("output.txt").IsSelected(),
			)
		t.Views().Main().Content(Contains("VAR=from_direnv"))
	},
})

Verifies that when the user switches repos from inside lazygit, env vars that direnv would load for the target repo are applied to subprocesses (custom commands, git hooks, etc.). The test puts a fake `direnv` binary on PATH so it works regardless of whether the host has real direnv installed.

View Source
var DirenvUnloadsOnBlockedEnvrc = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Blocked .envrc unloads the previous repo's env even if the user skips approval",
	ExtraCmdArgs: []string{},
	ExtraEnvVars: map[string]string{
		"PATH": "{{actualPath}}/bin:" + os.Getenv("PATH"),

		"LG_DIRENV_TEST": "from_previous_repo",
	},
	SetupConfig: func(cfg *config.AppConfig) {
		otherRepo, _ := filepath.Abs("../other")
		cfg.GetAppState().RecentRepos = []string{otherRepo}
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     config.Keybinding{"X"},
				Context: "files",
				Command: `echo "VAR=[$LG_DIRENV_TEST]" > output.txt`,
			},
		}
	},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial")
		shell.CloneNonBare("other")

		shell.CreateFile("../other/.envrc", "export LG_DIRENV_TEST=from_envrc\n")

		shell.CreateFile("../bin/direnv", `#!/bin/sh
case "$1 $2" in
"export json")
    echo '{"LG_DIRENV_TEST":null}'
    echo "direnv: error $PWD/.envrc is blocked" >&2
    exit 1
    ;;
"status --json")
    printf '{"state":{"foundRC":{"allowed":1,"path":"%s/.envrc"}}}\n' "$PWD"
    ;;
esac
`)
		shell.MakeExecutable("../bin/direnv")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.GlobalPress(keys.Universal.OpenRecentRepos)
		t.ExpectPopup().Menu().Title(Equals("Recent repositories")).
			Lines(
				Contains("other").IsSelected(),
				Contains("Cancel"),
			).
			Confirm()

		t.ExpectPopup().Confirmation().
			Title(Equals("Approve .envrc?")).
			Content(Contains("export LG_DIRENV_TEST=from_envrc")).
			Cancel()

		t.Views().Files().
			Focus().
			Press(config.Keybinding{"X"}).
			NavigateToLine(Contains("output.txt"))
		t.Views().Main().Content(Contains("VAR=[]"))
	},
})

Real direnv exits non-zero when the destination .envrc isn't authorized, but it still emits a valid JSON delta on stdout that unloads vars from the previously-active .envrc. We have to apply that delta anyway, or the previous repo's env leaks into the new one. This test exercises the "skip approval" branch: the approval popup appears, the user cancels, and the previous repo's env is still gone.

View Source
var InitialOpen = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Confirms a popup appears on first opening Lazygit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().DisableStartupPopups = false
	},
	SetupRepo: func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.ExpectPopup().Confirmation().
			Title(Equals("")).
			Content(Contains("Thanks for using lazygit!")).
			Confirm()

		t.Views().Files().IsFocused()
	},
})
View Source
var RecentReposOnLaunch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "When opening to a menu, focus is correctly given to the menu",
	ExtraCmdArgs: []string{},
	ExtraEnvVars: map[string]string{
		"SHOW_RECENT_REPOS": "true",
	},
	Skip:        false,
	SetupConfig: func(config *config.AppConfig) {},
	SetupRepo:   func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.ExpectPopup().Menu().
			Title(Equals("Recent repositories")).
			Select(Contains("Cancel")).
			Confirm()

		t.Views().Files().IsFocused()
	},
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL