findGitRootForPath finds the root directory of the git repository containing the specified path
(path string)
| 26 | |
| 27 | // findGitRootForPath finds the root directory of the git repository containing the specified path |
| 28 | func findGitRootForPath(path string) (string, error) { |
| 29 | gitLog.Printf("Finding git root for path: %s", path) |
| 30 | |
| 31 | // Get absolute path first |
| 32 | absPath, err := filepath.Abs(path) |
| 33 | if err != nil { |
| 34 | return "", fmt.Errorf("failed to get absolute path: %w", err) |
| 35 | } |
| 36 | |
| 37 | // Validate the absolute path |
| 38 | absPath, err = fileutil.ValidateAbsolutePath(absPath) |
| 39 | if err != nil { |
| 40 | return "", fmt.Errorf("invalid path: %w", err) |
| 41 | } |
| 42 | |
| 43 | // Use the directory containing the file |
| 44 | dir := filepath.Dir(absPath) |
| 45 | |
| 46 | // Find git root using filesystem traversal from the file's directory |
| 47 | gitRoot, err := gitutil.FindGitRootFrom(dir) |
| 48 | if err != nil { |
| 49 | return "", fmt.Errorf("failed to get repository root for path %s: %w", path, err) |
| 50 | } |
| 51 | gitLog.Printf("Found git root for path: %s", gitRoot) |
| 52 | return gitRoot, nil |
| 53 | } |
| 54 | |
| 55 | // parseGitHubRepoSlugFromURL extracts owner/repo from a GitHub URL |
| 56 | // Supports HTTPS (https://github.com/owner/repo), SCP-style SSH (git@github.com:owner/repo), |