file

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 2 Imported by: 0

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: "",
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.Gui.ShowFileTree = true
	},
	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 DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding all possible permutations of changed files",
	ExtraCmdArgs: "",
	Skip:         true,
	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.RunShellCommandExpectError(`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: "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: "R ", label: "renamed.txt → renamed2.txt", menuTitle: "renamed2.txt"},
			{status: "AM", label: "added-changed.txt", menuTitle: "added-changed.txt"},
			{status: "A ", label: "new-staged.txt", menuTitle: "new-staged.txt"},
			{status: "??", label: "new.txt", menuTitle: "new.txt"},
		})

		t.Views().Files().IsEmpty()
	},
})
View Source
var DiscardStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding staged changes",
	ExtraCmdArgs: "",
	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(` M fileToRemove`),
				Contains(`?? file3`),
			).
			SelectNextItem().
			PressPrimaryAction().
			Lines(
				Contains(` M file2`),
				Contains(`M  fileToRemove`).IsSelected(),
				Contains(`?? file3`),
			).
			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 GitIgnore = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that we can't ignore the .gitignore file, then ignore/exclude other files",
	ExtraCmdArgs: "",
	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"))
			})
	},
})

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