Skip to content

Commit

Permalink
fix: resolve symlinks for startup and git
Browse files Browse the repository at this point in the history
  • Loading branch information
smitropoulos committed Dec 2, 2023
1 parent 1555503 commit cc62bbc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/app/entry_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
log.Fatal(err)
}

absRepoPath, err = filepath.EvalSymlinks(cliArgs.RepoPath)
if err != nil {
log.Fatal(err)
}

if isRepo, err := isDirectoryAGitRepository(absRepoPath); err != nil || !isRepo {
log.Fatal(absRepoPath + " is not a valid git repository.")
}
Expand Down
47 changes: 42 additions & 5 deletions pkg/commands/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,21 @@ func NewGitCommand(
gitConfig git_config.IGitConfig,
) (*GitCommand, error) {
currentPath, err := os.Getwd()

if err != nil {
return nil, utils.WrapError(err)
}

// Check if the current path is a symlink and walk it
absRepoPath, err := filepath.EvalSymlinks(currentPath)
if err != nil {
return nil, utils.WrapError(err)
}

if absRepoPath != currentPath {
currentPath = absRepoPath
}

// converting to forward slashes for the sake of windows (which uses backwards slashes). We want everything
// to have forward slashes internally
currentPath = filepath.ToSlash(currentPath)
Expand Down Expand Up @@ -136,7 +147,15 @@ func NewGitCommandAux(
// common ones are: cmn, osCommand, dotGitDir, configCommands
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo)

gitCommon := git_commands.NewGitCommon(cmn, version, cmd, osCommand, repoPaths, repo, configCommands)
gitCommon := git_commands.NewGitCommon(
cmn,
version,
cmd,
osCommand,
repoPaths,
repo,
configCommands,
)

fileLoader := git_commands.NewFileLoader(gitCommon, cmd, configCommands)
statusCommands := git_commands.NewStatusCommands(gitCommon)
Expand All @@ -150,18 +169,34 @@ func NewGitCommandAux(
diffCommands := git_commands.NewDiffCommands(gitCommon)
fileCommands := git_commands.NewFileCommands(gitCommon)
submoduleCommands := git_commands.NewSubmoduleCommands(gitCommon)
workingTreeCommands := git_commands.NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader)
workingTreeCommands := git_commands.NewWorkingTreeCommands(
gitCommon,
submoduleCommands,
fileLoader,
)
rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands)
stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
patchBuilder := patch.NewPatchBuilder(cmn.Log,
func(from string, to string, reverse bool, filename string, plain bool) (string, error) {
return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, plain)
})
patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchBuilder)
patchCommands := git_commands.NewPatchCommands(
gitCommon,
rebaseCommands,
commitCommands,
statusCommands,
stashCommands,
patchBuilder,
)
bisectCommands := git_commands.NewBisectCommands(gitCommon)
worktreeCommands := git_commands.NewWorktreeCommands(gitCommon)

branchLoader := git_commands.NewBranchLoader(cmn, cmd, branchCommands.CurrentBranchInfo, configCommands)
branchLoader := git_commands.NewBranchLoader(
cmn,
cmd,
branchCommands.CurrentBranchInfo,
configCommands,
)
commitFileLoader := git_commands.NewCommitFileLoader(cmn, cmd)
commitLoader := git_commands.NewCommitLoader(cmn, cmd, statusCommands.RebaseMode, gitCommon)
reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd)
Expand Down Expand Up @@ -232,5 +267,7 @@ func findWorktreeRoot(fs afero.Fs, currentPath string) (string, error) {
}

func VerifyInGitRepo(osCommand *oscommands.OSCommand) error {
return osCommand.Cmd.New(git_commands.NewGitCmd("rev-parse").Arg("--git-dir").ToArgv()).DontLog().Run()
return osCommand.Cmd.New(git_commands.NewGitCmd("rev-parse").Arg("--git-dir").ToArgv()).
DontLog().
Run()
}

0 comments on commit cc62bbc

Please sign in to comment.