MCPcopy Create free account
hub / github.com/delinoio/oss / changedFormatFiles

Function changedFormatFiles

scripts/ci/format-changed.mjs:84–139  ·  view source on GitHub ↗
(cwd, base, head, local = false)

Source from the content-addressed store, hash-verified

82}
83
84export 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
141export function runFormatter(cwd, paths, mode = Mode.Check) {

Callers 2

mainFunction · 0.85

Calls 5

hasMethod · 0.80
revisionFunction · 0.70
gitFunction · 0.70
resolveFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected