Skip to content

Commit 1ea63af

Browse files
committed
path normalization for cross-platform
1 parent 8dcddb4 commit 1ea63af

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/core/ignore/GitIgnoreController.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export class GitIgnoreController extends BaseIgnoreController {
5151

5252
// Check each location and load if it exists
5353
for (const gitignorePath of commonGitignorePaths) {
54-
if (await fileExistsAtPath(gitignorePath)) {
54+
const exists = await fileExistsAtPath(gitignorePath)
55+
56+
if (exists) {
5557
this.gitignoreFiles.push(gitignorePath)
5658
await this.loadGitignoreFile(gitignorePath)
5759
}
@@ -120,24 +122,29 @@ export class GitIgnoreController extends BaseIgnoreController {
120122
const relativeDir = path.relative(this.cwd, path.dirname(gitignoreFile))
121123

122124
if (relativeDir) {
123-
// For nested .gitignore files, prefix patterns with the relative directory
125+
// For nested .gitignore files, we need to create patterns that match files within that directory
124126
const lines = content.split("\n").filter((line) => line.trim() && !line.startsWith("#"))
125127
const adjustedPatterns = lines.map((pattern) => {
126128
const trimmed = pattern.trim()
129+
// Convert Windows paths to POSIX for consistent pattern matching
130+
const normalizedRelativeDir = relativeDir.split(path.sep).join("/")
131+
127132
if (trimmed.startsWith("/")) {
128133
// Absolute patterns (starting with /) are relative to the .gitignore location
129-
return path.posix.join(relativeDir, trimmed.slice(1))
134+
return normalizedRelativeDir + trimmed
130135
} else if (trimmed.startsWith("!")) {
131136
// Negation patterns
132137
const negatedPattern = trimmed.slice(1)
133138
if (negatedPattern.startsWith("/")) {
134-
return "!" + path.posix.join(relativeDir, negatedPattern.slice(1))
139+
return "!" + normalizedRelativeDir + negatedPattern
135140
} else {
136-
return "!" + path.posix.join(relativeDir, "**", negatedPattern)
141+
// For relative negation patterns, match in the directory and subdirectories
142+
return "!" + normalizedRelativeDir + "/" + negatedPattern
137143
}
138144
} else {
139-
// Relative patterns apply to the directory and all subdirectories
140-
return path.posix.join(relativeDir, "**", trimmed)
145+
// Relative patterns - match files directly in the directory
146+
// This handles cases like "*.tmp" in src/.gitignore matching "src/temp.tmp"
147+
return normalizedRelativeDir + "/" + trimmed
141148
}
142149
})
143150

0 commit comments

Comments
 (0)