You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing two repos failing to import for seemingly different reasons (based on the Lerna error message.) I tried fresh git clones of the repos to rule out any issues with my local clones.
Errored while running ImportCommand.execute
Failed to apply commit 2495e18.
Error: Command failed: git am -3
fatal: sha1 information is lacking or useless (packages/intl-relativeformat/tests/index.js).
error: could not build fake ancestor
Let me know if there's something I should try differently, or if you need more info from me. Since these repos are public you should be able to reproduce the import errors above.
Reacted by André Staltz, Hawken Rives, Matt Karl, Evan Henley, Felipe Ribeiro, Jed Verity, Pedro Duarte, Quintin Knudsen, Danny Martini, Peter Murphy and 8 more
Hi @ericf, just want to let you know that I haven't forgotten about this. I spent some time looking into it, and it actually doesn't look like there's an "easy" solution. The trouble arises from merge commits. When changes are pulled in with merge commits the output of git format-patch is always relative to the topic branch that the commit was originally made on. That's not guaranteed to apply to the target branch it wound up in, though. Only the final state of the topic branch needs to apply cleanly to the branch it's merged into. Intervening commits may conflict. There may even ultimately be conflict resolution in the merge commit itself.
Git itself actually doesn't produce a patch-set that applies in this case. For example, in master of intl-messageformat this fails on the same commit that lerna import does:
$ git format-patch 09b7b91 # generate patches for every commit after the initial commit
$ git reset --hard 09b7b91 # rewind to the initial commit
$ git am 0*.patch # re-play commit history
...
error: patch failed: tests/message.js:27
error: tests/message.js: patch does not apply
Patch failed at 0023 Move `lib/message.js` to `./index.js`.
I'm not sure if there's going to be a solution to this that lets us preserve one-for-one commit history from the external repository. We might wind up needing to squash branches that contain patches that don't apply cleanly. Unless a better solution presents itself before I have a chance to take this on, that's what I'll do.
Reacted by Brian M Hunt
Reacted by Aditya Rao, JimmyLv_吕立青 and Illia Lukianov
I've done some monorepoing at my job with custom bash scripts for some time and decided to use lerna in something I'm working now, but had this same problem.
However, while lerna fails in my current project, my old custom bash script works, so it might be worth taking a look.
It's a different way to rewrite history, it uses filter-branch and actually causes a merge and doesn't alter anything regarding the commit author (which I think is nice). So maybe lerna should do that instead?
Had the same issue with beta30 and beta37. Pretty much every repo has merge commits on master. We don't really care of retaining them, so if lerna could flatten the branch history (essentially making it look like no merges did happen and all the commits originally went straight to master) that would be sufficient for us.
interactive rebase against root seems to be doing exactly that so we do probably have the backup plan, but if lerna automated that that would be great
ADD: A bit of context. Monorepo concept is relatively new and I believe many companies are deciding to use it to consolidate bits of the existing code.
To me the import feature is one of the biggest selling points (we've currently decided to start using lerna for clusters of the related modules).
So I believe smooth import process (fixing the current issue + wokring with the remotes #269) is crucial for the existing projects to migrate to lerna.
Reacted by asharma-r7, Danny Martini, Ian Wright, Andrew Krespanis, Peter Murphy, Benjamin Otto, Mario Ranftl, Sam Marshall, Victor Alloza, Thomas Hunter II and 5 more
I have no idea if this is relevant to anybody else, but a slightly modified form of the function in this stack overflow answer worked great for me. For OS X users, make sure to install and use gnu-sed (brew install gnu-sed was all I had to do, but others may need to update the script to use gsed).
Define this function in a shell script somewhere (I put it in my ~/.bash_profile temporarily b/c I'm lazy and/or stupid):
It'll take a bit to run but when it finishes, your git history should look like you've been committing files under packages/your-repo all along. Everything on GitHub (history, merges, commits, blame, diffs) look to be working.
I haven't tested whether it's possible to pull in upstream changes from the original repo (but I seriously doubt it), so make sure you stop committing to the original one and fully switch over.
I don't have any special understanding of why this works, I likely can't help if it doesn't work for you. When in doubt, do it in a freshly cloned local version of your lerna repo so you can delete it and try again. Good luck!
I agree that git filter-branch is often the best choice for this sort of thing; I also recognize that filter-branch is almost impossible to generalize (in any useful way), and will almost always be a one-off, custom thing.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Activity
jamiebuilds commentedon Jul 11, 2016
cc @gigabo
gigabo commentedon Jul 11, 2016
Thanks for reporting @ericf. I'll see if I can track down what's going wrong.
gigabo commentedon Jul 25, 2016
Hi @ericf, just want to let you know that I haven't forgotten about this. I spent some time looking into it, and it actually doesn't look like there's an "easy" solution. The trouble arises from merge commits. When changes are pulled in with merge commits the output of
git format-patchis always relative to the topic branch that the commit was originally made on. That's not guaranteed to apply to the target branch it wound up in, though. Only the final state of the topic branch needs to apply cleanly to the branch it's merged into. Intervening commits may conflict. There may even ultimately be conflict resolution in the merge commit itself.Git itself actually doesn't produce a patch-set that applies in this case. For example, in master of
intl-messageformatthis fails on the same commit thatlerna importdoes:I'm not sure if there's going to be a solution to this that lets us preserve one-for-one commit history from the external repository. We might wind up needing to squash branches that contain patches that don't apply cleanly. Unless a better solution presents itself before I have a chance to take this on, that's what I'll do.
ericf commentedon Jul 25, 2016
@gigabo thanks for digging deep into this one — definitely a messy Git situation.
I think that seems fine me to as a strategy to employ when there's an issue in a merge commit.
jamiebuilds commentedon Jul 25, 2016
Rather than errorring out can we be interactive and allow the user to take an action on a commit?
Even if that means retrying to import over and over, but each time something doesn't work let the user do something that fixes it.
Just throwing ideas out there
felipernb commentedon Oct 21, 2016
I've done some monorepoing at my job with custom bash scripts for some time and decided to use lerna in something I'm working now, but had this same problem.
However, while lerna fails in my current project, my old custom bash script works, so it might be worth taking a look.
Here it is: https://gist.github.com/felipernb/968fafb2eb8f8fa741847a2eb87e62e5
It's a different way to rewrite history, it uses
filter-branchand actually causes a merge and doesn't alter anything regarding the commit author (which I think is nice). So maybe lerna should do that instead?gigabo commentedon Oct 21, 2016
Sorry to leave this dangling. Unfortunately I no longer contribute to Lerna.
As a workaround I've found that
git rebase --interactive(even with no changes) will produce a linear history that can be fed intolerna import.peduarte commentedon Nov 8, 2016
Having the same issue here.
git rebase --interactivedidn't help unfortunately.0xR commentedon Nov 13, 2016
Having the same issue, since I don't have time to investigate further I just copied the files over without git history. I'm on beta.30 btw.
[-]Import failing (2.0.0-beta.24)[/-][+][Bug] Import failing (2.0.0-beta.24)[/+]emirotin commentedon Feb 18, 2017
Had the same issue with beta30 and beta37. Pretty much every repo has merge commits on master. We don't really care of retaining them, so if lerna could flatten the branch history (essentially making it look like no merges did happen and all the commits originally went straight to master) that would be sufficient for us.
interactive rebase against root seems to be doing exactly that so we do probably have the backup plan, but if lerna automated that that would be great
emirotin commentedon Feb 18, 2017
ADD: A bit of context. Monorepo concept is relatively new and I believe many companies are deciding to use it to consolidate bits of the existing code.
To me the import feature is one of the biggest selling points (we've currently decided to start using lerna for clusters of the related modules).
So I believe smooth import process (fixing the current issue + wokring with the remotes #269) is crucial for the existing projects to migrate to lerna.
trxcllnt commentedon Sep 8, 2017
I have no idea if this is relevant to anybody else, but a slightly modified form of the function in this stack overflow answer worked great for me. For OS X users, make sure to install and use
gnu-sed(brew install gnu-sedwas all I had to do, but others may need to update the script to usegsed).Define this function in a shell script somewhere (I put it in my
~/.bash_profiletemporarily b/c I'm lazy and/or stupid):Then from the root of your lerna mono-repo, run:
It'll take a bit to run but when it finishes, your git history should look like you've been committing files under
packages/your-repoall along. Everything on GitHub (history, merges, commits, blame, diffs) look to be working.I haven't tested whether it's possible to pull in upstream changes from the original repo (but I seriously doubt it), so make sure you stop committing to the original one and fully switch over.
I don't have any special understanding of why this works, I likely can't help if it doesn't work for you. When in doubt, do it in a freshly cloned local version of your lerna repo so you can delete it and try again. Good luck!
evocateur commentedon Sep 8, 2017
I agree that
git filter-branchis often the best choice for this sort of thing; I also recognize thatfilter-branchis almost impossible to generalize (in any useful way), and will almost always be a one-off, custom thing.stale commentedon Dec 27, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
lock commentedon Apr 3, 2019
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.