mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 11:02:41 +03:00
Test bare repos with dotfile setup
This commit is contained in:
@@ -27,13 +27,6 @@ func (self Paths) ActualRepo() string {
|
|||||||
return filepath.Join(self.Actual(), "repo")
|
return filepath.Join(self.Actual(), "repo")
|
||||||
}
|
}
|
||||||
|
|
||||||
// When an integration test first runs, we copy everything in the 'actual' directory,
|
|
||||||
// and copy it into the 'expected' directory so that future runs can be compared
|
|
||||||
// against what we expect.
|
|
||||||
func (self Paths) Expected() string {
|
|
||||||
return filepath.Join(self.root, "expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self Paths) Config() string {
|
func (self Paths) Config() string {
|
||||||
return filepath.Join(self.root, "used_config")
|
return filepath.Join(self.root, "used_config")
|
||||||
}
|
}
|
||||||
|
@@ -6,9 +6,11 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazycore/pkg/utils"
|
lazycoreUtils "github.com/jesseduffield/lazycore/pkg/utils"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -30,7 +32,7 @@ func RunTests(
|
|||||||
keyPressDelay int,
|
keyPressDelay int,
|
||||||
maxAttempts int,
|
maxAttempts int,
|
||||||
) error {
|
) error {
|
||||||
projectRootDir := utils.GetLazyRootDirectory()
|
projectRootDir := lazycoreUtils.GetLazyRootDirectory()
|
||||||
err := os.Chdir(projectRootDir)
|
err := os.Chdir(projectRootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -177,8 +179,17 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := []string{tempLazygitPath(), "-debug", "--use-config-dir=" + paths.Config(), "--path=" + paths.ActualRepo()}
|
cmdArgs := []string{tempLazygitPath(), "-debug", "--use-config-dir=" + paths.Config()}
|
||||||
cmdArgs = append(cmdArgs, test.ExtraCmdArgs()...)
|
if !test.useCustomPath {
|
||||||
|
cmdArgs = append(cmdArgs, "--path="+paths.ActualRepo())
|
||||||
|
}
|
||||||
|
resolvedExtraArgs := lo.Map(test.ExtraCmdArgs(), func(arg string, _ int) string {
|
||||||
|
return utils.ResolvePlaceholderString(arg, map[string]string{
|
||||||
|
"actualPath": paths.Actual(),
|
||||||
|
"actualRepoPath": paths.ActualRepo(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
cmdArgs = append(cmdArgs, resolvedExtraArgs...)
|
||||||
|
|
||||||
cmdObj := osCommand.Cmd.New(cmdArgs)
|
cmdObj := osCommand.Cmd.New(cmdArgs)
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ type IntegrationTest struct {
|
|||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
isDemo bool
|
isDemo bool
|
||||||
|
useCustomPath bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ integrationTypes.IntegrationTest = &IntegrationTest{}
|
var _ integrationTypes.IntegrationTest = &IntegrationTest{}
|
||||||
@@ -66,6 +67,10 @@ type NewIntegrationTestArgs struct {
|
|||||||
Height int
|
Height int
|
||||||
// If true, this is not a test but a demo to be added to our docs
|
// If true, this is not a test but a demo to be added to our docs
|
||||||
IsDemo bool
|
IsDemo bool
|
||||||
|
// If true, the test won't invoke lazygit with the --path arg.
|
||||||
|
// Useful for when we're passing --git-dir and --work-tree (because --path is
|
||||||
|
// incompatible with those args)
|
||||||
|
UseCustomPath bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type GitVersionRestriction struct {
|
type GitVersionRestriction struct {
|
||||||
@@ -137,6 +142,7 @@ func NewIntegrationTest(args NewIntegrationTestArgs) *IntegrationTest {
|
|||||||
width: args.Width,
|
width: args.Width,
|
||||||
height: args.Height,
|
height: args.Height,
|
||||||
isDemo: args.IsDemo,
|
isDemo: args.IsDemo,
|
||||||
|
useCustomPath: args.UseCustomPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -245,6 +245,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
worktree.Crud,
|
worktree.Crud,
|
||||||
worktree.CustomCommand,
|
worktree.CustomCommand,
|
||||||
worktree.DetachWorktreeFromBranch,
|
worktree.DetachWorktreeFromBranch,
|
||||||
|
worktree.DotfileBareRepo,
|
||||||
worktree.FastForwardWorktreeBranch,
|
worktree.FastForwardWorktreeBranch,
|
||||||
worktree.ForceRemoveWorktree,
|
worktree.ForceRemoveWorktree,
|
||||||
worktree.RemoveWorktreeFromBranch,
|
worktree.RemoveWorktreeFromBranch,
|
||||||
|
74
pkg/integration/tests/worktree/dotfile_bare_repo.go
Normal file
74
pkg/integration/tests/worktree/dotfile_bare_repo.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package worktree
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Can't think of a better name than 'dotfile' repo: I'm using that
|
||||||
|
// because that's the case we're typically dealing with.
|
||||||
|
|
||||||
|
var DotfileBareRepo = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Open lazygit in the worktree of a dotfile bare repo and add a file and commit",
|
||||||
|
ExtraCmdArgs: []string{"--git-dir={{.actualPath}}/.bare", "--work-tree={{.actualPath}}/repo"},
|
||||||
|
Skip: true,
|
||||||
|
// passing this because we're explicitly passing --git-dir and --work-tree args
|
||||||
|
UseCustomPath: true,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
// we're going to have a directory structure like this:
|
||||||
|
// project
|
||||||
|
// - .bare
|
||||||
|
// - repo (the worktree)
|
||||||
|
//
|
||||||
|
// The first repo is called 'repo' because that's the
|
||||||
|
// directory that all lazygit tests start in
|
||||||
|
|
||||||
|
// Delete the .git dir that all tests start with by default
|
||||||
|
shell.DeleteFile(".git")
|
||||||
|
|
||||||
|
// Create a bare repo in the parent directory
|
||||||
|
shell.RunCommand([]string{"git", "init", "--bare", "../.bare"})
|
||||||
|
shell.RunCommand([]string{"git", "--git-dir=../.bare", "--work-tree=.", "checkout", "-b", "mybranch"})
|
||||||
|
shell.CreateFile("blah", "original content\n")
|
||||||
|
|
||||||
|
// Add a file and commit
|
||||||
|
shell.RunCommand([]string{"git", "--git-dir=../.bare", "--work-tree=.", "add", "blah"})
|
||||||
|
shell.RunCommand([]string{"git", "--git-dir=../.bare", "--work-tree=.", "commit", "-m", "initial commit"})
|
||||||
|
|
||||||
|
shell.UpdateFile("blah", "updated content\n")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Branches().
|
||||||
|
Lines(
|
||||||
|
Contains("mybranch"),
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Views().Commits().
|
||||||
|
Lines(
|
||||||
|
Contains("initial commit"),
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
IsFocused().
|
||||||
|
Lines(
|
||||||
|
Contains(" M blah"), // shows as modified
|
||||||
|
).
|
||||||
|
PressPrimaryAction().
|
||||||
|
Press(keys.Files.CommitChanges)
|
||||||
|
|
||||||
|
t.ExpectPopup().CommitMessagePanel().
|
||||||
|
Title(Equals("Commit summary")).
|
||||||
|
Type("Add blah").
|
||||||
|
Confirm()
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
|
t.Views().Commits().
|
||||||
|
Lines(
|
||||||
|
Contains("Add blah"),
|
||||||
|
Contains("initial commit"),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
Reference in New Issue
Block a user