stash

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 2 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 Apply = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Apply a stash entry",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.NewBranch("stash")
		shell.Checkout("master")
		shell.CreateFile("file", "content")
		shell.GitAddAll()
		shell.Stash("stash one")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash one").IsSelected(),
			).
			PressPrimaryAction().
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Stash apply")).
					Content(Contains("Are you sure you want to apply this stash entry?")).
					Confirm()
			}).
			Lines(
				Contains("stash one").IsSelected(),
			)

		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file"),
			)
	},
})
View Source
var ApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Restore part of a stash entry via applying a custom patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFile("myfile", "content")
		shell.CreateFile("myfile2", "content")
		shell.GitAddAll()
		shell.Stash("stash one")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash one").IsSelected(),
			).
			PressEnter().
			Tap(func() {
				t.Views().CommitFiles().
					IsFocused().
					Lines(
						Equals("▼ /").IsSelected(),
						Contains("myfile"),
						Contains("myfile2"),
					).
					SelectNextItem().
					PressPrimaryAction()

				t.Views().Information().Content(Contains("Building patch"))

				t.Views().
					CommitFiles().
					Press(keys.Universal.CreatePatchOptionsMenu)

				t.ExpectPopup().Menu().
					Title(Equals("Patch options")).
					Select(MatchesRegexp(`Apply patch$`)).Confirm()
			})

		t.Views().Files().Lines(
			Contains("myfile"),
		)
	},
})
View Source
var CreateBranch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Create a branch from a stash entry",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.NewBranch("stash")
		shell.Checkout("master")
		shell.CreateFile("myfile", "content")
		shell.GitAddAll()
		shell.Stash("stash one")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash one").IsSelected(),
			).
			Press(keys.Universal.New).
			Tap(func() {
				t.ExpectPopup().Prompt().
					Title(Contains("New branch name (branch is off of 'stash@{0}: On master: stash one'")).
					Type("new_branch").
					Confirm()
			})

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

		t.Views().Branches().
			IsFocused().
			Lines(
				Contains("new_branch").IsSelected(),
				Contains("master"),
				Contains("stash"),
			).
			PressEnter()

		t.Views().SubCommits().
			Lines(
				Contains("On master: stash one").IsSelected(),
				MatchesRegexp(`index on master:.*initial commit`),
				Contains("initial commit"),
			)

		t.Views().Main().Content(Contains("myfile | 1 +"))
	},
})
View Source
var Drop = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Drop a stash entry",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.NewBranch("stash")
		shell.Checkout("master")
		shell.CreateFile("file", "content")
		shell.GitAddAll()
		shell.Stash("stash one")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash one").IsSelected(),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Stash drop")).
					Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")).
					Confirm()
			}).
			IsEmpty()

		t.Views().Files().IsEmpty()
	},
})
View Source
var DropMultiple = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Drop multiple stash entries",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFileAndAdd("file1", "content1")
		shell.Stash("stash one")
		shell.CreateFileAndAdd("file2", "content2")
		shell.Stash("stash two")
		shell.CreateFileAndAdd("file3", "content3")
		shell.Stash("stash three")
		shell.CreateFileAndAdd("file4", "content4")
		shell.Stash("stash four")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			SelectNextItem().
			Lines(
				Contains("stash four"),
				Contains("stash three").IsSelected(),
				Contains("stash two"),
				Contains("stash one"),
			).
			Press(keys.Universal.RangeSelectDown).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Stash drop")).
					Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")).
					Confirm()
			}).
			Lines(
				Contains("stash four"),
				Contains("stash one"),
			)

		t.Views().Files().IsEmpty()
	},
})
View Source
var DropMultipleInFilteredMode = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Drop multiple stash entries when filtering by path",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFileAndAdd("file1", "content1")
		shell.Stash("stash one")
		shell.CreateFileAndAdd("file2", "content2a")
		shell.Stash("stash two-a")
		shell.CreateFileAndAdd("file3", "content3")
		shell.Stash("stash three")
		shell.CreateFileAndAdd("file2", "content2b")
		shell.Stash("stash two-b")
		shell.CreateFileAndAdd("file4", "content4")
		shell.Stash("stash four")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			Lines(
				Contains("stash four"),
				Contains("stash two-b"),
				Contains("stash three"),
				Contains("stash two-a"),
				Contains("stash one"),
			)

		t.GlobalPress(keys.Universal.FilteringMenu)
		t.ExpectPopup().Menu().
			Title(Equals("Filtering")).
			Select(Contains("Enter path to filter by")).
			Confirm()

		t.ExpectPopup().Prompt().
			Title(Equals("Enter path:")).
			Type("file2").
			Confirm()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash two-b").IsSelected(),
				Contains("stash two-a"),
			).
			Press(keys.Universal.RangeSelectDown).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Stash drop")).
					Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")).
					Confirm()
			}).
			IsEmpty()

		t.GlobalPress(keys.Universal.Return)
		t.Views().Stash().
			Lines(
				Contains("stash four"),
				Contains("stash three"),
				Contains("stash one"),
			)
	},
})
View Source
var FilterByPath = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Filter the stash list by path",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFileAndAdd("file1", "content")
		shell.Stash("file1")
		shell.CreateDir("subdir")
		shell.CreateFileAndAdd("subdir/file2", "content")
		shell.Stash("subdir/file2")
		shell.CreateFileAndAdd("file1", "other content")
		shell.Stash("file1 again")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		filterBy := func(path string) {
			t.GlobalPress(keys.Universal.FilteringMenu)
			t.ExpectPopup().Menu().
				Title(Equals("Filtering")).
				Select(Contains("Enter path to filter by")).
				Confirm()

			t.ExpectPopup().Prompt().
				Title(Equals("Enter path:")).
				Type(path).
				Confirm()
		}

		t.Views().Stash().
			Lines(
				Contains("file1 again"),
				Contains("subdir/file2"),
				Contains("file1"),
			)

		filterBy("file1")

		t.Views().Stash().
			Lines(
				Contains("file1 again"),
				Contains("file1"),
			)

		t.GlobalPress(keys.Universal.Return)
		filterBy("subdir")

		t.Views().Stash().
			Lines(
				Contains("subdir/file2"),
			)
	},
})
View Source
var Pop = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Pop a stash entry",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.NewBranch("stash")
		shell.Checkout("master")
		shell.CreateFile("file", "content")
		shell.GitAddAll()
		shell.Stash("stash one")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash one").IsSelected(),
			).
			Press(keys.Stash.PopStash).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Stash pop")).
					Content(Contains("Are you sure you want to pop this stash entry?")).
					Confirm()
			}).
			IsEmpty()

		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file"),
			)
	},
})
View Source
var PreventDiscardingFileChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Check that it is not allowed to discard changes to a file of a stash",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFile("file", "content")
		shell.GitAddAll()
		shell.Stash("stash one")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().IsEmpty()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("stash one").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file").IsSelected(),
			).
			Press(keys.Universal.Remove)

		t.ExpectPopup().Confirmation().
			Title(Equals("Error")).
			Content(Contains("Changes can only be discarded from local commits")).
			Confirm()
	},
})
View Source
var Rename = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Try to rename the stash.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("blah").
			NewBranch("stash").
			Checkout("master").
			CreateFileAndAdd("file-1", "change to stash1").
			Stash("foo").
			CreateFileAndAdd("file-2", "change to stash2").
			Stash("bar")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			Focus().
			Lines(
				Contains("On master: bar"),
				Contains("On master: foo"),
			).
			SelectNextItem().
			Press(keys.Stash.RenameStash).
			Tap(func() {
				t.ExpectPopup().Prompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm()
			}).
			SelectedLine(Contains("On master: foo baz"))

		t.Views().Main().Content(Contains("file-1"))
	},
})
View Source
var ShowWithBranchNamedStash = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "View stash when there is a branch also named 'stash'",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFile("file", "content")
		shell.GitAddAll()

		shell.NewBranch("stash")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Contains("file"),
			).
			Press(keys.Files.StashAllChanges)

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				MatchesRegexp(`\ds .* my stashed file`),
			)

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

		t.Views().Stash().Focus()
		t.Views().Main().ContainsLines(Equals(" file | 1 +"))
	},
})
View Source
var Stash = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stashing files directly (not going through the stash menu)",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.NewBranch("stash")
		shell.Checkout("master")
		shell.CreateFile("file", "content")
		shell.GitAddAll()
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Contains("file"),
			).
			Press(keys.Files.StashAllChanges)

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				MatchesRegexp(`\ds .* my stashed file`),
			)

		t.Views().Files().
			IsEmpty()
	},
})
View Source
var StashAll = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stashing all changes (via the menu)",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFile("file", "content")
		shell.GitAddAll()
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Contains("file"),
			).
			Press(keys.Files.ViewStashOptions)

		t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("Stash all changes$")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				Contains("my stashed file"),
			)

		t.Views().Files().
			IsEmpty()
	},
})
View Source
var StashAndKeepIndex = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stash staged changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file-staged", "content")
		shell.CreateFileAndAdd("file-unstaged", "content")
		shell.EmptyCommit("initial commit")
		shell.UpdateFileAndAdd("file-staged", "new content")
		shell.UpdateFile("file-unstaged", "new content")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Equals("▼ /"),
				Equals("  M  file-staged"),
				Equals("   M file-unstaged"),
			).
			Press(keys.Files.ViewStashOptions)

		t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(Contains("Stash all changes and keep index")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				Contains("my stashed file"),
			)

		t.Views().Files().
			Lines(
				Equals("M  file-staged"),
			)

		t.Views().Stash().
			Focus().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Equals("▼ /"),
				Equals("  M file-staged"),
				Equals("  M file-unstaged"),
			)
	},
})
View Source
var StashIncludingUntrackedFiles = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stashing all files including untracked ones",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("initial commit")
		shell.CreateFile("file_1", "content")
		shell.CreateFile("file_2", "content")
		shell.GitAdd("file_1")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Equals("▼ /"),
				Equals("  A  file_1"),
				Equals("  ?? file_2"),
			).
			Press(keys.Files.ViewStashOptions)

		t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(Contains("Stash all changes including untracked files")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				Contains("my stashed file"),
			)

		t.Views().Files().
			IsEmpty()
	},
})
View Source
var StashStaged = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stash staged changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file-staged", "content")
		shell.CreateFileAndAdd("file-unstaged", "content")
		shell.EmptyCommit("initial commit")
		shell.UpdateFileAndAdd("file-staged", "new content")
		shell.UpdateFile("file-unstaged", "new content")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Equals("▼ /"),
				Equals("  M  file-staged"),
				Equals("   M file-unstaged"),
			).
			Press(keys.Files.ViewStashOptions)

		t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("Stash staged changes$")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				Contains("my stashed file"),
			)

		t.Views().Files().
			Lines(
				Equals(" M file-unstaged"),
			)

		t.Views().Stash().
			Focus().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file-staged").IsSelected(),
			)
	},
})
View Source
var StashStagedPartialFile = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stash staged changes when a file is partially staged",
	ExtraCmdArgs: []string{},
	GitVersion:   AtLeast("git version 2.35.0"),
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file-staged", "line1\nline2\nline3\nline4\n")
		shell.Commit("initial commit")
		shell.UpdateFile("file-staged", "line1\nline2 mod\nline3\nline4 mod\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			PressEnter()

		t.Views().Staging().
			Content(
				Contains(" line1\n-line2\n+line2 mod\n line3\n-line4\n+line4 mod"),
			).
			PressPrimaryAction().
			Content(
				Contains(" line1\n line2 mod\n line3\n-line4\n+line4 mod"),
			).
			PressEscape()

		t.Views().Files().
			IsFocused().
			Press(keys.Files.ViewStashOptions)

		t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("Stash staged changes$")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Focus().
			Lines(
				Contains("my stashed file"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file-staged").IsSelected(),
			)
		t.Views().Main().
			Content(
				Contains(" line1\n-line2\n+line2 mod\n line3\n line4"),
			)

		t.Views().Files().
			Focus().
			Lines(
				Contains("file-staged"),
			)

		t.Views().Main().
			Content(
				Contains(" line1\n line2\n line3\n-line4\n+line4 mod"),
			)
	},
})
View Source
var StashUnstaged = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stash unstaged changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file-staged", "content")
		shell.CreateFileAndAdd("file-unstaged", "content")
		shell.EmptyCommit("initial commit")
		shell.UpdateFileAndAdd("file-staged", "new content")
		shell.UpdateFile("file-unstaged", "new content")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Stash().
			IsEmpty()

		t.Views().Files().
			Lines(
				Equals("▼ /"),
				Equals("  M  file-staged"),
				Equals("   M file-unstaged"),
			).
			Press(keys.Files.ViewStashOptions)

		t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("Stash unstaged changes$")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

		t.Views().Stash().
			Lines(
				Contains("my stashed file"),
			)

		t.Views().Files().
			Lines(
				Contains("file-staged"),
			)

		t.Views().Stash().
			Focus().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file-unstaged").IsSelected(),
			)
	},
})

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