MCPcopy Create free account
hub / github.com/domharrington/node-gitlog / createCommandArguments

Function createCommandArguments

src/index.ts:250–318  ·  view source on GitHub ↗

Run "git log" and return the result as JSON

(options: GitlogOptions<T>)

Source from the content-addressed store, hash-verified

248
249/** Run "git log" and return the result as JSON */
250function createCommandArguments<
251 T extends CommitField | DefaultField = DefaultField
252>(options: GitlogOptions<T>) {
253 // Start constructing command
254 let command: string[] = ["log", "-l0"];
255
256 if (options.findCopiesHarder) {
257 command.push("--find-copies-harder");
258 }
259
260 if (options.all) {
261 command.push("--all");
262 }
263
264 if (options.includeMergeCommitFiles) {
265 command.push("-m");
266 }
267
268 if (options.follow) {
269 command.push("--follow");
270 }
271
272 command.push(`-n ${options.number}`);
273
274 command = addOptionalArguments(command, options);
275
276 // Start of custom format
277 let prettyArgument: string = "--pretty=@begin@";
278
279 // Iterating through the fields and adding them to the custom format
280 if (options.fields) {
281 options.fields.forEach((field) => {
282 if (!fieldMap[field] && !notOptFields.includes(field as any)) {
283 throw new Error(`Unknown field: ${field}`);
284 }
285
286 prettyArgument += delimiter + fieldMap[field];
287 });
288 }
289
290 // Close custom format
291 prettyArgument += "@end@";
292 command.push(prettyArgument);
293
294 // Append branch (revision range) if specified
295 if (options.branch) {
296 command.push(options.branch);
297 }
298
299 // File and file status
300 if (options.nameStatus && !options.fileLineRange) {
301 command.push("--name-status");
302 }
303
304 if (options.fileLineRange) {
305 command.push(
306 `-L ${options.fileLineRange.startLine},${options.fileLineRange.endLine}:${options.fileLineRange.file}`
307 );

Callers 1

gitlogFunction · 0.85

Calls 1

addOptionalArgumentsFunction · 0.85

Tested by

no test coverage detected