staging

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: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DiffChangeScreenMode = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Change the staged changes screen mode",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile("file", "first line\nsecond line")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			Focus().
			PressEnter()

		t.Views().Staging().
			IsFocused().
			PressPrimaryAction().
			Title(Equals("Unstaged changes")).
			Content(Contains("+second line").DoesNotContain("+first line")).
			PressTab()

		t.Views().StagingSecondary().
			IsFocused().
			Title(Equals("Staged changes")).
			Content(Contains("+first line").DoesNotContain("+second line")).
			Press(keys.Universal.NextScreenMode).
			Tap(func() {
				t.Views().AppStatus().
					IsInvisible()
				t.Views().Staging().
					IsVisible()
			}).
			Press(keys.Universal.NextScreenMode).
			Tap(func() {
				t.Views().AppStatus().
					IsInvisible()
				t.Views().Staging().
					IsInvisible()
			})
	},
})
View Source
var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Change the number of diff context lines while in the staging panel",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {

		shell.CreateFileAndAdd("file1", "1a\n2a\n3a\n4a\n5a\n6a\n7a\n8a\n9a\n10a\n11a\n12a\n13a\n14a\n15a")
		shell.Commit("one")

		shell.UpdateFile("file1", "1a\n2a\n3b\n4a\n5a\n6a\n7a\n8a\n9a\n10a\n11a\n12a\n13b\n14a\n15a")

	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.IncreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 4"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.DecreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 3"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.DecreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 2"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.DecreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 1"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			PressPrimaryAction().
			Press(keys.Universal.TogglePanel)

		t.Views().StagingSecondary().
			IsFocused().
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.DecreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 0"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.IncreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 1"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.IncreaseContextInDiffView).
			Tap(func() {
				t.ExpectToast(Equals("Changed diff context size to 2"))
			}).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			)
	},
})
View Source
var DiscardAllChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discard all changes of a file in the staging panel, then assert we land in the staging panel of the next file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "one\ntwo\n")
		shell.CreateFileAndAdd("file2", "1\n2\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "one\ntwo\nthree\nfour\n")
		shell.UpdateFile("file2", "1\n2\n3\n4\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Equals("▼ /").IsSelected(),
				Equals("   M file1"),
				Equals("   M file2"),
			).
			SelectNextItem().
			PressEnter()

		t.Views().Staging().
			IsFocused().
			Press(keys.Main.ToggleSelectHunk).
			SelectedLines(Contains("+three")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Common().ConfirmDiscardLines()
			}).
			SelectedLines(Contains("+four")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Common().ConfirmDiscardLines()

				t.Views().Files().
					Lines(
						Equals(" M file2"),
					)
			}).
			IsFocused().
			SelectedLines(Contains("+3"))
	},
})
View Source
var Search = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Use the search feature in the staging panel",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile("file1", "one\ntwo\nthree\nfour\nfive")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			Press(keys.Universal.StartSearch).
			Tap(func() {
				t.ExpectSearch().
					Type("four").
					Confirm()

				t.Views().Search().IsVisible().Content(Contains("matches for 'four' (1 of 1)"))
			}).
			SelectedLine(Contains("+four")).
			PressPrimaryAction().
			Content(DoesNotContain("+four")).
			Tap(func() {
				t.Views().StagingSecondary().
					Content(Contains("+four"))
			})
	},
})
View Source
var SelectNextLineAfterStagingInTwoHunkDiff = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "After staging lines from a two-hunk diff, the cursor advances correctly",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {

		shell.CreateFileAndAdd("file1", "1\n2\na\nb\nc\nd\ne\nf\ng\n3\n4\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "1b\n2b\na\nb\nc\nd\ne\nf\ng\n3b\n4b\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			ContainsLines(
				Contains("-1"),
				Contains("-2"),
				Contains("+1b"),
				Contains("+2b"),
				Contains(" a"),
				Contains(" b"),
				Contains(" c"),
				Contains("@@"),
				Contains(" e"),
				Contains(" f"),
				Contains(" g"),
				Contains("-3"),
				Contains("-4"),
				Contains("+3b"),
				Contains("+4b"),
			).
			NavigateToLine(Contains("-2")).
			PressPrimaryAction().
			SelectedLine(Contains("+1b")).
			PressPrimaryAction().
			SelectedLine(Contains("+2b")).
			PressPrimaryAction().
			SelectedLine(Contains("-3"))
	},
})

Tests that after staging individual lines from a consecutive changes block, the cursor advances to the correct next change. The file has two separate hunks so that we can verify the cursor crosses hunk boundaries correctly.

View Source
var SelectNextLineAfterStagingIsolatedAddedLine = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "After staging an isolated added line, the cursor advances to the next hunk's first change",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "1\n2\n3\n4\n5\n6\n7\n8\n9\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "1\n2\n3\nnew\n4\n5\n6\n7b\n8\n9\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			ContainsLines(
				Contains(" 1"),
				Contains(" 2"),
				Contains(" 3"),
				Contains("+new"),
				Contains(" 4"),
				Contains(" 5"),
				Contains(" 6"),
				Contains("-7"),
				Contains("+7b"),
				Contains(" 8"),
				Contains(" 9"),
			).
			SelectedLine(Contains("+new")).
			PressPrimaryAction().
			SelectedLine(Contains("-7"))
	},
})

Tests that after staging an isolated addition (one that is alone in its block of changes), the cursor stays at the first change of the next block of changes which moves up to the same line, even if that block starts with a deletion.

View Source
var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage and unstage various hunks of a file in the staging panel",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "1a\n2a\n3a\n4a\n5a\n6a\n7a\n8a")
		shell.Commit("one")

		shell.UpdateFile("file1", "1a\n2a\n3b\n4a\n5a\n6b\n7a\n8a")

	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains("-3a"),
			).
			Press(keys.Universal.NextBlock).
			SelectedLines(
				Contains("-6a"),
			).
			Press(keys.Main.ToggleSelectHunk).
			SelectedLines(
				Contains("-6a"),
				Contains("+6b"),
			).
			SelectPreviousItem().
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			SelectNextItem().
			SelectedLines(
				Contains("-6a"),
				Contains("+6b"),
			).
			PressPrimaryAction().
			ContainsLines(
				Contains("-3a"),
				Contains("+3b"),
			).
			Tap(func() {
				t.Views().StagingSecondary().
					ContainsLines(
						Contains("-6a"),
						Contains("+6b"),
					)
			}).
			Press(keys.Universal.TogglePanel)

		t.Views().StagingSecondary().
			IsFocused().
			SelectedLines(
				Contains("-6a"),
			).
			PressPrimaryAction().
			SelectedLines(
				Contains("+6b"),
			).
			PressPrimaryAction().
			IsEmpty()

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains("-3a"),
			).
			Press(keys.Main.ToggleSelectHunk).
			SelectedLines(
				Contains(`-3a`),
				Contains(`+3b`),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Common().ConfirmDiscardLines()
			}).
			Content(DoesNotContain("-3a").DoesNotContain("+3b")).
			SelectedLines(
				Contains("-6a"),
				Contains("+6b"),
			)
	},
})
View Source
var StageLines = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage and unstage various lines of a file in the staging panel",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "one\ntwo\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "one\ntwo\nthree\nfour\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			SelectedLines(Contains("+three")).
			PressPrimaryAction().
			Content(DoesNotContain("+three")).
			Tap(func() {
				t.Views().StagingSecondary().
					ContainsLines(
						Contains("+three"),
					)
			}).
			SelectedLines(Contains("+four")).
			PressPrimaryAction().
			IsEmpty()

		t.Views().StagingSecondary().
			IsFocused().
			ContainsLines(
				Contains("+three"),
				Contains("+four"),
			).
			SelectedLines(Contains("+three")).
			PressPrimaryAction().
			Content(DoesNotContain("+three")).
			Tap(func() {
				t.Views().Staging().
					ContainsLines(
						Contains("+three"),
					)
			}).
			SelectedLines(Contains("+four")).
			Press(keys.Universal.Remove).
			IsEmpty()

		t.Views().Staging().
			IsFocused().
			ContainsLines(
				Contains("+three"),
				Contains("+four"),
			).
			SelectedLines(Contains("+three")).
			PressPrimaryAction().
			Content(DoesNotContain("+three")).
			Tap(func() {
				t.Views().StagingSecondary().
					Content(Contains("+three"))
			}).
			Press(keys.Universal.TogglePanel)

		t.Views().StagingSecondary().
			IsFocused().
			Press(keys.Universal.TogglePanel)

		t.Views().Staging().
			SelectedLines(Contains("+four")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Discard change")).
					Content(Contains("Are you sure you want to discard this change")).
					Confirm()
			}).
			IsEmpty()

		t.Views().StagingSecondary().
			IsFocused().
			ContainsLines(
				Contains("+three"),
			).
			PressEscape()

		t.Views().Files().
			IsFocused().
			Lines(
				Contains("M  file1").IsSelected(),
			).
			PressEnter()

		t.Views().StagingSecondary().
			IsFocused()
	},
})
View Source
var StagePartialBlockOfChangesFirstLines = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage only the first few lines of a block of consecutive changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "1\n2\n3\n4\n5\n6\n7\n8\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "1\n2b\n3b\n4b\n5b\n6b\n7b\n8\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			ContainsLines(
				Contains(" 1"),
				Contains("-2"),
				Contains("-3"),
				Contains("-4"),
				Contains("-5"),
				Contains("-6"),
				Contains("-7"),
				Contains("+2b"),
				Contains("+3b"),
				Contains("+4b"),
				Contains("+5b"),
				Contains("+6b"),
				Contains("+7b"),
				Contains(" 8"),
			).
			SelectedLines(Contains("-2")).
			PressPrimaryAction().
			SelectedLines(Contains("-3")).
			PressPrimaryAction().
			NavigateToLine(Contains("+2b")).
			PressPrimaryAction().
			SelectedLines(Contains("+3b")).
			PressPrimaryAction()

		t.Views().StagingSecondary().
			ContainsLines(
				Contains(" 1"),
				Contains("-2"),
				Contains("-3"),
				Contains("+2b"),
				Contains("+3b"),
				Contains(" 4"),
				Contains(" 5"),
				Contains(" 6"),
			)
	},
})
View Source
var StagePartialBlockOfChangesLastLines = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage only the last few lines of a consecutive block of changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "1\n2\n3\n4\n5\n6\n7\n8\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "1\n2b\n3b\n4b\n5b\n6b\n7b\n8\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			ContainsLines(
				Contains(" 1"),
				Contains("-2"),
				Contains("-3"),
				Contains("-4"),
				Contains("-5"),
				Contains("-6"),
				Contains("-7"),
				Contains("+2b"),
				Contains("+3b"),
				Contains("+4b"),
				Contains("+5b"),
				Contains("+6b"),
				Contains("+7b"),
				Contains(" 8"),
			).
			NavigateToLine(Contains("-6")).
			PressPrimaryAction().
			SelectedLines(Contains("-7")).
			PressPrimaryAction().
			NavigateToLine(Contains("+6b")).
			PressPrimaryAction().
			SelectedLines(Contains("+7b")).
			PressPrimaryAction()

		t.Views().StagingSecondary().
			ContainsLines(
				Contains(" 3"),
				Contains(" 4"),
				Contains(" 5"),
				Contains("-6"),
				Contains("-7"),
				Contains("+6b"),
				Contains("+7b"),
				Contains(" 8"),
			)
	},
})
View Source
var StagePartialBlockOfChangesMiddleLines = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage only the middle lines of a consecutive block of changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "1\n2\n3\n4\n5\n6\n7\n8\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "1\n2b\n3b\n4b\n5b\n6b\n7b\n8\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			ContainsLines(
				Contains(" 1"),
				Contains("-2"),
				Contains("-3"),
				Contains("-4"),
				Contains("-5"),
				Contains("-6"),
				Contains("-7"),
				Contains("+2b"),
				Contains("+3b"),
				Contains("+4b"),
				Contains("+5b"),
				Contains("+6b"),
				Contains("+7b"),
				Contains(" 8"),
			).
			NavigateToLine(Contains("-4")).
			PressPrimaryAction().
			SelectedLines(Contains("-5")).
			PressPrimaryAction().
			NavigateToLine(Contains("+4b")).
			PressPrimaryAction().
			SelectedLines(Contains("+5b")).
			PressPrimaryAction()

		t.Views().StagingSecondary().
			ContainsLines(
				Contains(" 1"),
				Contains(" 2"),
				Contains(" 3"),
				Contains("-4"),
				Contains("-5"),
				Contains(" 6"),
				Contains(" 7"),
				Contains("+4b"),
				Contains("+5b"),
				Contains(" 8"),
			)
	},
})
View Source
var StageRanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage and unstage various ranges of a file in the staging panel",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().Gui.UseHunkModeInStagingView = false
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "one\ntwo\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "one\ntwo\nthree\nfour\nfive\nsix\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains("+three"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("+five")).
			SelectedLines(
				Contains("+three"),
				Contains("+four"),
				Contains("+five"),
			).
			PressPrimaryAction().
			SelectedLines(
				Contains("+six"),
			).
			ContainsLines(
				Contains(" five"),
				Contains("+six"),
			).
			Tap(func() {
				t.Views().StagingSecondary().
					ContainsLines(
						Contains("+three"),
						Contains("+four"),
						Contains("+five"),
					)
			}).
			Press(keys.Universal.TogglePanel)

		t.Views().StagingSecondary().
			IsFocused().
			SelectedLines(
				Contains("+three"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("+five")).
			SelectedLines(
				Contains("+three"),
				Contains("+four"),
				Contains("+five"),
			).
			PressPrimaryAction().
			IsEmpty().
			Tap(func() {
				t.Views().Staging().
					ContainsLines(
						Contains("+three"),
						Contains("+four"),
						Contains("+five"),
						Contains("+six"),
					)
			})

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains("+four"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			SelectNextItem().
			SelectedLines(
				Contains("+four"),
				Contains("+five"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Common().ConfirmDiscardLines()
			}).
			ContainsLines(
				Contains("+three"),
				Contains("+six"),
			)
	},
})

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