diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
| commit | 76cb9c2a39d477a64824a985ade40507e3bbade1 (patch) | |
| tree | 41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/vitest/dist/chunks/git.Bm2pzPAa.js | |
| parent | 819a39a21ac992b1393244a4c283bbb125208c69 (diff) | |
| download | neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2 neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip | |
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/vitest/dist/chunks/git.Bm2pzPAa.js')
| -rw-r--r-- | vanilla/node_modules/vitest/dist/chunks/git.Bm2pzPAa.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vanilla/node_modules/vitest/dist/chunks/git.Bm2pzPAa.js b/vanilla/node_modules/vitest/dist/chunks/git.Bm2pzPAa.js new file mode 100644 index 0000000..cc3c0a1 --- /dev/null +++ b/vanilla/node_modules/vitest/dist/chunks/git.Bm2pzPAa.js @@ -0,0 +1,71 @@ +import { resolve } from 'pathe'; +import { x } from 'tinyexec'; + +class VitestGit { + root; + constructor(cwd) { + this.cwd = cwd; + } + async resolveFilesWithGitCommand(args) { + let result; + try { + result = await x("git", args, { nodeOptions: { cwd: this.root } }); + } catch (e) { + e.message = e.stderr; + throw e; + } + return result.stdout.split("\n").filter((s) => s !== "").map((changedPath) => resolve(this.root, changedPath)); + } + async findChangedFiles(options) { + const root = await this.getRoot(this.cwd); + if (!root) return null; + this.root = root; + const changedSince = options.changedSince; + if (typeof changedSince === "string") { + const [committed, staged, unstaged] = await Promise.all([ + this.getFilesSince(changedSince), + this.getStagedFiles(), + this.getUnstagedFiles() + ]); + return [ + ...committed, + ...staged, + ...unstaged + ]; + } + const [staged, unstaged] = await Promise.all([this.getStagedFiles(), this.getUnstagedFiles()]); + return [...staged, ...unstaged]; + } + getFilesSince(hash) { + return this.resolveFilesWithGitCommand([ + "diff", + "--name-only", + `${hash}...HEAD` + ]); + } + getStagedFiles() { + return this.resolveFilesWithGitCommand([ + "diff", + "--cached", + "--name-only" + ]); + } + getUnstagedFiles() { + return this.resolveFilesWithGitCommand([ + "ls-files", + "--other", + "--modified", + "--exclude-standard" + ]); + } + async getRoot(cwd) { + const args = ["rev-parse", "--show-cdup"]; + try { + return resolve(cwd, (await x("git", args, { nodeOptions: { cwd } })).stdout.trim()); + } catch { + return null; + } + } +} + +export { VitestGit }; |
