diff --git a/lib/git.js b/lib/git.js index b712bb439bed6c4c63360af7f5f2e7c51cfa613d..ee01e78a40569424cc6e7e67d7a56747ef97ac98 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,61 +1,90 @@ "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } +var __awaiter = + (this && this.__awaiter) || + function (thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P + ? value + : new P(function (resolve) { + resolve(value); + }); + } return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); }); -}; + }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.listCommits = exports.parseLogMessage = exports.lastTag = exports.listTagNames = exports.changedPaths = exports.getRootPath = void 0; +exports.listCommits = + exports.parseLogMessage = + exports.lastTag = + exports.listTagNames = + exports.changedPaths = + exports.getRootPath = + void 0; const execa = require("execa"); function getRootPath() { - const cwd = process.cwd(); - return execa.sync("git", ["rev-parse", "--show-toplevel"], { cwd }).stdout; + const cwd = process.cwd(); + return execa.sync("git", ["rev-parse", "--show-toplevel"], { cwd }).stdout; } exports.getRootPath = getRootPath; function changedPaths(sha) { - return __awaiter(this, void 0, void 0, function* () { - const result = yield execa("git", ["show", "-m", "--name-only", "--pretty=format:", "--first-parent", sha]); - return result.stdout.split("\n"); - }); + return __awaiter(this, void 0, void 0, function* () { + const result = yield execa("git", ["show", "-m", "--name-only", "--pretty=format:", "--first-parent", sha]); + return result.stdout.split("\n"); + }); } exports.changedPaths = changedPaths; function listTagNames() { - return execa.sync("git", ["tag"]).stdout.split("\n").filter(Boolean); + return execa.sync("git", ["tag"]).stdout.split("\n").filter(Boolean); } exports.listTagNames = listTagNames; function lastTag() { - return execa.sync("git", ["describe", "--abbrev=0", "--tags"]).stdout; + let ref = execa.sync("git", ["rev-list", "--tags", "--max-count=1"]).stdout; + return execa.sync("git", ["describe", "--tags", ref]).stdout; } exports.lastTag = lastTag; function parseLogMessage(commit) { - const parts = commit.match(/hash<(.+)> ref<(.*)> message<(.*)> date<(.*)>/) || []; - if (!parts || parts.length === 0) { - return null; - } - return { - sha: parts[1], - refName: parts[2], - summary: parts[3], - date: parts[4], - }; + const parts = commit.match(/hash<(.+)> ref<(.*)> message<(.*)> date<(.*)>/) || []; + if (!parts || parts.length === 0) { + return null; + } + return { + sha: parts[1], + refName: parts[2], + summary: parts[3], + date: parts[4], + }; } exports.parseLogMessage = parseLogMessage; function listCommits(from, to = "") { - return execa - .sync("git", [ - "log", - "--oneline", - "--pretty=hash<%h> ref<%D> message<%s> date<%cd>", - "--date=short", - `${from}..${to}`, + return execa + .sync("git", [ + "log", + "--oneline", + "--pretty=hash<%h> ref<%D> message<%s> date<%cd>", + "--date=short", + `${from}..${to}`, ]) - .stdout.split("\n") - .filter(Boolean) - .map(parseLogMessage) - .filter(Boolean); + .stdout.split("\n") + .filter(Boolean) + .map(parseLogMessage) + .filter(Boolean); } exports.listCommits = listCommits;