MCPcopy Create free account
hub / github.com/github/gh-aw / getRepositoryRelativePath

Function getRepositoryRelativePath

pkg/cli/helpers.go:31–57  ·  view source on GitHub ↗

getRepositoryRelativePath converts an absolute file path to a repository-relative path This ensures stable workflow identifiers regardless of where the repository is cloned

(absPath string)

Source from the content-addressed store, hash-verified

29// getRepositoryRelativePath converts an absolute file path to a repository-relative path
30// This ensures stable workflow identifiers regardless of where the repository is cloned
31func getRepositoryRelativePath(absPath string) (string, error) {
32 // Get the repository root for the specific file
33 repoRoot, err := findGitRootForPath(absPath)
34 if err != nil {
35 // If we can't get the repo root, just use the basename as fallback
36 helpersLog.Printf("Warning: could not get repository root for %s: %v, using basename", absPath, err)
37 return filepath.Base(absPath), nil
38 }
39
40 // Convert both paths to absolute to ensure they can be compared
41 absPath, err = filepath.Abs(absPath)
42 if err != nil {
43 return "", fmt.Errorf("failed to get absolute path: %w", err)
44 }
45
46 // Get the relative path from repo root
47 relPath, err := filepath.Rel(repoRoot, absPath)
48 if err != nil {
49 return "", fmt.Errorf("failed to get relative path: %w", err)
50 }
51
52 // Normalize path separators to forward slashes for consistency across platforms
53 // This ensures the same hash value on Windows, Linux, and macOS
54 relPath = filepath.ToSlash(relPath)
55
56 return relPath, nil
57}
58
59// getAbsoluteWorkflowDir converts a relative workflow dir to absolute path
60func getAbsoluteWorkflowDir(workflowDir string, gitRoot string) string {

Calls 3

findGitRootForPathFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45