summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuka Markušić <luka.markusic@microblink.com>2022-04-07 18:45:08 +0200
committerJesse Duffield <jessedduffield@gmail.com>2022-04-09 09:53:03 +1000
commit58ed23a47adbc4e0cef119c0f32adceaef28ff48 (patch)
tree210e9ef281a33b3e5e8b5bbf211ecfb6ddd62f48
parent336f2772e80dc20c28fc0ffe7049be3401c86e29 (diff)
Make worktrees work
-rw-r--r--pkg/commands/git.go8
-rw-r--r--pkg/commands/git_test.go14
2 files changed, 13 insertions, 9 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 6c6a3ac7c..64f0455b7 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -63,7 +63,7 @@ func NewGitCommand(
return nil, err
}
- repo, err := setupRepository(gogit.PlainOpen, cmn.Tr.GitconfigParseErr)
+ repo, err := setupRepository(gogit.PlainOpenWithOptions, gogit.PlainOpenOptions{DetectDotGit: false, EnableDotGitCommonDir: true}, cmn.Tr.GitconfigParseErr)
if err != nil {
return nil, err
}
@@ -207,7 +207,7 @@ func resolvePath(path string) (string, error) {
return filepath.EvalSymlinks(path)
}
-func setupRepository(openGitRepository func(string) (*gogit.Repository, error), gitConfigParseErrorStr string) (*gogit.Repository, error) {
+func setupRepository(openGitRepository func(string, *gogit.PlainOpenOptions) (*gogit.Repository, error), options gogit.PlainOpenOptions, gitConfigParseErrorStr string) (*gogit.Repository, error) {
unresolvedPath := env.GetGitDirEnv()
if unresolvedPath == "" {
var err error
@@ -222,7 +222,7 @@ func setupRepository(openGitRepository func(string) (*gogit.Repository, error),
return nil, err
}
- repository, err := openGitRepository(path)
+ repository, err := openGitRepository(path, &options)
if err != nil {
if strings.Contains(err.Error(), `unquoted '\' must be followed by new line`) {
return nil, errors.New(gitConfigParseErrorStr)
@@ -254,7 +254,7 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam
}
fileContent := string(fileBytes)
if !strings.HasPrefix(fileContent, "gitdir: ") {
- return "", errors.New(".git is a file which suggests we are in a submodule but the file's contents do not contain a gitdir pointing to the actual .git directory")
+ return "", errors.New(".git is a file which suggests we are in a submodule or a worktree but the file's contents do not contain a gitdir pointing to the actual .git directory")
}
return strings.TrimSpace(strings.TrimPrefix(fileContent, "gitdir: ")), nil
}
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index a0faf3a78..a36a5c6fe 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -116,18 +116,20 @@ func TestNavigateToRepoRootDirectory(t *testing.T) {
func TestSetupRepository(t *testing.T) {
type scenario struct {
testName string
- openGitRepository func(string) (*gogit.Repository, error)
+ openGitRepository func(string, *gogit.PlainOpenOptions) (*gogit.Repository, error)
errorStr string
+ options gogit.PlainOpenOptions
test func(*gogit.Repository, error)
}
scenarios := []scenario{
{
"A gitconfig parsing error occurred",
- func(string) (*gogit.Repository, error) {
+ func(string, *gogit.PlainOpenOptions) (*gogit.Repository, error) {
return nil, fmt.Errorf(`unquoted '\' must be followed by new line`)
},
"error translated",
+ gogit.PlainOpenOptions{},
func(r *gogit.Repository, err error) {
assert.Error(t, err)
assert.EqualError(t, err, "error translated")
@@ -135,10 +137,11 @@ func TestSetupRepository(t *testing.T) {
},
{
"A gogit error occurred",
- func(string) (*gogit.Repository, error) {
+ func(string, *gogit.PlainOpenOptions) (*gogit.Repository, error) {
return nil, fmt.Errorf("Error from inside gogit")
},
"",
+ gogit.PlainOpenOptions{},
func(r *gogit.Repository, err error) {
assert.Error(t, err)
assert.EqualError(t, err, "Error from inside gogit")
@@ -146,13 +149,14 @@ func TestSetupRepository(t *testing.T) {
},
{
"Setup done properly",
- func(string) (*gogit.Repository, error) {
+ func(string, *gogit.PlainOpenOptions) (*gogit.Repository, error) {
assert.NoError(t, os.RemoveAll("/tmp/lazygit-test"))
r, err := gogit.PlainInit("/tmp/lazygit-test", false)
assert.NoError(t, err)
return r, nil
},
"",
+ gogit.PlainOpenOptions{},
func(r *gogit.Repository, err error) {
assert.NoError(t, err)
assert.NotNil(t, r)
@@ -163,7 +167,7 @@ func TestSetupRepository(t *testing.T) {
for _, s := range scenarios {
s := s
t.Run(s.testName, func(t *testing.T) {
- s.test(setupRepository(s.openGitRepository, s.errorStr))
+ s.test(setupRepository(s.openGitRepository, s.options, s.errorStr))
})
}
}