Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions pkg/sources/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,17 @@ func normalizeFileURI(uri *url.URL) (*url.URL, error) {
return nil, fmt.Errorf("failed to resolve absolute path for %q: %w", rawPath, err)
}

// Convert to forward slashes (for Windows compatibility)
normalizedPath := filepath.ToSlash(absPath)

// Ensure path starts with / for proper file:/// URI format
if !strings.HasPrefix(normalizedPath, "/") {
normalizedPath = "/" + normalizedPath
}

normalizedURI := &url.URL{
Scheme: "file",
Path: absPath,
Path: normalizedPath,
}

return normalizedURI, nil
Expand Down Expand Up @@ -1341,7 +1349,17 @@ func PrepareRepo(ctx context.Context, uriString, clonePath string, trustLocalGit
if !isRepoBare(path) {
// Only copy index file for non-bare clones from working directory repos. This is used to see staged changes.
// Note: To scan **un**staged changes in the future, we'd need to set core.worktree to the original path.
originalIndexPath := filepath.Join(strings.TrimPrefix(normalizedURI.String(), "file://"), gitDirName, "index")

uriPath := strings.TrimPrefix(normalizedURI.String(), "file://")

// on windows we get "/C:/path". We need to remove the leading slash.
// on unix/macintosh, we get "/path" which needs the leading slash preserved.
if len(uriPath) >= 3 && uriPath[0] == '/' && uriPath[2] == ':' {
uriPath = strings.TrimPrefix(uriPath, "/")
}

originalIndexPath := filepath.Join(uriPath, gitDirName, "index")

clonedIndexPath := filepath.Join(path, gitDirName, "index")

indexData, err := os.ReadFile(originalIndexPath)
Expand Down
Loading