custom_commands

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessCommitProperties = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Run a command that accesses properties of a commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("my change")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "commits",
				Command: "printf '%s\n%s\n%s' '{{ .SelectedLocalCommit.Name }}' '{{ .SelectedLocalCommit.Hash }}' '{{ .SelectedLocalCommit.Sha }}' > file.txt",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("my change").IsSelected(),
			).
			Press("X")

		hash := t.Git().GetCommitHash("HEAD")
		t.FileSystem().FileContent("file.txt", Equals(fmt.Sprintf("my change\n%s\n%s", hash, hash)))
	},
})
View Source
var BasicCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command to create a new file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: "touch myfile",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a").
			Lines(
				Contains("myfile"),
			)
	},
})
View Source
var CheckForConflicts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Run a command and check for conflicts after",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shared.MergeConflictsSetup(shell)
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "m",
				Context: "localBranches",
				Command: "git merge {{ .SelectedLocalBranch.Name | quote }}",
				After: &config.CustomCommandAfterHook{
					CheckForConflicts: true,
				},
			},
		}

		cfg.GetUserConfig().Git.LocalBranchSortOrder = "recency"
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			TopLines(
				Contains("first-change-branch"),
				Contains("second-change-branch"),
			).
			NavigateToLine(Contains("second-change-branch")).
			Press("m")

		t.Common().AcknowledgeConflicts()
	},
})
View Source
var ConditionalPromptFalseString = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Conditional prompt is skipped when condition is bare false or template false",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo "{{.Form.Choice}}" > result.txt`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Choice",
						Type:  "menu",
						Title: "Pick one",
						Options: []config.CustomCommandMenuOption{
							{
								Name:        "foo",
								Description: "Foo",
								Value:       "FOO",
							},
							{
								Name:        "bar",
								Description: "Bar",
								Value:       "BAR",
							},
						},
					},
					{
						Key:       "Skipped1",
						Type:      "input",
						Title:     "This is always skipped (false)",
						Condition: `false`,
					},
					{
						Key:       "Skipped2",
						Type:      "input",
						Title:     "This is always skipped (template false)",
						Condition: `{{ eq "a" "b" }}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Press("a")

		t.ExpectPopup().Menu().Title(Equals("Pick one")).Select(Contains("foo")).Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("result.txt").IsSelected(),
			)

		t.FileSystem().FileContent("result.txt", Equals("FOO\n"))
	},
})
View Source
var ConditionalPromptFalseValue = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Entering literal false as form input does not incorrectly skip a conditional prompt",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo "{{.Form.Word}} {{.Form.Extra}}" > result.txt`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Word",
						Type:  "input",
						Title: "Enter a word",
					},
					{
						Key:       "Extra",
						Type:      "input",
						Title:     "Enter extra",
						Condition: `{{ eq .Form.Word "false" }}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Press("a")

		t.ExpectPopup().Prompt().Title(Equals("Enter a word")).Type("false").Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Enter extra")).Type("baz").Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("result.txt").IsSelected(),
			)

		t.FileSystem().FileContent("result.txt", Equals("false baz\n"))
	},
})
View Source
var ConditionalPrompts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command with conditional prompts that are skipped based on form values",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo "{{.Form.Choice}}{{if .Form.Detail}} {{.Form.Detail}}{{end}}" > result.txt`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Choice",
						Type:  "menu",
						Title: "Choose an option",
						Options: []config.CustomCommandMenuOption{
							{
								Name:        "first",
								Description: "First option",
								Value:       "FIRST",
								Key:         "1",
							},
							{
								Name:        "second",
								Description: "Second option",
								Value:       "SECOND",
								Key:         "H",
							},
						},
					},
					{
						Key:       "Detail",
						Type:      "input",
						Title:     "Enter detail for second option",
						Condition: `{{ eq .Form.Choice "SECOND" }}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Files().
			IsFocused().
			Press("a")

		t.ExpectPopup().Menu().
			Title(Equals("Choose an option"))

		t.Views().Menu().Press("1")

		t.Views().Files().
			Focus().
			Lines(
				Contains("result.txt").IsSelected(),
			)

		t.FileSystem().FileContent("result.txt", Equals("FIRST\n"))

		t.Shell().DeleteFile("result.txt")
		t.GlobalPress(keys.Files.RefreshFiles)

		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a")

		t.ExpectPopup().Menu().
			Title(Equals("Choose an option"))

		t.Views().Menu().Press("H")

		t.ExpectPopup().Prompt().Title(Equals("Enter detail for second option")).Type("extra").Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("result.txt").IsSelected(),
			)

		t.FileSystem().FileContent("result.txt", Equals("SECOND extra\n"))
	},
})
View Source
var CustomCommandsSubmenu = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using custom commands from a custom commands menu",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo:    func(shell *Shell) {},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:         "x",
				Description: "My Custom Commands",
				CommandMenu: []config.CustomCommand{
					{
						Key:     "1",
						Context: "global",
						Command: "touch myfile-global",
					},
					{
						Key:     "2",
						Context: "files",
						Command: "touch myfile-files",
					},
					{
						Key:     "3",
						Context: "commits",
						Command: "touch myfile-commits",
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			Focus().
			IsEmpty().
			Press("x").
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("My Custom Commands")).
					Lines(
						Contains("1 touch myfile-global"),
						Contains("2 touch myfile-files"),
					).
					Select(Contains("touch myfile-files")).Confirm()
			}).
			Lines(
				Contains("myfile-files"),
			)

		t.Views().Commits().
			Focus().
			Press("x").
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("My Custom Commands")).
					Lines(
						Contains("1 touch myfile-global"),
						Contains("3 touch myfile-commits"),
					)
				t.GlobalPress("3")
			})

		t.Views().Files().
			Lines(
				Equals("▼ /"),
				Contains("myfile-commits"),
				Contains("myfile-files"),
			)
	},
})
View Source
var CustomCommandsSubmenuWithSpecialKeybindings = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using custom commands from a custom commands menu with keybindings that conflict with builtin ones",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo:    func(shell *Shell) {},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:         "x",
				Description: "My Custom Commands",
				CommandMenu: []config.CustomCommand{
					{
						Key:     "j",
						Context: "global",
						Command: "echo j",
						Output:  "popup",
					},
					{
						Key:     "H",
						Context: "global",
						Command: "echo H",
						Output:  "popup",
					},
					{
						Key:     "y",
						Context: "global",
						Command: "echo y",
						Output:  "popup",
					},
					{
						Key:     "<down>",
						Context: "global",
						Command: "echo down",
						Output:  "popup",
					},
				},
			},
		}
		cfg.GetUserConfig().Keybinding.Universal.ConfirmMenu = "y"
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			Focus().
			IsEmpty().
			Press("x").
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("My Custom Commands")).
					Lines(
						Contains("j echo j"),
						Contains("H echo H"),
						Contains("  echo y"),
						Contains("  echo down"),
					)
				t.GlobalPress("j")
				t.ExpectPopup().Alert().Title(Equals("echo j")).Content(Equals("j")).Confirm()
			}).
			Press("x").
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("My Custom Commands"))
				t.GlobalPress("H")
				t.ExpectPopup().Alert().Title(Equals("echo H")).Content(Equals("H")).Confirm()
			})
	},
})
View Source
var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command referring prompt responses by name",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo {{.Form.FileContent | quote}} > {{.Form.FileName | quote}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "FileName",
						Type:  "input",
						Title: "Enter a file name",
					},
					{
						Key:   "FileContent",
						Type:  "menu",
						Title: "Choose file content",
						Options: []config.CustomCommandMenuOption{
							{
								Name:        "foo",
								Description: "Foo",
								Value:       "FOO",
							},
							{
								Name:        "bar",
								Description: "Bar",
								Value:       `"BAR"`,
							},
							{
								Name:        "baz",
								Description: "Baz",
								Value:       "BAZ",
							},
						},
					},
					{
						Type:  "confirm",
						Title: "Are you sure?",
						Body:  "Are you REALLY sure you want to make this file? Up to you buddy.",
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a")

		t.ExpectPopup().Prompt().Title(Equals("Enter a file name")).Type("my file").Confirm()

		t.ExpectPopup().Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm()

		t.ExpectPopup().Confirmation().
			Title(Equals("Are you sure?")).
			Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
			Confirm()

		t.Views().Files().
			Lines(
				Contains("my file").IsSelected(),
			)

		t.Views().Main().Content(Contains(`"BAR"`))
	},
})
View Source
var GlobalContext = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Ensure global context works",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("my change")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "global",
				Command: "touch myfile",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Commits().
			Focus().
			Press("X")

		t.Views().Files().
			Focus().
			Lines(Contains("myfile"))

		t.Shell().DeleteFile("myfile")
		t.GlobalPress(keys.Files.RefreshFiles)

		t.Views().Branches().
			Focus().
			Press("X")

		t.Views().Files().
			Focus().
			Lines(Contains("myfile"))

		t.Shell().DeleteFile("myfile")
		t.GlobalPress(keys.Files.RefreshFiles)

		t.Views().Files().
			Focus().
			Press("X")

		t.Views().Files().
			Focus().
			Lines(Contains("myfile"))

		t.Shell().DeleteFile("myfile")
	},
})
View Source
var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using menuFromCommand prompt type",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("foo").
			EmptyCommit("bar").
			EmptyCommit("baz").
			NewBranch("feature/foo")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `echo "{{index .PromptResponses 0}} {{index .PromptResponses 1}} {{ .SelectedLocalBranch.Name }}" > output.txt`,
				Prompts: []config.CustomCommandPrompt{
					{
						Type:        "menuFromCommand",
						Title:       "Choose commit message",
						Command:     `git log --oneline --pretty=%B`,
						Filter:      `(?P<commit_message>.*)`,
						ValueFormat: `{{ .commit_message }}`,
						LabelFormat: `{{ .commit_message | yellow }}`,
					},
					{
						Type:         "input",
						Title:        "Description",
						InitialValue: `{{ if .SelectedLocalBranch.Name }}Branch: #{{ .SelectedLocalBranch.Name }}{{end}}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty()

		t.Views().Branches().
			Focus().
			Press("a")

		t.ExpectPopup().Menu().Title(Equals("Choose commit message")).Select(Contains("bar")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Description")).Type(" my branch").Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("output.txt").IsSelected(),
			)

		t.Views().Main().Content(Contains("bar Branch: #feature/foo my branch feature/foo"))
	},
})
View Source
var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using prompt response in menuFromCommand entries",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("foo").
			NewBranch("feature/foo").
			EmptyCommit("bar").
			NewBranch("feature/bar").
			EmptyCommit("baz")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: "git checkout {{ index .PromptResponses 1 }}",
				Prompts: []config.CustomCommandPrompt{
					{
						Type:         "input",
						Title:        "Which git command do you want to run?",
						InitialValue: "branch",
					},
					{
						Type:        "menuFromCommand",
						Title:       "Branch:",
						Command:     `git {{ index .PromptResponses 0 }} --format='%(refname:short)'`,
						Filter:      "(?P<branch>.*)",
						ValueFormat: `{{ .branch }}`,
						LabelFormat: `{{ .branch | green }}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Git().CurrentBranchName("feature/bar")

		t.Views().Branches().
			Focus().
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Which git command do you want to run?")).
			InitialText(Equals("branch")).
			Confirm()

		t.ExpectPopup().Menu().Title(Equals("Branch:")).Select(Equals("master")).Confirm()

		t.Git().CurrentBranchName("master")
	},
})
View Source
var MenuPromptWithKeys = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command with menu options that have keybindings",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo {{.Form.Choice | quote}} > result.txt`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Choice",
						Type:  "menu",
						Title: "Choose an option",
						Options: []config.CustomCommandMenuOption{
							{
								Name:        "first",
								Description: "First option",
								Value:       "FIRST",
								Key:         "1",
							},
							{
								Name:        "second",
								Description: "Second option",
								Value:       "SECOND",
								Key:         "H",
							},
							{
								Name:        "third",
								Description: "Third option",
								Value:       "THIRD",
								Key:         "3",
							},
						},
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Press("a")

		t.ExpectPopup().Menu().
			Title(Equals("Choose an option"))

		t.Views().Menu().Press("H")

		t.FileSystem().FileContent("result.txt", Equals("SECOND\n"))
	},
})
View Source
var MultipleContexts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Test that multiple contexts works",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("my change")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "commits, reflogCommits",
				Command: "touch myfile",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Commits().
			Focus().
			Press("X")

		t.Views().Files().
			Focus().
			Lines(Contains("myfile"))

		t.Shell().DeleteFile("myfile")
		t.GlobalPress(keys.Files.RefreshFiles)

		t.Views().Branches().
			Focus().
			Press("X")

		t.Views().Files().
			Focus().
			IsEmpty()

		t.Views().ReflogCommits().
			Focus().
			Press("X")

		t.Views().Files().
			Focus().
			Lines(Contains("myfile"))

		t.Shell().DeleteFile("myfile")
	},
})
View Source
var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command with multiple prompts",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo "{{index .PromptResponses 1}}" > {{index .PromptResponses 0}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Type:  "input",
						Title: "Enter a file name",
					},
					{
						Type:  "menu",
						Title: "Choose file content",
						Options: []config.CustomCommandMenuOption{
							{
								Name:        "foo",
								Description: "Foo",
								Value:       "FOO",
							},
							{
								Name:        "bar",
								Description: "Bar",
								Value:       "BAR",
							},
							{
								Name:        "baz",
								Description: "Baz",
								Value:       "BAZ",
							},
						},
					},
					{
						Type:  "confirm",
						Title: "Are you sure?",
						Body:  "Are you REALLY sure you want to make this file? Up to you buddy.",
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a")

		t.ExpectPopup().Prompt().Title(Equals("Enter a file name")).Type("myfile").Confirm()

		t.ExpectPopup().Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm()

		t.ExpectPopup().Confirmation().
			Title(Equals("Are you sure?")).
			Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
			Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("myfile").IsSelected(),
			)

		t.Views().Main().Content(Contains("BAR"))
	},
})
View Source
var RunCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command that uses runCommand template function in a prompt step",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `git checkout {{.Form.Branch}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:          "Branch",
						Type:         "input",
						Title:        "Enter a branch name",
						InitialValue: "myprefix/{{ runCommand \"echo dynamic\" }}/",
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Enter a branch name")).
			InitialText(Contains("myprefix/dynamic/")).
			Confirm()
	},
})
View Source
var SelectedCommit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Use the {{ .SelectedCommit }} template variable in different contexts",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.CreateNCommits(3)
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "global",
				Command: "printf '%s' '{{ .SelectedCommit.Name }}' > file.txt",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Commits().Focus().
			NavigateToLine(Contains("commit 01"))
		t.Views().ReflogCommits().Focus().
			NavigateToLine(Contains("commit 02"))
		t.Views().Branches().Focus().
			Lines(Contains("master").IsSelected()).
			PressEnter()
		t.Views().SubCommits().IsFocused().
			NavigateToLine(Contains("commit 03"))

		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 03"))

		t.Views().SubCommits().PressEnter()
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 03"))

		t.Views().ReflogCommits().Focus()
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit: commit 02"))

		t.Views().ReflogCommits().PressEnter()
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit: commit 02"))

		t.Views().Commits().Focus()
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 01"))

		t.Views().Commits().PressEnter()
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 01"))

		t.Views().Files().Focus()
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 01"))
	},
})
View Source
var SelectedCommitRange = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Use the {{ .SelectedCommitRange }} template variable",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.CreateNCommits(3)
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "global",
				Command: `git log --format="%s" {{.SelectedCommitRange.From}}^..{{.SelectedCommitRange.To}} > file.txt`,
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().Focus().
			Lines(
				Contains("commit 03").IsSelected(),
				Contains("commit 02"),
				Contains("commit 01"),
			)

		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 03\n"))

		t.Views().Commits().Focus().
			Press(keys.Universal.RangeSelectDown)

		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("commit 03\ncommit 02\n"))
	},
})
View Source
var SelectedPath = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Use the {{ .SelectedPath }} template variable in different contexts",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("folder1")
		shell.CreateFileAndAdd("folder1/file1", "")
		shell.Commit("commit")
		shell.CreateDir("folder2")
		shell.CreateFile("folder2/file2", "")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "global",
				Command: "printf '%s' '{{ .SelectedPath }}' > file.txt",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			Focus().
			NavigateToLine(Contains("file2"))
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("folder2/file2"))

		t.Views().Commits().
			Focus().
			PressEnter()
		t.Views().CommitFiles().
			IsFocused().
			NavigateToLine(Contains("file1"))
		t.GlobalPress("X")
		t.FileSystem().FileContent("file.txt", Equals("folder1/file1"))
	},
})
View Source
var SelectedSubmodule = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Use the {{ .SelectedSubmodule }} template variable",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("Initial commit")
		shell.CloneIntoSubmodule("submodule", "path/submodule")
		shell.Commit("Add submodule")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "submodules",
				Command: "printf '%s' '{{ .SelectedSubmodule.Path }}' > file.txt",
			},
			{
				Key:     "U",
				Context: "submodules",
				Command: "printf '%s' '{{ .SelectedSubmodule.Url }}' > file.txt",
			},
			{
				Key:     "N",
				Context: "submodules",
				Command: "printf '%s' '{{ .SelectedSubmodule.Name }}' > file.txt",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Submodules().
			Focus().
			Lines(
				Contains("submodule").IsSelected(),
			)

		t.Views().Submodules().Press("X")
		t.FileSystem().FileContent("file.txt", Equals("path/submodule"))

		t.Views().Submodules().Press("U")
		t.FileSystem().FileContent("file.txt", Equals("../submodule"))

		t.Views().Submodules().Press("N")
		t.FileSystem().FileContent("file.txt", Equals("submodule"))
	},
})
View Source
var ShowOutputInPanel = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Run a command and show the output in a panel",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("my change")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "X",
				Context: "commits",
				Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
				Output:  "popup",
			},
			{
				Key:         "Y",
				Context:     "commits",
				Command:     "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
				Output:      "popup",
				OutputTitle: "Subject of commit {{ .SelectedLocalCommit.Hash }}",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("my change").IsSelected(),
			).
			Press("X")

		t.ExpectPopup().Alert().
			Title(Equals("printf '%s' 'my change'")).
			Content(Equals("my change")).
			Confirm()

		t.Views().Commits().
			Press("Y")

		hash := t.Git().GetCommitHash("HEAD")
		t.ExpectPopup().Alert().
			Title(Equals(fmt.Sprintf("Subject of commit %s", hash))).
			Content(Equals("my change"))
	},
})
View Source
var SuggestionsCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command that uses a suggestions command in a prompt step",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-one")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-two")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-three")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-four")
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `git checkout {{.Form.Branch}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Branch",
						Type:  "input",
						Title: "Enter a branch name",
						Suggestions: config.CustomCommandSuggestions{
							Command: "git branch --format='%(refname:short)'",
						},
					},
				},
			},
		}

		cfg.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical"
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("branch-four").IsSelected(),
				Contains("branch-one"),
				Contains("branch-three"),
				Contains("branch-two"),
			).
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Enter a branch name")).
			Type("three").
			SuggestionLines(Contains("branch-three")).
			ConfirmFirstSuggestion()

		t.Views().Branches().
			Lines(
				Contains("branch-three"),
				Contains("branch-four").IsSelected(),
				Contains("branch-one"),
				Contains("branch-two"),
			)
	},
})
View Source
var SuggestionsPreset = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command that uses a suggestions preset in a prompt step",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-one")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-two")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-three")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-four")
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `git checkout {{.Form.Branch}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Branch",
						Type:  "input",
						Title: "Enter a branch name",
						Suggestions: config.CustomCommandSuggestions{
							Preset: "branches",
						},
					},
				},
			},
		}

		cfg.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical"
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("branch-four").IsSelected(),
				Contains("branch-one"),
				Contains("branch-three"),
				Contains("branch-two"),
			).
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Enter a branch name")).
			Type("three").
			SuggestionLines(Contains("branch-three")).
			ConfirmFirstSuggestion()

		t.Views().Branches().
			Lines(
				Contains("branch-three"),
				Contains("branch-four").IsSelected(),
				Contains("branch-one"),
				Contains("branch-two"),
			)
	},
})

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