summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-08-09 21:27:12 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-08-13 13:55:08 +1000
commitba96baee32f5d02173312b357327eb7478492f89 (patch)
treefbd0c91d5799f9519d617f7041518c0c7e14d2bc
parentd890238c7bcbdd62e7158df0c1f3f0e5c0b05b66 (diff)
move code from main into app package to allow test to be injected
-rw-r--r--main.go22
-rw-r--r--pkg/app/app.go6
-rw-r--r--pkg/app/entry_point.go (renamed from pkg/app/run.go)29
-rw-r--r--pkg/app/types/types.go (renamed from pkg/gui/types/main_args.go)16
-rw-r--r--pkg/gui/gui.go32
-rw-r--r--pkg/gui/gui_adapter.go (renamed from pkg/gui/gui_adapter_impl.go)21
-rw-r--r--pkg/gui/recent_repos_panel.go3
-rw-r--r--pkg/gui/test_mode.go8
-rw-r--r--pkg/gui/types/test.go27
-rw-r--r--pkg/integration/README.md11
-rw-r--r--pkg/integration/deprecated/integration.go (renamed from pkg/integration/integration_old.go)2
-rw-r--r--pkg/integration/deprecated/integration_test.go (renamed from pkg/gui/old_gui_test.go)40
-rw-r--r--pkg/integration/deprecated/runner/main.go (renamed from test/runner_old/main.go)10
-rw-r--r--pkg/integration/deprecated/tui/main.go (renamed from test/lazyintegration/main.go)12
-rw-r--r--pkg/integration/env.go29
-rw-r--r--pkg/integration/helpers/assert.go29
-rw-r--r--pkg/integration/helpers/input.go65
-rw-r--r--pkg/integration/helpers/shell.go32
-rw-r--r--pkg/integration/helpers/test.go (renamed from pkg/integration/helpers/test_impl.go)54
-rw-r--r--pkg/integration/integration.go477
-rw-r--r--pkg/integration/integration_test.go (renamed from pkg/gui/gui_test.go)17
-rw-r--r--pkg/integration/integration_tests/tests.go19
-rw-r--r--pkg/integration/runner/main.go (renamed from test/runner/main.go)18
-rw-r--r--pkg/integration/tests/branch/suggestions.go (renamed from pkg/integration/integration_tests/branch/suggestions.go)5
-rw-r--r--pkg/integration/tests/commit/commit.go (renamed from pkg/integration/integration_tests/commit/commit.go)5
-rw-r--r--pkg/integration/tests/commit/new_branch.go (renamed from pkg/integration/integration_tests/commit/new_branch.go)5
-rw-r--r--pkg/integration/tests/interactive_rebase/one.go (renamed from pkg/integration/integration_tests/interactive_rebase/one.go)5
-rw-r--r--pkg/integration/tests/tests.go18
-rw-r--r--pkg/integration/tui/main.go323
-rw-r--r--pkg/integration/types/types.go106
-rw-r--r--test/integration_new/commit/commit/expected/repo/.git_keep/indexbin209 -> 209 bytes
-rw-r--r--test/integration_new/commit/commit/expected/repo/.git_keep/logs/HEAD2
-rw-r--r--test/integration_new/commit/commit/expected/repo/.git_keep/logs/refs/heads/master2
-rw-r--r--test/integration_new/commit/commit/expected/repo/.git_keep/objects/46/0150760ff1f381c3f5769b919cb73107c5871abin125 -> 0 bytes
-rw-r--r--test/integration_new/commit/commit/expected/repo/.git_keep/objects/94/4b9ea58bef8f6352c3a081a1d0037125bcaabcbin0 -> 124 bytes
-rw-r--r--test/integration_new/commit/commit/expected/repo/.git_keep/refs/heads/master2
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/logs/HEAD8
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/logs/refs/heads/master6
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/logs/refs/heads/my-branch-name2
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/objects/0a/f36e404e6fec1c3a4d887e30622238e5ea0b2bbin0 -> 147 bytes
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/objects/47/0038e1336649b2965305f9f6a82501a836810ebin118 -> 0 bytes
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/objects/4e/72cd440eec154569568bff8d4c955052ae246cbin0 -> 118 bytes
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/objects/56/3414ba32c967cfbe21a17fe892d6118c1c58e82
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/objects/62/a60693a2e154e745ee353f67a05156d0532c23bin148 -> 0 bytes
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/objects/c8/bec8f2b323cbb476e708bd10c145ea7cc9f7262
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/refs/heads/master2
-rw-r--r--test/integration_new/commit/new_branch/expected/repo/.git_keep/refs/heads/my-branch-name2
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/COMMIT_EDITMSG10
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/ORIG_HEAD2
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/REBASE_HEAD2
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/indexbin460 -> 460 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/logs/HEAD20
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/logs/refs/heads/master12
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/2e/2cd25ffdec58d32b5d549f8402bd054e22cc2a3
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/67/41ab4fe22a3d36b6c64397fc4295dbae1ba71d3
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/84/b1ae9d83049341897c9388afffdc9049c3317f3
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/8a/3839811a7a9f4c678090c9def892d1e7ad7e54bin0 -> 147 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/90/fda12ce101e7d0d4594a879e5bbd1be3c857a8bin0 -> 147 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/9c/68b57ac7b652fbebc5e93a9a1b72014400c2692
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/a1/a6f7bda6aeaa08ec75f590845780fde90d901cbin117 -> 0 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/aa/2585aff7d2278341ca816f187e623503d7c4fb4
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/ab/a3469fd6fc584a6af9c0073873005ffaaea56c3
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/b8/5535ebf12659044c33386376121d76756ceb59bin0 -> 222 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/cb/7e56856ecee89fa44c613e094fcf962fe18cf1bin148 -> 0 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/cc/9defb8ae9134f1a9a6c28a0006dc8c8cd78347bin0 -> 117 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/da/71be1afbb03f46e91ab5de17d69f148bb009f34
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/objects/f4/316f7a6df3fe5b7e8da1b2c8767ed1e825dc05bin153 -> 0 bytes
-rw-r--r--test/integration_new/interactive_rebase/one/expected/repo/.git_keep/refs/heads/master2
68 files changed, 1080 insertions, 466 deletions
diff --git a/main.go b/main.go
index 8684b8cd6..6faf41ddf 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,8 @@ import (
"github.com/integrii/flaggy"
"github.com/jesseduffield/lazygit/pkg/app"
+ "github.com/jesseduffield/lazygit/pkg/integration"
+ integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
)
@@ -24,8 +26,9 @@ var (
func main() {
cliArgs := parseCliArgsAndEnvVars()
buildInfo := getBuildInfo()
+ integrationTest := getIntegrationTest()
- app.Start(cliArgs, buildInfo, nil)
+ app.Start(cliArgs, buildInfo, integrationTest)
}
func parseCliArgsAndEnvVars() *app.CliArgs {
@@ -129,3 +132,20 @@ func getBuildInfo() *app.BuildInfo {
return buildInfo
}
+
+func getIntegrationTest() integrationTypes.IntegrationTest {
+ integrationTestName := os.Getenv("LAZYGIT_TEST_NAME")
+ if integrationTestName == "" {
+ return nil
+ }
+
+ // unsetting so that if we run lazygit in as a 'daemon' we don't think we're trying to run a test again
+ os.Unsetenv("LAZYGIT_TEST_NAME")
+ for _, candidateTest := range integration.Tests {
+ if candidateTest.Name() == integrationTestName {
+ return candidateTest
+ }
+ }
+
+ panic("Could not find integration test with name: " + integrationTestName)
+}
diff --git a/pkg/app/app.go b/pkg/app/app.go
index a45ffb118..3a1c127de 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -14,6 +14,7 @@ import (
"github.com/go-errors/errors"
"github.com/jesseduffield/generics/slices"
+ appTypes "github.com/jesseduffield/lazygit/pkg/app/types"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@@ -22,7 +23,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/env"
"github.com/jesseduffield/lazygit/pkg/gui"
- "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/updates"
)
@@ -41,7 +41,7 @@ type App struct {
func Run(
config config.AppConfigurer,
common *common.Common,
- startArgs types.StartArgs,
+ startArgs appTypes.StartArgs,
) {
app, err := NewApp(config, common)
@@ -217,7 +217,7 @@ func (app *App) setupRepo() (bool, error) {
return false, nil
}
-func (app *App) Run(startArgs types.StartArgs) error {
+func (app *App) Run(startArgs appTypes.StartArgs) error {
err := app.Gui.RunAndHandleError(startArgs)
return err
}
diff --git a/pkg/app/run.go b/pkg/app/entry_point.go
index b1e2c396f..551b959a6 100644
--- a/pkg/app/run.go
+++ b/pkg/app/entry_point.go
@@ -10,9 +10,9 @@ import (
"strings"
"github.com/jesseduffield/lazygit/pkg/app/daemon"
+ appTypes "github.com/jesseduffield/lazygit/pkg/app/types"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/env"
- "github.com/jesseduffield/lazygit/pkg/gui/types"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
"github.com/jesseduffield/lazygit/pkg/logs"
"gopkg.in/yaml.v3"
@@ -40,12 +40,7 @@ type BuildInfo struct {
BuildSource string
}
-// only used when running integration tests
-type TestConfig struct {
- Test integrationTypes.Test
-}
-
-func Start(cliArgs *CliArgs, buildInfo *BuildInfo, test integrationTypes.Test) {
+func Start(cliArgs *CliArgs, buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTest) {
if cliArgs.RepoPath != "" {
if cliArgs.WorkTree != "" || cliArgs.GitDir != "" {
log.Fatal("--path option is incompatible with the --work-tree and --git-dir options")
@@ -118,8 +113,8 @@ func Start(cliArgs *CliArgs, buildInfo *BuildInfo, test integrationTypes.Test) {
log.Fatal(err.Error())
}
- if test != nil {
- test.SetupConfig(appConfig)
+ if integrationTest != nil {
+ integrationTest.SetupConfig(appConfig)
}
common, err := NewCommon(appConfig)
@@ -134,23 +129,23 @@ func Start(cliArgs *CliArgs, buildInfo *BuildInfo, test integrationTypes.Test) {
parsedGitArg := parseGitArg(cliArgs.GitArg)
- Run(appConfig, common, types.NewStartArgs(cliArgs.FilterPath, parsedGitArg, test))
+ Run(appConfig, common, appTypes.NewStartArgs(cliArgs.FilterPath, parsedGitArg, integrationTest))
}
-func parseGitArg(gitArg string) types.GitArg {
- typedArg := types.GitArg(gitArg)
+func parseGitArg(gitArg string) appTypes.GitArg {
+ typedArg := appTypes.GitArg(gitArg)
// using switch so that linter catches when a new git arg value is defined but not handled here
switch typedArg {
- case types.GitArgNone, types.GitArgStatus, types.GitArgBranch, types.GitArgLog, types.GitArgStash:
+ case appTypes.GitArgNone, appTypes.GitArgStatus, appTypes.GitArgBranch, appTypes.GitArgLog, appTypes.GitArgStash:
return typedArg
}
permittedValues := []string{
- string(types.GitArgStatus),
- string(types.GitArgBranch),
- string(types.GitArgLog),
- string(types.GitArgStash),
+ string(appTypes.GitArgStatus),
+ string(appTypes.GitArgBranch),
+ string(appTypes.GitArgLog),
+ string(appTypes.GitArgStash),
}
log.Fatalf("Invalid git arg value: '%s'. Must be one of the following values: %s. e.g. 'lazygit status'. See 'lazygit --help'.",
diff --git a/pkg/gui/types/main_args.go b/pkg/app/types/types.go
index 7d9b9fbb7..002111087 100644
--- a/pkg/gui/types/main_args.go
+++ b/pkg/app/types/types.go
@@ -1,4 +1,8 @@
-package types
+package app
+
+import (
+ integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
+)
// StartArgs is the struct that represents some things we want to do on program start
type StartArgs struct {
@@ -7,7 +11,7 @@ type StartArgs struct {
// GitArg determines what context we open in
GitArg GitArg
// integration test (only relevant when invoking lazygit in the context of an integration test)
- Test Test
+ IntegrationTest integrationTypes.IntegrationTest
}
type GitArg string
@@ -20,10 +24,10 @@ const (
GitArgStash GitArg = "stash"
)
-func NewStartArgs(filterPath string, gitArg GitArg, test Test) StartArgs {
+func NewStartArgs(filterPath string, gitArg GitArg, test integrationTypes.IntegrationTest) StartArgs {
return StartArgs{
- FilterPath: filterPath,
- GitArg: gitArg,
- Test: test,
+ FilterPath: filterPath,
+ GitArg: gitArg,
+ IntegrationTest: test,
}
}
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 11c8af78b..8be5a4a4d 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/jesseduffield/gocui"
+ appTypes "github.com/jesseduffield/lazygit/pkg/app/types"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
@@ -31,6 +32,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/services/custom_commands"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
+ integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
"github.com/jesseduffield/lazygit/pkg/tasks"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/updates"
@@ -213,7 +215,7 @@ const (
COMPLETE
)
-func (gui *Gui) onNewRepo(startArgs types.StartArgs, reuseState bool) error {
+func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool) error {
var err error
gui.git, err = commands.NewGitCommand(
gui.Common,
@@ -245,7 +247,7 @@ func (gui *Gui) onNewRepo(startArgs types.StartArgs, reuseState bool) error {
// it gets a bit confusing to land back in the status panel when visiting a repo
// you've already switched from. There's no doubt some easy way to make the UX
// optimal for all cases but I'm too lazy to think about what that is right now
-func (gui *Gui) resetState(startArgs types.StartArgs, reuseState bool) {
+func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) {
currentDir, err := os.Getwd()
if reuseState {
@@ -300,28 +302,28 @@ func (gui *Gui) resetState(startArgs types.StartArgs, reuseState bool) {
gui.RepoStateMap[Repo(currentDir)] = gui.State
}
-func initialScreenMode(startArgs types.StartArgs) WindowMaximisation {
- if startArgs.FilterPath != "" || startArgs.GitArg != types.GitArgNone {
+func initialScreenMode(startArgs appTypes.StartArgs) WindowMaximisation {
+ if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
return SCREEN_HALF
} else {
return SCREEN_NORMAL
}
}
-func initialContext(contextTree *context.ContextTree, startArgs types.StartArgs) types.IListContext {
+func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartArgs) types.IListContext {
var initialContext types.IListContext = contextTree.Files
if startArgs.FilterPath != "" {
initialContext = contextTree.LocalCommits
- } else if startArgs.GitArg != types.GitArgNone {
+ } else if startArgs.GitArg != appTypes.GitArgNone {
switch startArgs.GitArg {
- case types.GitArgStatus:
+ case appTypes.GitArgStatus:
initialContext = contextTree.Files
- case types.GitArgBranch:
+ case appTypes.GitArgBranch:
initialContext = contextTree.Branches
- case types.GitArgLog:
+ case appTypes.GitArgLog:
initialContext = contextTree.LocalCommits
- case types.GitArgStash:
+ case appTypes.GitArgStash:
initialContext = contextTree.Stash
default:
panic("unhandled git arg")
@@ -417,7 +419,7 @@ var RuneReplacements = map[rune]string{
graph.CommitSymbol: "o",
}
-func (gui *Gui) initGocui(headless bool, test types.Test) (*gocui.Gui, error) {
+func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest) (*gocui.Gui, error) {
recordEvents := RecordingEvents()
playMode := gocui.NORMAL
if recordEvents {
@@ -476,8 +478,8 @@ func (gui *Gui) viewTabMap() map[string][]context.TabView {
}
// Run: setup the gui with keybindings and start the mainloop
-func (gui *Gui) Run(startArgs types.StartArgs) error {
- g, err := gui.initGocui(Headless(), startArgs.Test)
+func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
+ g, err := gui.initGocui(Headless(), startArgs.IntegrationTest)
if err != nil {
return err
}
@@ -492,7 +494,7 @@ func (gui *Gui) Run(startArgs types.StartArgs) error {
})
deadlock.Opts.Disable = !gui.Debug
- gui.handleTestMode(startArgs.Test)
+ gui.handleTestMode(startArgs.IntegrationTest)
gui.g.OnSearchEscape = gui.onSearchEscape
if err := gui.Config.ReloadUserConfig(); err != nil {
@@ -553,7 +555,7 @@ func (gui *Gui) Run(startArgs types.StartArgs) error {
return gui.g.MainLoop()
}
-func (gui *Gui) RunAndHandleError(startArgs types.StartArgs) error {
+func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
gui.stopChan = make(chan struct{})
return utils.SafeWithError(func() error {
if err := gui.Run(startArgs); err != nil {
diff --git a/pkg/gui/gui_adapter_impl.go b/pkg/gui/gui_adapter.go
index 427b8eb47..5566f8b0f 100644
--- a/pkg/gui/gui_adapter_impl.go
+++ b/pkg/gui/gui_adapter.go
@@ -9,17 +9,18 @@ import (
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
+ integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
)
// this g