Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --atomic when running git push in lerna version #2392

Closed
weareoutman opened this issue Dec 26, 2019 · 7 comments · Fixed by #2393
Closed

Use --atomic when running git push in lerna version #2392

weareoutman opened this issue Dec 26, 2019 · 7 comments · Fixed by #2393

Comments

@weareoutman
Copy link
Contributor

weareoutman commented Dec 26, 2019

Currently, lerna version will push repository by git push --follow-tags, which defaults to non-atomic, that could cause problems in certain situations.

E.g., when somebody else pushed new commits to origin/master during one running lerna version.

Expected Behavior

Do an atomic pushing when running lerna version.

Current Behavior

Tags are pushed, but master is rejected. These orphan tags need to be manually deleted, to avoid conflicts in future.

Possible Solution

Use git push --follow-tags --atomic (which is supported since git v2.4.0).

Steps to Reproduce (for bugs)

  1. Fetch and pull newest master.
  2. Run lerna version.
  3. Somebody else pushed new commits to master.
  4. Check yes in the prompt of lerna version.
  5. Result: changes made and tags pushed, but master rejected.
  6. Delete all these orphan tags.
lerna.json

{
  "packages": [
    "libs/*"
  ],
  "version": "independent",
  "npmClient": "yarn",
  "stream": true,
  "useWorkspaces": true,
  "conventionalCommits": true,
  "command": {
    "publish": {
      "npmClient": "npm",
      "allowBranch": "master",
      "verifyAccess": false,
      "message": "chore(release): publish",
      "registry": "https://registry.npm.easyops.local"
    }
  }
}

Context

Your Environment

Executable Version
lerna --version 3.13.1
npm --version 6.12.0
yarn --version 1.17.3
node --version 12.13.0
OS Version
macOS Catalina 10.15.1
@evocateur
Copy link
Member

Yep, sounds reasonable to me.

@weareoutman
Copy link
Contributor Author

Sorry for the troubles caused by the PR #2393 , and thanks for the fixes @evocateur .

But, the latest fix 6f0e2bb#diff-4a3a3aa992c599b130c66225bed2e8f4R16 seems to reintroduced the original issue here . It will try a non-atomic pushing after a failed atomic pushing (which is not caused by older git but by rejected by updated origin). I can give a detailed log later.

@evocateur
Copy link
Member

@weareoutman Do you know if there is a specific non-zero exit code that can distinguish this atomic rejection from unsupported atomic?

@weareoutman
Copy link
Contributor Author

@evocateur I can't find official docs about exit code list of git. But i tried on my Mac.

When meet atomic rejection, exit code is 1:

wangshenwei@wangshenweis-MacBook-Pro my-repo % git push --follow-tags --atomic --no-verify origin master
error: atomic push failed for ref refs/heads/master. status: 5

fatal: the remote end hung up unexpectedly\nTo git.easyops.local:weareoutman/my-repo.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@git.easyops.local:weareoutman/my-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
wangshenwei@wangshenweis-MacBook-Pro my-repo % echo $?
1

When meet unsupported options, exit code is 129:

wangshenwei@wangshenweis-MacBook-Pro my-repo % git push --follow-tags --atomic --no-verify --not-existed-arg origin master
error: unknown option `not-existed-arg'
usage: git push [<options>] [<repository> [<refspec>...]]

~~blabla

wangshenwei@wangshenweis-MacBook-Pro my-repo % echo $?
129

However, I can't ensure other versions of git on other platforms work as the same. Maybe we can try like this:

if (/atomic/.test(error.stderr) && !/atomic push failed/.test(error.stderr)) {
  // Now we say the git client does not support `--atomic`.
}

@AliMD
Copy link

AliMD commented Jun 21, 2021

same issue in asure devops

@aleguern
Copy link

aleguern commented Jul 6, 2022

Same on AWS code suite

@aleguern
Copy link

aleguern commented Jul 7, 2022

I fixed it using --no-push and pushing manually with the same command used in the library.

"scripts": {
   "publish": "lerna publish --no-push",
   "postversion":"git push --follow-tags --no-verify origin master"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants