MCPcopy Create free account
hub / github.com/EndBug/add-and-commit / add

Function add

src/main.ts:220–258  ·  view source on GitHub ↗
(ignoreErrors: 'all' | 'pathspec' | 'none' = 'none')

Source from the content-addressed store, hash-verified

218 });
219
220async function add(ignoreErrors: 'all' | 'pathspec' | 'none' = 'none') {
221 const input = getInput('add');
222 if (!input) return [];
223
224 const parsed = parseInputArray(input);
225 const res: (string | void)[] = [];
226
227 for (const args of parsed) {
228 res.push(
229 // Push the result of every git command (which are executed in order) to the array
230 // If any of them fails, the whole function will return a Promise rejection
231 await git
232 .add(matchGitArgs(args), (err, data) =>
233 log(ignoreErrors === 'all' ? null : err, data),
234 )
235 .catch((e: Error) => {
236 // if I should ignore every error, return
237 if (ignoreErrors === 'all') return;
238
239 // if it's a pathspec error...
240 if (
241 e.message.includes('fatal: pathspec') &&
242 e.message.includes('did not match any files')
243 ) {
244 if (ignoreErrors === 'pathspec') return;
245
246 const peh = getInput('pathspec_error_handling'),
247 err = new Error(
248 `Add command did not match any file: git add ${args}`,
249 );
250 if (peh === 'exitImmediately') throw err;
251 if (peh === 'exitAtEnd') exitErrors.push(err);
252 } else throw e;
253 }),
254 );
255 }
256
257 return res;
258}
259
260async function remove(
261 ignoreErrors: 'all' | 'pathspec' | 'none' = 'none',

Callers 1

main.tsFile · 0.70

Calls 6

getInputFunction · 0.90
parseInputArrayFunction · 0.90
matchGitArgsFunction · 0.90
logFunction · 0.90
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected