patch_building

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Apply = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Apply a custom patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-a")
		shell.CreateFileAndAdd("file1", "first line\n")
		shell.Commit("first commit")

		shell.NewBranch("branch-b")
		shell.UpdateFileAndAdd("file1", "first line\nsecond line\n")
		shell.Commit("update")

		shell.Checkout("branch-a")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("branch-a").IsSelected(),
				Contains("branch-b"),
			).
			Press(keys.Universal.NextItem).
			PressEnter()

		t.Views().SubCommits().
			IsFocused().
			Lines(
				Contains("update").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("M file1").IsSelected(),
			).
			PressPrimaryAction()

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

		t.Views().PatchBuildingSecondary().Content(Contains("second line"))

		t.Common().SelectPatchOption(MatchesRegexp(`Apply patch$`))

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

		t.Views().Main().
			Content(Contains("second line"))
	},
})
View Source
var ApplyInReverse = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Apply a custom patch in reverse",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content\n")
		shell.CreateFileAndAdd("file2", "file2 content\n")
		shell.Commit("first commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
				Contains("file2"),
			).
			PressPrimaryAction()

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

		t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))

		t.Common().SelectPatchOption(Contains("Apply patch in reverse"))

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

		t.Views().Main().
			Content(Contains("-file1 content"))
	},
})
View Source
var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Apply a custom patch in reverse, resulting in a conflict",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content\n")
		shell.CreateFileAndAdd("file2", "file2 content\n")
		shell.Commit("first commit")
		shell.UpdateFileAndAdd("file1", "file1 content\nmore file1 content\n")
		shell.UpdateFileAndAdd("file2", "file2 content\nmore file2 content\n")
		shell.Commit("second commit")
		shell.UpdateFileAndAdd("file1", "file1 content\nmore file1 content\neven more file1\n")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("second commit"),
				Contains("first commit"),
			).
			NavigateToLine(Contains("second commit")).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("M").Contains("file1").IsSelected(),
				Contains("M").Contains("file2"),
			).
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().PatchBuildingSecondary().Content(
					Contains("+more file1 content"))
			}).
			SelectNextItem().
			PressPrimaryAction()

		t.Views().PatchBuildingSecondary().Content(
			Contains("+more file1 content").Contains("+more file2 content"))

		t.Common().SelectPatchOption(Contains("Apply patch in reverse"))

		t.ExpectPopup().Alert().
			Title(Equals("Error")).
			Content(Contains("Applied patch to 'file1' with conflicts.")).
			Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("UU").Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().MergeConflicts().
			IsFocused().
			ContainsLines(
				Contains("file1 content"),
				Contains("<<<<<<< ours").IsSelected(),
				Contains("more file1 content").IsSelected(),
				Contains("even more file1").IsSelected(),
				Contains("=======").IsSelected(),
				Contains(">>>>>>> theirs"),
			).
			SelectNextItem().
			PressPrimaryAction()

		t.Views().Files().
			Focus().
			Lines(
				Contains("M").Contains("file1").IsSelected(),
				Contains("M").Contains("file2"),
			)

		t.Views().Main().
			ContainsLines(
				Contains(" file1 content"),
				Contains("-more file1 content"),
				Contains("-even more file1"),
			)
	},
})
View Source
var MoveRangeToIndex = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Apply a custom patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "first line\n")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file1", "first line\nsecond line\n")
		shell.CreateFileAndAdd("file2", "file two content\n")
		shell.CreateFileAndAdd("file3", "file three content\n")
		shell.Commit("second commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("second commit").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("M file1").IsSelected(),
				Contains("A file2"),
				Contains("A file3"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file2")).
			PressPrimaryAction()

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

		t.Views().PatchBuildingSecondary().Content(Contains("second line"))
		t.Views().PatchBuildingSecondary().Content(Contains("file two content"))

		t.Common().SelectPatchOption(MatchesRegexp(`Move patch out into index$`))

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file3").IsSelected(),
			).PressEscape()

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

		t.Views().Main().
			Content(Contains("second line"))

		t.Views().Files().Focus().NavigateToLine(Contains("file2"))

		t.Views().Main().
			Content(Contains("file two content"))
	},
})
View Source
var MoveToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to an earlier commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	GitVersion:   AtLeast("2.26.0"),
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFileAndAdd("dir/file1", "file1 content")
		shell.CreateFileAndAdd("dir/file2", "file2 content")
		shell.Commit("first commit")

		shell.CreateFileAndAdd("unrelated-file", "")
		shell.Commit("destination commit")

		shell.UpdateFileAndAdd("dir/file1", "file1 content with old changes")
		shell.DeleteFileAndAdd("dir/file2")
		shell.CreateFileAndAdd("dir/file3", "file3 content")
		shell.Commit("commit to move from")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("commit to move from").IsSelected(),
				Contains("destination commit"),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
			).
			PressPrimaryAction().
			PressEscape()

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

		t.Views().Commits().
			IsFocused().
			SelectNextItem()

		t.Common().SelectPatchOption(Contains("Move patch to selected commit"))

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("commit to move from"),
				Contains("destination commit").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
				Contains("A unrelated-file"),
			).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			SelectPreviousItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("(none)"),
			)
	},
})
View Source
var MoveToEarlierCommitNoKeepEmpty = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to an earlier commit, for older git versions that don't keep the empty commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	GitVersion:   Before("2.26.0"),
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFileAndAdd("dir/file1", "file1 content")
		shell.CreateFileAndAdd("dir/file2", "file2 content")
		shell.Commit("first commit")

		shell.CreateFileAndAdd("unrelated-file", "")
		shell.Commit("destination commit")

		shell.UpdateFileAndAdd("dir/file1", "file1 content with old changes")
		shell.DeleteFileAndAdd("dir/file2")
		shell.CreateFileAndAdd("dir/file3", "file3 content")
		shell.Commit("commit to move from")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("commit to move from").IsSelected(),
				Contains("destination commit"),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
			).
			PressPrimaryAction().
			PressEscape()

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

		t.Views().Commits().
			IsFocused().
			SelectNextItem()

		t.Common().SelectPatchOption(Contains("Move patch to selected commit"))

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("destination commit"),
				Contains("first commit").IsSelected(),
			).
			SelectPreviousItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
				Contains("A unrelated-file"),
			).
			PressEscape()
	},
})
View Source
var MoveToIndex = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to the index",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content\n")
		shell.CreateFileAndAdd("file2", "file2 content\n")
		shell.Commit("first commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
				Contains("file2"),
			).
			PressPrimaryAction()

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

		t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))

		t.Common().SelectPatchOption(Contains("Move patch out into index"))

		t.Views().Files().
			Lines(
				Contains("A").Contains("file1"),
			)

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file2").IsSelected(),
			).
			PressEscape()

		t.Views().Main().
			Content(Contains("+file2 content"))

		t.Views().Commits().
			Lines(
				Contains("first commit").IsSelected(),
			)

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

		t.Views().Main().
			Content(Contains("file1 content"))
	},
})
View Source
var MoveToIndexPartOfAdjacentAddedLines = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to the index, with only some lines of a range of adjacent added lines in the patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file1", "1st line\n2nd line\n")
		shell.Commit("commit to move from")

		shell.UpdateFileAndAdd("unrelated-file", "")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

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

		t.Views().PatchBuilding().
			IsFocused().
			PressEnter().
			PressPrimaryAction()

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

		t.Common().SelectPatchOption(Contains("Move patch out into index"))

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			Tap(func() {
				t.Views().Main().
					Content(Contains("+2nd line").
						DoesNotContain("1st line"))
			})

		t.Views().Files().
			Focus().
			ContainsLines(
				Contains("M").Contains("file1"),
			)

		t.Views().Main().
			Content(Contains("+1st line\n 2nd line\n"))
	},
})
View Source
var MoveToIndexPartial = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to the index. This is different from the MoveToIndex test in that we're only selecting a partial patch from a file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "first line\nsecond line\nthird line\n")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file1", "first line2\nsecond line\nthird line2\n")
		shell.Commit("second commit")

		shell.CreateFileAndAdd("file2", "file1 content")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("second commit"),
				Contains("first commit"),
			).
			NavigateToLine(Contains("second commit")).
			PressEnter()

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

		t.Views().PatchBuilding().
			IsFocused().
			ContainsLines(
				Contains(`-first line`).IsSelected(),
				Contains(`+first line2`),
				Contains(` second line`),
				Contains(`-third line`),
				Contains(`+third line2`),
			).
			PressPrimaryAction().
			SelectNextItem().
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().PatchBuildingSecondary().
					ContainsLines(
						Contains(`-first line`),
						Contains(`+first line2`),
						Contains(` second line`),
						Contains(` third line`),
					)

				t.Common().SelectPatchOption(Contains("Move patch out into index"))

				t.Views().Files().
					Lines(
						Contains("M").Contains("file1"),
					)
			})

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1"),
			)

		t.Views().Main().
			ContainsLines(
				Contains(` first line`),
				Contains(` second line`),
				Contains(`-third line`),
				Contains(`+third line2`),
			)

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

		t.Views().Main().
			ContainsLines(
				Contains(`-first line`),
				Contains(`+first line2`),
				Contains(` second line`),
				Contains(` third line2`),
			)
	},
})
View Source
var MoveToIndexWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to the index, causing a conflict",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file1", "file1 content with old changes")
		shell.Commit("second commit")

		shell.UpdateFileAndAdd("file1", "file1 content with new changes")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("second commit"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressPrimaryAction()

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

		t.Common().SelectPatchOption(Contains("Move patch out into index"))

		t.Common().AcknowledgeConflicts()

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

		t.Views().MergeConflicts().
			IsFocused().
			ContainsLines(
				Contains("<<<<<<< HEAD").IsSelected(),
				Contains("file1 content").IsSelected(),
				Contains("=======").IsSelected(),
				Contains("file1 content with new changes"),
				Contains(">>>>>>>"),
			).
			PressPrimaryAction()

		t.Common().ContinueOnConflictsResolved()

		t.ExpectPopup().Alert().
			Title(Equals("Error")).
			Content(Contains("Applied patch to 'file1' with conflicts")).
			Confirm()

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

		t.Views().MergeConflicts().
			TopLines(
				Contains("<<<<<<< ours"),
				Contains("file1 content"),
				Contains("======="),
				Contains("file1 content with old changes"),
				Contains(">>>>>>> theirs"),
			).
			IsFocused()
	},
})
View Source
var MoveToIndexWorksEvenIfNoprefixIsSet = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Moving a patch to the index works even if diff.noprefix or diff.external are set",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content\n")
		shell.Commit("first commit")

		shell.SetConfig("diff.noprefix", "true")
		shell.SetConfig("diff.external", "echo")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressPrimaryAction()

		t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))

		t.Common().SelectPatchOption(Contains("Move patch out into index"))

		t.Views().CommitFiles().IsFocused().
			Lines(
				Equals("(none)"),
			)

		t.Views().Files().
			Lines(
				Contains("A").Contains("file1"),
			)
	},
})
View Source
var MoveToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to a later commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFileAndAdd("dir/file1", "file1 content")
		shell.CreateFileAndAdd("dir/file2", "file2 content")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("dir/file1", "file1 content with old changes")
		shell.DeleteFileAndAdd("dir/file2")
		shell.CreateFileAndAdd("dir/file3", "file3 content")
		shell.Commit("commit to move from")

		shell.CreateFileAndAdd("unrelated-file", "")
		shell.Commit("destination commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("destination commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
			).
			PressPrimaryAction().
			PressEscape()

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

		t.Views().Commits().
			IsFocused().
			SelectPreviousItem()

		t.Common().SelectPatchOption(Contains("Move patch to selected commit"))

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("destination commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
				Contains("A unrelated-file"),
			).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("(none)"),
			)
	},
})
View Source
var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to a later commit, with only parts of a hunk in the patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file1", "1st line\n2nd line\n")
		shell.Commit("commit to move from")

		shell.UpdateFileAndAdd("unrelated-file", "")
		shell.Commit("destination commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("destination commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

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

		t.Views().PatchBuilding().
			IsFocused().
			PressEnter().
			PressPrimaryAction().
			PressEscape()

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

		t.Views().CommitFiles().
			IsFocused().
			PressEscape()

		t.Views().Commits().
			IsFocused().
			SelectPreviousItem()

		t.Common().SelectPatchOption(Contains("Move patch to selected commit"))

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("destination commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
				Contains("unrelated-file"),
			).
			Tap(func() {
				t.Views().Main().
					Content(Contains("+1st line\n 2nd line"))
			}).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			Tap(func() {
				t.Views().Main().
					Content(Contains("+2nd line").
						DoesNotContain("1st line"))
			})
	},
})
View Source
var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to a new commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFileAndAdd("dir/file1", "file1 content")
		shell.CreateFileAndAdd("dir/file2", "file2 content")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("dir/file1", "file1 content with old changes")
		shell.DeleteFileAndAdd("dir/file2")
		shell.CreateFileAndAdd("dir/file3", "file3 content")
		shell.Commit("commit to move from")

		shell.UpdateFileAndAdd("dir/file1", "file1 content with new changes")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
			).
			PressPrimaryAction().
			PressEscape()

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

		t.Common().SelectPatchOption(Contains("Move patch into new commit"))

		t.ExpectPopup().CommitMessagePanel().
			InitialText(Equals("")).
			Type("new commit").Confirm()

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("third commit"),
				Contains("new commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("  M file1"),
				Contains("  D file2"),
				Contains("  A file3"),
			).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("third commit"),
				Contains("new commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("(none)"),
			)
	},
})
View Source
var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Move a patch from a commit to a new commit, with only parts of a hunk in the patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file1", "1st line\n2nd line\n")
		shell.Commit("commit to move from")

		shell.UpdateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

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

		t.Views().PatchBuilding().
			IsFocused().
			PressEnter().
			PressPrimaryAction()

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

		t.Common().SelectPatchOption(Contains("Move patch into new commit"))

		t.ExpectPopup().CommitMessagePanel().
			InitialText(Equals("")).
			Type("new commit").Confirm()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			Tap(func() {
				t.Views().Main().
					Content(Contains("+1st line\n 2nd line"))
			}).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("third commit"),
				Contains("new commit").IsSelected(),
				Contains("commit to move from"),
				Contains("first commit"),
			).
			SelectNextItem().
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			Tap(func() {
				t.Views().Main().
					Content(Contains("+2nd line").
						DoesNotContain("1st line"))
			})
	},
})
View Source
var RemoveFromCommit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Remove a custom patch from a commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content\n")
		shell.CreateFileAndAdd("file2", "file2 content\n")
		shell.Commit("first commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
				Contains("file2"),
			).
			PressPrimaryAction()

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

		t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))

		t.Common().SelectPatchOption(Contains("Remove patch from original commit"))

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

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file2").IsSelected(),
			).
			PressEscape()

		t.Views().Main().
			Content(Contains("+file2 content"))

		t.Views().Commits().
			Lines(
				Contains("first commit").IsSelected(),
			)
	},
})
View Source
var ResetWithEscape = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Reset a custom patch with the escape keybinding",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content")
		shell.Commit("first commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))
			}).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			PressEscape()

		t.Views().Information().Content(DoesNotContain("Building patch"))
	},
})
View Source
var SelectAllFiles = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add all files of a commit to a custom patch with the 'a' keybinding",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content")
		shell.CreateFileAndAdd("file2", "file2 content")
		shell.CreateFileAndAdd("file3", "file3 content")
		shell.Commit("first commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
				Contains("file2"),
				Contains("file3"),
			).
			Press(keys.Files.ToggleStagedAll)

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

		t.Views().Secondary().Content(
			Contains("file1").Contains("file3").Contains("file3"),
		)
	},
})
View Source
var SpecificSelection = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Build a custom patch with a specific selection of lines, adding individual lines, as well as a range and hunk, and adding a file directly",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("hunk-file", "1a\n1b\n1c\n1d\n1e\n1f\n1g\n1h\n1i\n1j\n1k\n1l\n1m\n1n\n1o\n1p\n1q\n1r\n1s\n1t\n1u\n1v\n1w\n1x\n1y\n1z\n")
		shell.Commit("first commit")

		shell.UpdateFileAndAdd("hunk-file", "aa\n1b\ncc\n1d\n1e\n1f\n1g\n1h\n1i\n1j\n1k\n1l\n1m\n1n\n1o\n1p\n1q\n1r\n1s\ntt\nuu\nvv\n1w\n1x\n1y\n1z\n")

		shell.CreateFileAndAdd("line-file", "2a\n2b\n2c\n2d\n2e\n2f\n2g\n2h\n2i\n2j\n2k\n2l\n2m\n2n\n2o\n2p\n2q\n2r\n2s\n2t\n2u\n2v\n2w\n2x\n2y\n2z\n")
		shell.CreateFileAndAdd("direct-file", "direct file content")
		shell.Commit("second commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("second commit").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("direct-file").IsSelected(),
				Contains("hunk-file"),
				Contains("line-file"),
			).
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().Secondary().Content(Contains("direct file content"))
			}).
			NavigateToLine(Contains("hunk-file")).
			PressEnter()

		t.Views().PatchBuilding().
			IsFocused().
			SelectedLines(
				Contains("-1a"),
			).
			Press(keys.Main.ToggleSelectHunk).
			SelectedLines(
				Contains(`@@ -1,6 +1,6 @@`),
				Contains(`-1a`),
				Contains(`+aa`),
				Contains(` 1b`),
				Contains(`-1c`),
				Contains(`+cc`),
				Contains(` 1d`),
				Contains(` 1e`),
				Contains(` 1f`),
			).
			PressPrimaryAction().
			SelectedLines(
				Contains(`@@ -1,6 +1,6 @@`),
				Contains(`-1a`),
				Contains(`+aa`),
				Contains(` 1b`),
				Contains(`-1c`),
				Contains(`+cc`),
				Contains(` 1d`),
				Contains(` 1e`),
				Contains(` 1f`),
			).
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().Secondary().Content(

					DoesNotContain("direct file content").
						Contains("@@ -1,6 +1,6 @@").
						Contains(" 1f"),
				)
			}).
			PressEscape().
			PressEscape()

		t.Views().CommitFiles().
			IsFocused().
			NavigateToLine(Contains("line-file")).
			PressEnter()

		t.Views().PatchBuilding().
			IsFocused().
			SelectedLines(
				Contains("+2a"),
			).
			PressPrimaryAction().
			NavigateToLine(Contains("+2c")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("+2e")).
			PressPrimaryAction().
			NavigateToLine(Contains("+2g")).
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().Secondary().ContainsLines(
					Contains("+2a"),
					Contains("+2c"),
					Contains("+2d"),
					Contains("+2e"),
					Contains("+2g"),
				)
			}).
			PressEscape().
			Tap(func() {
				t.Views().Secondary().ContainsLines(

					Contains(`diff --git a/direct-file b/direct-file`),
					Contains(`new file mode 100644`),
					Contains(`index`),
					Contains(`--- /dev/null`),
					Contains(`+++ b/direct-file`),
					Contains(`@@ -0,0 +1 @@`),
					Contains(`+direct file content`),
					Contains(`\ No newline at end of file`),

					Contains(`diff --git a/hunk-file b/hunk-file`),
					Contains(`index`),
					Contains(`--- a/hunk-file`),
					Contains(`+++ b/hunk-file`),
					Contains(`@@ -1,6 +1,6 @@`),
					Contains(`-1a`),
					Contains(`+aa`),
					Contains(` 1b`),
					Contains(`-1c`),
					Contains(`+cc`),
					Contains(` 1d`),
					Contains(` 1e`),
					Contains(` 1f`),

					Contains(`diff --git a/line-file b/line-file`),
					Contains(`new file mode 100644`),
					Contains(`index`),
					Contains(`--- /dev/null`),
					Contains(`+++ b/line-file`),
					Contains(`@@ -0,0 +1,5 @@`),
					Contains(`+2a`),
					Contains(`+2c`),
					Contains(`+2d`),
					Contains(`+2e`),
					Contains(`+2g`),
				)
			})
	},
})
View Source
var StartNewPatch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Attempt to add a file from another commit to a patch, then agree to start a new patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content")
		shell.Commit("first commit")

		shell.CreateFileAndAdd("file2", "file2 content")
		shell.Commit("second commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("second commit").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file2").IsSelected(),
			).
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().Secondary().Content(Contains("file2"))
			}).
			PressEscape()

		t.Views().Commits().
			IsFocused().
			NavigateToLine(Contains("first commit")).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressPrimaryAction().
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Contains("Discard patch")).
					Content(Contains("You can only build a patch from one commit/stash-entry at a time. Discard current patch?")).
					Confirm()

				t.Views().Secondary().Content(Contains("file1").DoesNotContain("file2"))
			})
	},
})
View Source
var ToggleRange = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Check multi select toggle logic",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir1")
		shell.CreateFileAndAdd("dir1/file1-a", "d2f1 first line\nsecond line\nthird line\n")
		shell.CreateFileAndAdd("dir1/file2-a", "d1f2 first line\n")
		shell.CreateFileAndAdd("dir1/file3-a", "d1f3 first line\n")

		shell.CreateDir("dir2")
		shell.CreateFileAndAdd("dir2/file1-b", "d2f1 first line\nsecond line\nthird line\n")
		shell.CreateFileAndAdd("dir2/file2-b", "d2f2 first line\n")
		shell.CreateFileAndAdd("dir2/file3-b", "d2f3 first line\nsecond line\n")

		shell.Commit("first commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("first commit").IsSelected(),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("▼ dir1").IsSelected(),
				Contains("  A").Contains("file1-a"),
				Contains("  A").Contains("file2-a"),
				Contains("  A").Contains("file3-a"),
				Contains("▼ dir2"),
				Contains("  A").Contains("file1-b"),
				Contains("  A").Contains("file2-b"),
				Contains("  A").Contains("file3-b"),
			).
			NavigateToLine(Contains("file1-a")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file3-a")).
			PressPrimaryAction().
			Lines(
				Contains("▼ dir1"),
				Contains("  ●").Contains("file1-a").IsSelected(),
				Contains("  ●").Contains("file2-a").IsSelected(),
				Contains("  ●").Contains("file3-a").IsSelected(),
				Contains("▼ dir2"),
				Contains("  A").Contains("file1-b"),
				Contains("  A").Contains("file2-b"),
				Contains("  A").Contains("file3-b"),
			).
			PressEscape().
			NavigateToLine(Contains("file3-b")).
			PressEnter()

		t.Views().Main().IsFocused().
			NavigateToLine(Contains("second line")).
			PressPrimaryAction().
			PressEscape()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("▼ dir1"),
				Contains("  ●").Contains("file1-a"),
				Contains("  ●").Contains("file2-a"),
				Contains("  ●").Contains("file3-a"),
				Contains("▼ dir2"),
				Contains("  A").Contains("file1-b"),
				Contains("  A").Contains("file2-b"),
				Contains("  ◐").Contains("file3-b").IsSelected(),
			).
			NavigateToLine(Contains("dir1")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("dir2")).
			PressPrimaryAction().
			Lines(
				Contains("▼ dir1").IsSelected(),
				Contains("  ●").Contains("file1-a").IsSelected(),
				Contains("  ●").Contains("file2-a").IsSelected(),
				Contains("  ●").Contains("file3-a").IsSelected(),
				Contains("▼ dir2").IsSelected(),
				Contains("  ●").Contains("file1-b"),
				Contains("  ●").Contains("file2-b"),
				Contains("  ●").Contains("file3-b"),
			).
			PressPrimaryAction().
			Lines(
				Contains("▼ dir1").IsSelected(),
				Contains("  A").Contains("file1-a").IsSelected(),
				Contains("  A").Contains("file2-a").IsSelected(),
				Contains("  A").Contains("file3-a").IsSelected(),
				Contains("▼ dir2").IsSelected(),
				Contains("  A").Contains("file1-b"),
				Contains("  A").Contains("file2-b"),
				Contains("  A").Contains("file3-b"),
			)
	},
})

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