| 82 | } |
| 83 | |
| 84 | export function changedFormatFiles(cwd, base, head, local = false) { |
| 85 | revision(cwd, base); |
| 86 | revision(cwd, head); |
| 87 | const names = git( |
| 88 | cwd, |
| 89 | "diff", |
| 90 | "--name-only", |
| 91 | "--no-renames", |
| 92 | "-z", |
| 93 | base, |
| 94 | head, |
| 95 | "--", |
| 96 | ).split("\0"); |
| 97 | if (local) { |
| 98 | names.push( |
| 99 | ...git( |
| 100 | cwd, |
| 101 | "diff", |
| 102 | "--name-only", |
| 103 | "--no-renames", |
| 104 | "-z", |
| 105 | head, |
| 106 | "--", |
| 107 | ).split("\0"), |
| 108 | ); |
| 109 | names.push( |
| 110 | ...git(cwd, "ls-files", "--others", "--exclude-standard", "-z").split( |
| 111 | "\0", |
| 112 | ), |
| 113 | ); |
| 114 | } |
| 115 | // The checkout may be a PR merge commit. Select paths from the planner range, |
| 116 | // then check the actual validation tree; never replace it with head contents. |
| 117 | const present = new Set( |
| 118 | git( |
| 119 | cwd, |
| 120 | "ls-files", |
| 121 | "--cached", |
| 122 | "--others", |
| 123 | "--exclude-standard", |
| 124 | "-z", |
| 125 | ).split("\0"), |
| 126 | ); |
| 127 | return [...new Set(names)] |
| 128 | .filter((name) => { |
| 129 | if (!name || !extensions.has(extname(name)) || !present.has(name)) |
| 130 | return false; |
| 131 | try { |
| 132 | return lstatSync(resolve(cwd, name)).isFile(); |
| 133 | } catch (error) { |
| 134 | if (error.code === "ENOENT" && local) return false; |
| 135 | throw error; |
| 136 | } |
| 137 | }) |
| 138 | .sort(); |
| 139 | } |
| 140 | |
| 141 | export function runFormatter(cwd, paths, mode = Mode.Check) { |