diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-27 19:39:13 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 17:48:21 +1000 |
commit | 72a31aed769e5d3d04d067cae4e13d8b9b42218e (patch) | |
tree | ddfb629139f43760a4ee7a36f424cc26f81afa07 /pkg/commands | |
parent | 59e117738dd708fa6531c085b23107da5546c40f (diff) |
support opening lazygit in a symlinked submodule
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 41133424d..1c27b8642 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -66,10 +66,33 @@ func navigateToRepoRootDirectory(stat func(string) (os.FileInfo, error), chdir f } } +// resolvePath takes a path containing a symlink and returns the true path +func resolvePath(path string) (string, error) { + l, err := os.Lstat(path) + if err != nil { + return "", err + } + + if l.Mode()&os.ModeSymlink == 0 { + return path, nil + } + + return filepath.EvalSymlinks(path) +} + func setupRepository(openGitRepository func(string) (*gogit.Repository, error), sLocalize func(string) string) (*gogit.Repository, error) { - path := env.GetGitDirEnv() - if path == "" { - path = "." + unresolvedPath := env.GetGitDirEnv() + if unresolvedPath == "" { + var err error + unresolvedPath, err = os.Getwd() + if err != nil { + return nil, err + } + } + + path, err := resolvePath(unresolvedPath) + if err != nil { + return nil, err } repository, err := openGitRepository(path) |