1 | ;
|
2 |
|
3 | const log = require("npmlog");
|
4 | const childProcess = require("@lerna/child-process");
|
5 |
|
6 | module.exports.gitPush = gitPush;
|
7 |
|
8 | /**
|
9 | * @param {string} remote
|
10 | * @param {string} branch
|
11 | * @param {import("@lerna/child-process").ExecOpts} opts
|
12 | */
|
13 | function gitPush(remote, branch, opts) {
|
14 | log.silly("gitPush", remote, branch);
|
15 |
|
16 | return childProcess
|
17 | .exec("git", ["push", "--follow-tags", "--no-verify", "--atomic", remote, branch], opts)
|
18 | .catch((error) => {
|
19 | // @see https://github.com/sindresorhus/execa/blob/v1.0.0/index.js#L159-L179
|
20 | // the error message _should_ be on stderr except when GIT_REDIRECT_STDERR has been configured to redirect
|
21 | // to stdout. More details in https://git-scm.com/docs/git#Documentation/git.txt-codeGITREDIRECTSTDERRcode
|
22 | if (
|
23 | /atomic/.test(error.stderr) ||
|
24 | (process.env.GIT_REDIRECT_STDERR === "2>&1" && /atomic/.test(error.stdout))
|
25 | ) {
|
26 | // --atomic is only supported in git >=2.4.0, which some crusty CI environments deem unnecessary to upgrade.
|
27 | // so let's try again without attempting to pass an option that is almost 5 years old as of this writing...
|
28 | log.warn("gitPush", error.stderr);
|
29 | log.info("gitPush", "--atomic failed, attempting non-atomic push");
|
30 |
|
31 | return childProcess.exec("git", ["push", "--follow-tags", "--no-verify", remote, branch], opts);
|
32 | }
|
33 |
|
34 | // ensure unexpected errors still break chain
|
35 | throw error;
|
36 | });
|
37 | }
|