| 306 | } |
| 307 | |
| 308 | function topmostUntrackedDir(path: string, trackedDirs: Set<string>): string { |
| 309 | // Walk from the file up to the root; the first dir off the root |
| 310 | // that isn't tracked is the top of the untracked subtree. |
| 311 | const segments = path.split("/"); |
| 312 | let prefix = ""; |
| 313 | for (let i = 0; i < segments.length - 1; i++) { |
| 314 | prefix = prefix === "" ? segments[i] : `${prefix}/${segments[i]}`; |
| 315 | if (!trackedDirs.has(prefix)) return prefix; |
| 316 | } |
| 317 | return dirname(path); |
| 318 | } |
| 319 | |
| 320 | function dirname(path: string): string { |
| 321 | const i = path.lastIndexOf("/"); |