UNPKG

765 BJavaScriptView Raw
1"use strict";
2
3const log = require("npmlog");
4const path = require("path");
5const slash = require("slash");
6const childProcess = require("@lerna/child-process");
7
8module.exports.gitAdd = gitAdd;
9
10/**
11 * @param {string[]} changedFiles
12 * @param {{ granularPathspec: boolean; }} gitOpts
13 * @param {import("@lerna/child-process").ExecOpts} execOpts
14 */
15function gitAdd(changedFiles, gitOpts, execOpts) {
16 // granular pathspecs should be relative to the git root, but that isn't necessarily where lerna lives
17 const files = gitOpts.granularPathspec
18 ? changedFiles.map((file) => slash(path.relative(execOpts.cwd, path.resolve(execOpts.cwd, file))))
19 : ".";
20
21 log.silly("gitAdd", files);
22
23 return childProcess.exec("git", ["add", "--", ...files], execOpts);
24}