MCPcopy Create free account
hub / github.com/LegacyCodeHQ/clarity-cli / getRelativePath

Function getRelativePath

vcs/git/git_commit_content_reader.go:18–46  ·  view source on GitHub ↗

GetRelativePath converts an absolute file path to a path relative to the repository root

(absPath, repoPath string)

Source from the content-addressed store, hash-verified

16
17// GetRelativePath converts an absolute file path to a path relative to the repository root
18func getRelativePath(absPath, repoPath string) string {
19 // Get absolute repository path
20 absRepoPath, err := filepath.Abs(repoPath)
21 if err != nil {
22 // If we can't get absolute path, try relative path as-is
23 relPath, err := filepath.Rel(repoPath, absPath)
24 if err != nil {
25 // Fallback to using the absolute path
26 return absPath
27 }
28 return relPath
29 }
30
31 // Normalize symlinks for temp directories like /var -> /private/var.
32 resolvedRepoPath := resolveSymlinks(absRepoPath)
33 resolvedAbsPath := resolveSymlinks(absPath)
34 if relPath, err := filepath.Rel(resolvedRepoPath, resolvedAbsPath); err == nil {
35 return relPath
36 }
37
38 // Get path relative to repository root
39 relPath, err := filepath.Rel(absRepoPath, absPath)
40 if err != nil {
41 // Fallback to using the absolute path
42 return absPath
43 }
44
45 return relPath
46}
47
48func resolveSymlinks(path string) string {
49 resolved, err := filepath.EvalSymlinks(path)

Callers 1

GitCommitContentReaderFunction · 0.85

Calls 1

resolveSymlinksFunction · 0.70

Tested by

no test coverage detected