From f4c24e4429daa1c012d26667116a8d9f3742d7cd Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Mon, 18 Nov 2024 11:10:40 +0300 Subject: [PATCH] fix: use absolute paths when cloning remotes (#873) --- internal/git/repository.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/git/repository.go b/internal/git/repository.go index 5086a2b4..506563f1 100644 --- a/internal/git/repository.go +++ b/internal/git/repository.go @@ -26,10 +26,10 @@ var ( cmdStagedFiles = []string{"git", "diff", "--name-only", "--cached", "--diff-filter=ACMR"} cmdStatusShort = []string{"git", "status", "--short", "--porcelain"} cmdListStash = []string{"git", "stash", "list"} - cmdRootPath = []string{"git", "rev-parse", "--show-toplevel"} - cmdHooksPath = []string{"git", "rev-parse", "--git-path", "hooks"} - cmdInfoPath = []string{"git", "rev-parse", "--git-path", "info"} - cmdGitPath = []string{"git", "rev-parse", "--git-dir"} + cmdRootPath = []string{"git", "rev-parse", "--path-format=absolute", "--show-toplevel"} + cmdHooksPath = []string{"git", "rev-parse", "--path-format=absolute", "--git-path", "hooks"} + cmdInfoPath = []string{"git", "rev-parse", "--path-format=absolute", "--git-path", "info"} + cmdGitPath = []string{"git", "rev-parse", "--path-format=absolute", "--git-dir"} cmdAllFiles = []string{"git", "ls-files", "--cached"} cmdCreateStash = []string{"git", "stash", "create"} cmdStageFiles = []string{"git", "add"} @@ -62,15 +62,13 @@ func NewRepository(fs afero.Fs, git *CommandExecutor) (*Repository, error) { if err != nil { return nil, err } - if exists, _ := afero.DirExists(fs, filepath.Join(rootPath, hooksPath)); exists { - hooksPath = filepath.Join(rootPath, hooksPath) - } infoPath, err := git.Cmd(cmdInfoPath) if err != nil { return nil, err } infoPath = filepath.Clean(infoPath) + if exists, _ := afero.DirExists(fs, infoPath); !exists { err = fs.Mkdir(infoPath, infoDirMode) if err != nil { @@ -82,9 +80,6 @@ func NewRepository(fs afero.Fs, git *CommandExecutor) (*Repository, error) { if err != nil { return nil, err } - if !filepath.IsAbs(gitPath) { - gitPath = filepath.Join(rootPath, gitPath) - } emptyTreeSHA, err := git.Cmd(cmdEmptyTreeSHA) if err != nil {