版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

85 righe
2.0 KiB

  1. import { resolve } from 'pathe';
  2. import { e as execa } from './vendor-index.2cbcdd1e.js';
  3. import 'node:buffer';
  4. import 'node:path';
  5. import 'node:child_process';
  6. import 'node:process';
  7. import 'child_process';
  8. import 'path';
  9. import './vendor-_commonjsHelpers.addc3445.js';
  10. import 'fs';
  11. import 'node:url';
  12. import 'node:os';
  13. import 'assert';
  14. import 'events';
  15. import 'buffer';
  16. import 'stream';
  17. import 'util';
  18. class VitestGit {
  19. constructor(cwd) {
  20. this.cwd = cwd;
  21. }
  22. async resolveFilesWithGitCommand(args) {
  23. let result;
  24. try {
  25. result = await execa("git", args, { cwd: this.root });
  26. } catch (e) {
  27. e.message = e.stderr;
  28. throw e;
  29. }
  30. return result.stdout.split("\n").filter((s) => s !== "").map((changedPath) => resolve(this.root, changedPath));
  31. }
  32. async findChangedFiles(options) {
  33. const root = await this.getRoot(this.cwd);
  34. if (!root)
  35. return null;
  36. this.root = root;
  37. const changedSince = options.changedSince;
  38. if (typeof changedSince === "string") {
  39. const [committed, staged2, unstaged2] = await Promise.all([
  40. this.getFilesSince(changedSince),
  41. this.getStagedFiles(),
  42. this.getUnstagedFiles()
  43. ]);
  44. return [...committed, ...staged2, ...unstaged2];
  45. }
  46. const [staged, unstaged] = await Promise.all([
  47. this.getStagedFiles(),
  48. this.getUnstagedFiles()
  49. ]);
  50. return [...staged, ...unstaged];
  51. }
  52. getFilesSince(hash) {
  53. return this.resolveFilesWithGitCommand(
  54. ["diff", "--name-only", `${hash}...HEAD`]
  55. );
  56. }
  57. getStagedFiles() {
  58. return this.resolveFilesWithGitCommand(
  59. ["diff", "--cached", "--name-only"]
  60. );
  61. }
  62. getUnstagedFiles() {
  63. return this.resolveFilesWithGitCommand(
  64. [
  65. "ls-files",
  66. "--other",
  67. "--modified",
  68. "--exclude-standard"
  69. ]
  70. );
  71. }
  72. async getRoot(cwd) {
  73. const options = ["rev-parse", "--show-cdup"];
  74. try {
  75. const result = await execa("git", options, { cwd });
  76. return resolve(cwd, result.stdout);
  77. } catch {
  78. return null;
  79. }
  80. }
  81. }
  82. export { VitestGit };