Files
orca/src/main/git/check-ignored-paths.ts
T
0ec3882cb8 Add project Windows runtime selection (#5519)
* Add project Windows runtime selection

* Fix project Windows runtime selection

Co-authored-by: Orca <help@stably.ai>

* fix: preserve WSL shell variables

---------

Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Neil <neil@stably.ai>
2026-06-17 16:08:14 -07:00

47 lines
1.4 KiB
TypeScript

import type { GitRuntimeOptions } from './git-runtime-options'
import { gitOptionsForWorktree } from './git-runtime-options'
import { gitExecFileAsync } from './runner'
const CHECK_IGNORE_CHUNK_SIZE = 100
type GitExecError = Error & { stdout?: string; code?: number | string }
function parseCheckIgnoreOutput(stdout: string): string[] {
return stdout.split(/\r?\n/).filter(Boolean)
}
async function runCheckIgnoreChunk(
worktreePath: string,
relativePaths: string[],
options: GitRuntimeOptions = {}
): Promise<string[]> {
try {
const { stdout } = await gitExecFileAsync(
['-c', 'core.quotePath=false', 'check-ignore', '--', ...relativePaths],
gitOptionsForWorktree(worktreePath, options)
)
return parseCheckIgnoreOutput(stdout)
} catch (error) {
const gitError = error as GitExecError
if (gitError.code === 1) {
return parseCheckIgnoreOutput(gitError.stdout ?? '')
}
throw error
}
}
export async function checkIgnoredPaths(
worktreePath: string,
relativePaths: string[],
options: GitRuntimeOptions = {}
): Promise<string[]> {
const ignored = new Set<string>()
for (let i = 0; i < relativePaths.length; i += CHECK_IGNORE_CHUNK_SIZE) {
const chunk = relativePaths.slice(i, i + CHECK_IGNORE_CHUNK_SIZE)
for (const ignoredPath of await runCheckIgnoreChunk(worktreePath, chunk, options)) {
ignored.add(ignoredPath)
}
}
return Array.from(ignored)
}