file

package
v0.40.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 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 DirWithUntrackedFile = NewIntegrationTest(NewIntegrationTestArgs{

	Description:  "When selecting a directory that contains an untracked file, we should not get an error",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFile("dir/file", "foo")
		shell.GitAddAll()
		shell.Commit("first commit")
		shell.CreateFile("dir/untracked", "bar")
		shell.UpdateFile("dir/file", "baz")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Lines(
				Contains("first commit"),
			)

		t.Views().Main().
			Content(DoesNotContain("error: Could not access")).
			Content(Contains("baz"))
	},
})
View Source
var DiscardAllDirChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding all changes in a directory",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {

		shell.CreateDir("dir")

		shell.RunShellCommand(`echo test > dir/both-deleted.txt`)
		shell.RunShellCommand(`git checkout -b conflict && git add dir/both-deleted.txt`)
		shell.RunShellCommand(`echo bothmodded > dir/both-modded.txt && git add dir/both-modded.txt`)
		shell.RunShellCommand(`echo haha > dir/deleted-them.txt && git add dir/deleted-them.txt`)
		shell.RunShellCommand(`echo haha2 > dir/deleted-us.txt && git add dir/deleted-us.txt`)
		shell.RunShellCommand(`echo mod > dir/modded.txt && git add dir/modded.txt`)
		shell.RunShellCommand(`echo mod > dir/modded-staged.txt && git add dir/modded-staged.txt`)
		shell.RunShellCommand(`echo del > dir/deleted.txt && git add dir/deleted.txt`)
		shell.RunShellCommand(`echo del > dir/deleted-staged.txt && git add dir/deleted-staged.txt`)
		shell.RunShellCommand(`echo change-delete > dir/change-delete.txt && git add dir/change-delete.txt`)
		shell.RunShellCommand(`echo delete-change > dir/delete-change.txt && git add dir/delete-change.txt`)
		shell.RunShellCommand(`echo double-modded > dir/double-modded.txt && git add dir/double-modded.txt`)
		shell.RunShellCommand(`echo "renamed\nhaha" > dir/renamed.txt && git add dir/renamed.txt`)
		shell.RunShellCommand(`git commit -m one`)

		shell.RunShellCommand(`git branch conflict_second && git mv dir/both-deleted.txt dir/added-them-changed-us.txt`)
		shell.RunShellCommand(`git commit -m "dir/both-deleted.txt renamed in dir/added-them-changed-us.txt"`)
		shell.RunShellCommand(`echo blah > dir/both-added.txt && git add dir/both-added.txt`)
		shell.RunShellCommand(`echo mod1 > dir/both-modded.txt && git add dir/both-modded.txt`)
		shell.RunShellCommand(`rm dir/deleted-them.txt && git add dir/deleted-them.txt`)
		shell.RunShellCommand(`echo modded > dir/deleted-us.txt && git add dir/deleted-us.txt`)
		shell.RunShellCommand(`git commit -m "two"`)

		shell.RunShellCommand(`git checkout conflict_second`)
		shell.RunShellCommand(`git mv dir/both-deleted.txt dir/changed-them-added-us.txt`)
		shell.RunShellCommand(`git commit -m "both-deleted.txt renamed in dir/changed-them-added-us.txt"`)
		shell.RunShellCommand(`echo mod2 > dir/both-modded.txt && git add dir/both-modded.txt`)
		shell.RunShellCommand(`echo blah2 > dir/both-added.txt && git add dir/both-added.txt`)
		shell.RunShellCommand(`echo modded > dir/deleted-them.txt && git add dir/deleted-them.txt`)
		shell.RunShellCommand(`rm dir/deleted-us.txt && git add dir/deleted-us.txt`)
		shell.RunShellCommand(`git commit -m "three"`)
		shell.RunShellCommand(`git reset --hard conflict_second`)
		shell.RunCommandExpectError([]string{"git", "merge", "conflict"})

		shell.RunShellCommand(`echo "new" > dir/new.txt`)
		shell.RunShellCommand(`echo "new staged" > dir/new-staged.txt && git add dir/new-staged.txt`)
		shell.RunShellCommand(`echo mod2 > dir/modded.txt`)
		shell.RunShellCommand(`echo mod2 > dir/modded-staged.txt && git add dir/modded-staged.txt`)
		shell.RunShellCommand(`rm dir/deleted.txt`)
		shell.RunShellCommand(`rm dir/deleted-staged.txt && git add dir/deleted-staged.txt`)
		shell.RunShellCommand(`echo change-delete2 > dir/change-delete.txt && git add dir/change-delete.txt`)
		shell.RunShellCommand(`rm dir/change-delete.txt`)
		shell.RunShellCommand(`rm dir/delete-change.txt && git add dir/delete-change.txt`)
		shell.RunShellCommand(`echo "changed" > dir/delete-change.txt`)
		shell.RunShellCommand(`echo "change1" > dir/double-modded.txt && git add dir/double-modded.txt`)
		shell.RunShellCommand(`echo "change2" > dir/double-modded.txt`)
		shell.RunShellCommand(`echo before > dir/added-changed.txt && git add dir/added-changed.txt`)
		shell.RunShellCommand(`echo after > dir/added-changed.txt`)
		shell.RunShellCommand(`rm dir/renamed.txt && git add dir/renamed.txt`)
		shell.RunShellCommand(`echo "renamed\nhaha" > dir/renamed2.txt && git add dir/renamed2.txt`)
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("UA").Contains("added-them-changed-us.txt"),
				Contains("AA").Contains("both-added.txt"),
				Contains("DD").Contains("both-deleted.txt"),
				Contains("UU").Contains("both-modded.txt"),
				Contains("AU").Contains("changed-them-added-us.txt"),
				Contains("UD").Contains("deleted-them.txt"),
				Contains("DU").Contains("deleted-us.txt"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("dir")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			Tap(func() {
				t.Common().ContinueOnConflictsResolved()
			}).
			Lines(
				Contains("dir").IsSelected(),
				Contains(" M").Contains("added-changed.txt"),
				Contains(" D").Contains("change-delete.txt"),
				Contains("??").Contains("delete-change.txt"),
				Contains(" D").Contains("deleted.txt"),
				Contains(" M").Contains("double-modded.txt"),
				Contains(" M").Contains("modded.txt"),
				Contains("??").Contains("new.txt"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("dir")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			IsEmpty()
	},
})
View Source
var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding all possible permutations of changed files",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {

		shell.RunShellCommand(`echo test > both-deleted.txt`)
		shell.RunShellCommand(`git checkout -b conflict && git add both-deleted.txt`)
		shell.RunShellCommand(`echo bothmodded > both-modded.txt && git add both-modded.txt`)
		shell.RunShellCommand(`echo haha > deleted-them.txt && git add deleted-them.txt`)
		shell.RunShellCommand(`echo haha2 > deleted-us.txt && git add deleted-us.txt`)
		shell.RunShellCommand(`echo mod > modded.txt && git add modded.txt`)
		shell.RunShellCommand(`echo mod > modded-staged.txt && git add modded-staged.txt`)
		shell.RunShellCommand(`echo del > deleted.txt && git add deleted.txt`)
		shell.RunShellCommand(`echo del > deleted-staged.txt && git add deleted-staged.txt`)
		shell.RunShellCommand(`echo change-delete > change-delete.txt && git add change-delete.txt`)
		shell.RunShellCommand(`echo delete-change > delete-change.txt && git add delete-change.txt`)
		shell.RunShellCommand(`echo double-modded > double-modded.txt && git add double-modded.txt`)
		shell.RunShellCommand(`echo "renamed\nhaha" > renamed.txt && git add renamed.txt`)
		shell.RunShellCommand(`git commit -m one`)

		shell.RunShellCommand(`git branch conflict_second && git mv both-deleted.txt added-them-changed-us.txt`)
		shell.RunShellCommand(`git commit -m "both-deleted.txt renamed in added-them-changed-us.txt"`)
		shell.RunShellCommand(`echo blah > both-added.txt && git add both-added.txt`)
		shell.RunShellCommand(`echo mod1 > both-modded.txt && git add both-modded.txt`)
		shell.RunShellCommand(`rm deleted-them.txt && git add deleted-them.txt`)
		shell.RunShellCommand(`echo modded > deleted-us.txt && git add deleted-us.txt`)
		shell.RunShellCommand(`git commit -m "two"`)

		shell.RunShellCommand(`git checkout conflict_second`)
		shell.RunShellCommand(`git mv both-deleted.txt changed-them-added-us.txt`)
		shell.RunShellCommand(`git commit -m "both-deleted.txt renamed in changed-them-added-us.txt"`)
		shell.RunShellCommand(`echo mod2 > both-modded.txt && git add both-modded.txt`)
		shell.RunShellCommand(`echo blah2 > both-added.txt && git add both-added.txt`)
		shell.RunShellCommand(`echo modded > deleted-them.txt && git add deleted-them.txt`)
		shell.RunShellCommand(`rm deleted-us.txt && git add deleted-us.txt`)
		shell.RunShellCommand(`git commit -m "three"`)
		shell.RunShellCommand(`git reset --hard conflict_second`)
		shell.RunCommandExpectError([]string{"git", "merge", "conflict"})

		shell.RunShellCommand(`echo "new" > new.txt`)
		shell.RunShellCommand(`echo "new staged" > new-staged.txt && git add new-staged.txt`)
		shell.RunShellCommand(`echo mod2 > modded.txt`)
		shell.RunShellCommand(`echo mod2 > modded-staged.txt && git add modded-staged.txt`)
		shell.RunShellCommand(`rm deleted.txt`)
		shell.RunShellCommand(`rm deleted-staged.txt && git add deleted-staged.txt`)
		shell.RunShellCommand(`echo change-delete2 > change-delete.txt && git add change-delete.txt`)
		shell.RunShellCommand(`rm change-delete.txt`)
		shell.RunShellCommand(`rm delete-change.txt && git add delete-change.txt`)
		shell.RunShellCommand(`echo "changed" > delete-change.txt`)
		shell.RunShellCommand(`echo "change1" > double-modded.txt && git add double-modded.txt`)
		shell.RunShellCommand(`echo "change2" > double-modded.txt`)
		shell.RunShellCommand(`echo before > added-changed.txt && git add added-changed.txt`)
		shell.RunShellCommand(`echo after > added-changed.txt`)
		shell.RunShellCommand(`rm renamed.txt && git add renamed.txt`)
		shell.RunShellCommand(`echo "renamed\nhaha" > renamed2.txt && git add renamed2.txt`)
	},

	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		type statusFile struct {
			status    string
			label     string
			menuTitle string
		}

		discardOneByOne := func(files []statusFile) {
			for _, file := range files {
				t.Views().Files().
					IsFocused().
					SelectedLine(Contains(file.status + " " + file.label)).
					Press(keys.Universal.Remove)

				t.ExpectPopup().Menu().Title(Equals(file.menuTitle)).Select(Contains("Discard all changes")).Confirm()
			}
		}

		discardOneByOne([]statusFile{
			{status: "UA", label: "added-them-changed-us.txt", menuTitle: "added-them-changed-us.txt"},
			{status: "AA", label: "both-added.txt", menuTitle: "both-added.txt"},
			{status: "DD", label: "both-deleted.txt", menuTitle: "both-deleted.txt"},
			{status: "UU", label: "both-modded.txt", menuTitle: "both-modded.txt"},
			{status: "AU", label: "changed-them-added-us.txt", menuTitle: "changed-them-added-us.txt"},
			{status: "UD", label: "deleted-them.txt", menuTitle: "deleted-them.txt"},
			{status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"},
		})

		t.ExpectPopup().Confirmation().
			Title(Equals("Continue")).
			Content(Contains("All merge conflicts resolved. Continue?")).
			Cancel()

		discardOneByOne([]statusFile{
			{status: "AM", label: "added-changed.txt", menuTitle: "added-changed.txt"},
			{status: "MD", label: "change-delete.txt", menuTitle: "change-delete.txt"},
			{status: "D ", label: "delete-change.txt", menuTitle: "delete-change.txt"},
			{status: "D ", label: "deleted-staged.txt", menuTitle: "deleted-staged.txt"},
			{status: " D", label: "deleted.txt", menuTitle: "deleted.txt"},
			{status: "MM", label: "double-modded.txt", menuTitle: "double-modded.txt"},
			{status: "M ", label: "modded-staged.txt", menuTitle: "modded-staged.txt"},
			{status: " M", label: "modded.txt", menuTitle: "modded.txt"},
			{status: "A ", label: "new-staged.txt", menuTitle: "new-staged.txt"},
			{status: "??", label: "new.txt", menuTitle: "new.txt"},

			{status: "R ", label: "renamed.txt → renamed2.txt", menuTitle: "renamed2.txt"},
		})

		t.Views().Files().IsEmpty()
	},
})
View Source
var DiscardStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding staged changes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("fileToRemove", "original content")
		shell.CreateFileAndAdd("file2", "original content")
		shell.Commit("first commit")

		shell.CreateFile("file3", "original content")
		shell.UpdateFile("fileToRemove", "new content")
		shell.UpdateFile("file2", "new content")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains(` M file2`).IsSelected(),
				Contains(`?? file3`),
				Contains(` M fileToRemove`),
			).
			NavigateToLine(Contains(`fileToRemove`)).
			PressPrimaryAction().
			Lines(
				Contains(` M file2`),
				Contains(`?? file3`),
				Contains(`M  fileToRemove`).IsSelected(),
			).
			Press(keys.Files.ViewResetOptions)

		t.ExpectPopup().Menu().Title(Equals("")).Select(Contains("Discard staged changes")).Confirm()

		t.Views().Files().
			Lines(
				Contains(` M file2`),
				Contains(`?? file3`).IsSelected(),
			)

		t.FileSystem().FileContent("fileToRemove", Equals("original content"))
	},
})
View Source
var DiscardUnstagedDirChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding unstaged changes in a directory",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFileAndAdd("dir/file-one", "original content\n")

		shell.Commit("first commit")

		shell.UpdateFileAndAdd("dir/file-one", "original content\nnew content\n")
		shell.UpdateFile("dir/file-one", "original content\nnew content\neven newer content\n")

		shell.CreateDir("dir/subdir")
		shell.CreateFile("dir/subdir/unstaged-file-one", "unstaged file")
		shell.CreateFile("dir/unstaged-file-two", "unstaged file")

		shell.CreateFile("unstaged-file-three", "unstaged file")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("subdir"),
				Contains("??").Contains("unstaged-file-one"),
				Contains("MM").Contains("file-one"),
				Contains("??").Contains("unstaged-file-two"),
				Contains("??").Contains("unstaged-file-three"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("dir")).
					Select(Contains("Discard unstaged changes")).
					Confirm()
			}).
			Lines(
				Contains("dir").IsSelected(),
				Contains("M ").Contains("file-one"),

				Contains("??").Contains("unstaged-file-three"),
			)

		t.FileSystem().FileContent("dir/file-one", Equals("original content\nnew content\n"))
	},
})
View Source
var DiscardUnstagedFileChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding unstaged changes in a file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file-one", "original content\n")

		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file-one", "original content\nnew content\n")
		shell.UpdateFile("file-one", "original content\nnew content\neven newer content\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("MM").Contains("file-one").IsSelected(),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("file-one")).
					Select(Contains("Discard unstaged changes")).
					Confirm()
			}).
			Lines(
				Contains("M ").Contains("file-one").IsSelected(),
			)

		t.FileSystem().FileContent("file-one", Equals("original content\nnew content\n"))
	},
})
View Source
var Gitignore = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that we can't ignore the .gitignore file, then ignore/exclude other files",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile(".gitignore", "")
		shell.CreateFile("toExclude", "")
		shell.CreateFile("toIgnore", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains(`?? .gitignore`).IsSelected(),
				Contains(`?? toExclude`),
				Contains(`?? toIgnore`),
			).
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()

				t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot exclude .gitignore")).Confirm()
			}).
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .gitignore")).Confirm()

				t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot ignore .gitignore")).Confirm()

				t.FileSystem().FileContent(".gitignore", Equals(""))
				t.FileSystem().FileContent(".git/info/exclude", DoesNotContain(".gitignore"))
			}).
			SelectNextItem().
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()

				t.FileSystem().FileContent(".gitignore", Equals(""))
				t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
			}).
			SelectNextItem().
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .gitignore")).Confirm()

				t.FileSystem().FileContent(".gitignore", Equals("toIgnore\n"))
				t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
			})
	},
})
View Source
var RememberCommitMessageAfterFail = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that the commit message is remembered after a failed attempt at committing",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile(".git/hooks/pre-commit", preCommitHook)
		shell.MakeExecutable(".git/hooks/pre-commit")

		shell.CreateFileAndAdd("one", "one")

		shell.CreateFile("bad", "bad")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("bad"),
				Contains("one"),
			).
			Press(keys.Files.CommitChanges).
			Tap(func() {
				t.ExpectPopup().CommitMessagePanel().Type("my message").Confirm()

				t.ExpectPopup().Alert().Title(Equals("Error")).Content(Contains("Git command failed")).Confirm()
			}).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("bad")).Select(Contains("Discard all changes")).Confirm()
			}).
			Lines(
				Contains("one"),
			).
			Press(keys.Files.CommitChanges).
			Tap(func() {
				t.ExpectPopup().CommitMessagePanel().
					InitialText(Equals("my message")).
					Confirm()

				t.Views().Commits().
					Lines(
						Contains("my message"),
					)
			})
	},
})

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