patch_building

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CopyRenamedFileDiff = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Copy the diff of a renamed file to the clipboard; the diff shows the rename rather than a delete and add",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("original", "line1\nline2\nline3\nline4\nline5\n")
		shell.Commit("first commit")

		shell.RenameFileInGit("original", "renamed")
		shell.UpdateFileAndAdd("renamed", "line1\nline2 changed\nline3\nline4\nline5\n")
		shell.Commit("rename with modification")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("rename with modification").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("original → renamed").IsSelected(),
			).
			Press(keys.Files.CopyFileInfoToClipboard)

		t.ExpectPopup().Menu().
			Title(Equals("Copy to clipboard")).
			Select(Contains("Diff of selected file")).
			Confirm()

		t.ExpectToast(Contains("File diff copied to clipboard"))

		expectClipboard(t,
			Contains("rename from original").
				Contains("rename to renamed").
				Contains("-line2").
				Contains("+line2 changed"),
		)
	},
})
View Source
var RenameSimilarityThresholdChange = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Changing the rename similarity threshold refreshes the commit files panel, but is disabled while building a patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("original", "one\ntwo\nthree\nfour\nfive\n")
		shell.Commit("add original")

		shell.RenameFileInGit("original", "renamed")
		shell.UpdateFileAndAdd("renamed", "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\n")
		shell.Commit("change name and contents")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("change name and contents").IsSelected(),
				Contains("add original"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Equals("▼ /"),
				Equals("  D original"),
				Equals("  A renamed"),
			).
			Press(keys.Universal.DecreaseRenameSimilarityThreshold).
			Tap(func() {
				t.ExpectToast(Equals("Changed rename similarity threshold to 45%"))
			}).
			Lines(
				Equals("R original → renamed"),
			).
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().CommitFiles().
					Press(keys.Universal.IncreaseRenameSimilarityThreshold)
				t.ExpectPopup().Alert().
					Title(Equals("Error")).
					Content(Contains("Cannot change the rename similarity threshold while in patch building mode")).
					Confirm()
			}).
			Lines(
				Contains("original → renamed").IsSelected(),
			)
	},
})
View Source
var RenamedFileWhole = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add a whole renamed file to a custom patch and remove it from the commit, taking the rename with it",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("original", "line1\nline2\nline3\nline4\nline5\n")
		shell.Commit("first commit")

		shell.RenameFileInGit("original", "renamed")
		shell.UpdateFileAndAdd("renamed", "line1\nline2 changed\nline3\nline4\nline5\n")
		shell.Commit("rename with modification")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("rename with modification").IsSelected(),
				Contains("first commit"),
			).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("original → renamed").IsSelected(),
			).
			PressPrimaryAction()

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

		t.Views().Secondary().
			ContainsLines(
				Contains("diff --git a/original b/renamed"),
				Contains("similarity index"),
				Contains("rename from a/original"),
				Contains("rename to b/renamed"),
			)

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

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

		t.Views().Commits().
			Focus().
			Lines(
				Contains("rename with modification").IsSelected(),
				Contains("first commit"),
			)
	},
})
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(
				Equals("▼ /").IsSelected(),
				Equals("  A file1"),
				Equals("  A file2"),
				Equals("  A 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 SelectDirecoriesSharingPrefix = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Select directories sharing a prefix in the commit files view and add them to a custom patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("foo/file", "file1 content")
		shell.CreateFileAndAdd("foobar/file", "file2 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(
				Equals("▼ /").IsSelected(),
				Equals("  ▼ foo"),
				Equals("    A file"),
				Equals("  ▼ foobar"),
				Equals("    A file"),
			).
			SelectNextItem().
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("foobar")).
			PressPrimaryAction().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ foo").IsSelected(),
				Equals("    ● file").IsSelected(),
				Equals("  ▼ foobar").IsSelected(),
				Equals("    ● file"),
			)

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

		t.Views().Secondary().Content(
			Contains("foo/file").Contains("foobar/file"),
		)
	},
})
View Source
var ToggleDirectory = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Toggle a directory for a custom patch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir1")
		shell.CreateFileAndAdd("dir1/file1", "file1 content\n")
		shell.CreateFileAndAdd("dir1/file2", "file2 content\n")
		shell.CreateFileAndAdd("dir1/file3", "file3 content\n")
		shell.CreateFileAndAdd("other-file", "other 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(
				Equals("▼ /").IsSelected(),
				Equals("  ▼ dir1"),
				Equals("    A file1"),
				Equals("    A file2"),
				Equals("    A file3"),
				Equals("  A other-file"),
			).
			NavigateToLine(Contains("dir1")).
			PressPrimaryAction().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ dir1").IsSelected(),
				Equals("    ● file1"),
				Equals("    ● file2"),
				Equals("    ● file3"),
				Equals("  A other-file"),
			)

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

		t.Views().CommitFiles().
			PressPrimaryAction().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ dir1").IsSelected(),
				Equals("    A file1"),
				Equals("    A file2"),
				Equals("    A file3"),
				Equals("  A other-file"),
			)
	},
})
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(
				Equals("▼ /").IsSelected(),
				Equals("  ▼ dir1"),
				Equals("    A file1-a"),
				Equals("    A file2-a"),
				Equals("    A file3-a"),
				Equals("  ▼ dir2"),
				Equals("    A file1-b"),
				Equals("    A file2-b"),
				Equals("    A file3-b"),
			).
			NavigateToLine(Contains("file1-a")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file3-a")).
			PressPrimaryAction().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ dir1"),
				Equals("    ● file1-a").IsSelected(),
				Equals("    ● file2-a").IsSelected(),
				Equals("    ● file3-a").IsSelected(),
				Equals("  ▼ dir2"),
				Equals("    A file1-b"),
				Equals("    A file2-b"),
				Equals("    A file3-b"),
			).
			PressEscape().
			NavigateToLine(Contains("file3-b")).
			PressEnter()

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

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ dir1"),
				Equals("    ● file1-a"),
				Equals("    ● file2-a"),
				Equals("    ● file3-a"),
				Equals("  ▼ dir2"),
				Equals("    A file1-b"),
				Equals("    A file2-b"),
				Equals("    ◐ file3-b").IsSelected(),
			).
			NavigateToLine(Contains("dir1")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("dir2")).
			PressPrimaryAction().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ dir1").IsSelected(),
				Equals("    ● file1-a").IsSelected(),
				Equals("    ● file2-a").IsSelected(),
				Equals("    ● file3-a").IsSelected(),
				Equals("  ▼ dir2").IsSelected(),
				Equals("    ● file1-b"),
				Equals("    ● file2-b"),
				Equals("    ● file3-b"),
			).
			PressPrimaryAction().
			Lines(
				Equals("▼ /"),
				Equals("  ▼ dir1").IsSelected(),
				Equals("    A file1-a").IsSelected(),
				Equals("    A file2-a").IsSelected(),
				Equals("    A file3-a").IsSelected(),
				Equals("  ▼ dir2").IsSelected(),
				Equals("    A file1-b"),
				Equals("    A file2-b"),
				Equals("    A 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