UNPKG

986 BJavaScriptView Raw
1"use strict";
2
3const { EOL } = require("os");
4const log = require("npmlog");
5const tempWrite = require("temp-write");
6const childProcess = require("@lerna/child-process");
7
8module.exports.gitCommit = gitCommit;
9
10/**
11 * @param {string} message
12 * @param {{ amend: boolean; commitHooks: boolean; signGitCommit: boolean; }} gitOpts
13 * @param {import("@lerna/child-process").ExecOpts} opts
14 */
15function gitCommit(message, { amend, commitHooks, signGitCommit }, opts) {
16 log.silly("gitCommit", message);
17 const args = ["commit"];
18
19 if (commitHooks === false) {
20 args.push("--no-verify");
21 }
22
23 if (signGitCommit) {
24 args.push("--gpg-sign");
25 }
26
27 if (amend) {
28 args.push("--amend", "--no-edit");
29 } else if (message.indexOf(EOL) > -1) {
30 // Use tempfile to allow multi\nline strings.
31 args.push("-F", tempWrite.sync(message, "lerna-commit.txt"));
32 } else {
33 args.push("-m", message);
34 }
35
36 log.verbose("git", args);
37 return childProcess.exec("git", args, opts);
38}