question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

git --atomic fallback causes non-zero exit code

See original GitHub issue

Expected Behavior

Commands triggering git push should return exit code zero hosts running git <2.4.0, ie Azure DevOps 😦

Current Behavior

Commands using git push without --atomic support always return the exit code of the atomic request attempt on success.

Possible Solution

This appears to be because childProcess sets process.exitCode on error. https://github.com/lerna/lerna/blob/6cb8ab2d4af7ce25c812e8fb05cd04650105705f/core/child-process/index.js#L138

When the non-atomic fallback is triggered the exit code from the first attempt remains.

Resetting the exit code in the catch on atomic errors does fix this issue… but I’m not familiar enough to gauge the risk of race condition when doing so.

https://github.com/lerna/lerna/blob/6cb8ab2d4af7ce25c812e8fb05cd04650105705f/commands/version/lib/git-push.js#L26

diff --git a/commands/version/lib/git-push.js b/commands/version/lib/git-push.js
index 35936398..a7f0de1e 100644
--- a/commands/version/lib/git-push.js
+++ b/commands/version/lib/git-push.js
@@ -25,6 +25,8 @@ function gitPush(remote, branch, opts) {
       ) {
         // --atomic is only supported in git >=2.4.0, which some crusty CI environments deem unnecessary to upgrade.
         // so let's try again without attempting to pass an option that is almost 5 years old as of this writing...
+        // reset process.exitCode set by childProcess on atomic failure
+        process.exitCode = 0;
         log.warn("gitPush", error.stderr);
         log.info("gitPush", "--atomic failed, attempting non-atomic push");
 

Steps to Reproduce (for bugs)

  1. Remote host using git <2.4.0
  2. lerna publish patch -y
  3. echo $?

Exit code will be non-zero even on command success.

Your Environment

Executable Version
lerna --version 4.0.0
npm --version 7.3.0
yarn --version 1.22.10
node --version 15.5.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

2reactions
kkazalacommented, Jul 20, 2021

@miluxmilux I had the same issue. I use lerna version --no-push and git push --follow-tags origin HEAD:$(Build.SourceBranch) instead. At least I don’t get false exitcode 1 😃

0reactions
MrStLouiscommented, Feb 11, 2022

Identical issue here, worrying how stale this issue is

Read more comments on GitHub >

github_iconTop Results From Across the Web

git-config Documentation - Git
This command will fail with non-zero status upon error. Some exit codes are: The section or key is invalid (ret=1),. no section or...
Read more >
git push --atomic - Not failing - Stack Overflow
It seems from the diff here that there needs to be something on the remote server that will accept the atomic flag as...
Read more >
modesetting: Allow Present flips with mismatched stride on atomic ...
A legacy non-atomic driver will return a non-zero error code, either -EINVAL for early atomic Linux versions 4.0 - 4.19 (or for non-atomic...
Read more >
git-config(1) - FreeBSD
This command will fail with non-zero status upon error. ... is used to store a per-user configuration as fallback values for the .git/config...
Read more >
git-config command man page - git-core-doc - ManKier
This command will fail with non-zero status upon error. ... is used to store a per-user configuration as fallback values for the .git/config...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found