UNPKG

@netlify/git-utils

Version:

Utility for dealing with modified, created, deleted files since a git commit

19 lines (18 loc) 678 B
import { git } from './exec.js'; // Returns the number of lines of code added, removed or modified since the // `base` commit export const getLinesOfCode = function (base, head, cwd) { const stdout = git(['diff', '--shortstat', `${base}...${head}`], cwd); const insertions = parseStdout(stdout, INSERTION_REGEXP); const deletions = parseStdout(stdout, DELETION_REGEXP); return insertions + deletions; }; const parseStdout = function (stdout, regexp) { const result = regexp.exec(stdout); if (result === null) { return 0; } return Number(result[1]); }; const INSERTION_REGEXP = /(\d+) insertion/; const DELETION_REGEXP = /(\d+) deletion/;