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
{{ message }}
Repository navigation
Use git subtree for importing external packages #615
I've had issues using $ lerna import to pull in external packages and with no luck, I've had to find an alternative solution. Most of the problems I've encountered are some variation of the issues already raised in this repo, along the lines of:
Error: Command failed: /bin/sh -c git am -3
fatal: git apply: bad git-diff - inconsistent old filename on line 218
error: could not build fake ancestor
@gigabo briefly mentioned on slack that "The advantage of the method lerna import uses currently is the history is all rewritten to the target directory, so git log and git annotate work how you’d expect them to.". This is certainly a welcomed benefit, though given the buggy nature of this method, a simpler (and hopefully bug free) approach I used to get round this issue could be employed.
I had written the following bash script that utilises git's subtree cmd. This retains all of external package X's history and imports as expected into my lerna repo, with the difference being that the history isn't rewritten to the target directory as per lerna's method.
Workaround script:
if [[ $# -ne 2 ]]; then
echo "Please provide a project name and a project path to import an existing package. Example :"
echo " $0 my_project path/to/my_project"
exit 1
fi
project_name=$1
project_path=$2
git subtree add -P packages/$project_name $project_path master
Using the script above I was able to pull in several external packages with ease and so I wanted to share this with you guys to spark a discussion on whether we would like to see lerna employing git subtree as an alternative approach.
Reacted by Chris Laughlin, Bo Borgerson, Douglas Wade, Brian M Hunt, Ben Clinkinbeard, Kayla Altepeter, Nick Bergseng, Furkan Tunalı, Dan Phelps, Dan Argue and 3 more
@asharma93 I just tried to use lerna import on a fresh lerna repo (e.g. only ran a lerna init with the latest master), and was greeted with
dwade frontend/monorepo ‹import-build› » lerna import ../build
Lerna v2.0.0-beta.38
4d892f1
About to import 81 commits from ../build into packages/build
? Are you sure you want to import these commits onto the current branch? Yes
Errored while running ImportCommand.execute
Failed to apply commit 716f365.
Error: Command failed: git am -3
error: sha1 information is lacking or useless (packages/build/package.json).
error: could not build fake ancestor
Rolling back to previous HEAD (commit 4d892f1).
I can confirm that git subtree add -P packages/build ../build master works as intended, so I'm in favor of this change.
Reacted by Brian M Hunt, Rob Hilgefort and Kevin Ross
any updates on this?
i think it solves the #1058 ("issue with importing packages with merge commits") much better then the "--flatten" flag that removes the merges history whatsoever.
In my experience, the subtree import doesn't update the paths in the history of the files (like lerna currently does manually), so it ends up with broken file history. Happy to be proven wrong though
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
doug-wade commentedon Mar 20, 2017
@asharma93 I just tried to use
lerna importon a fresh lerna repo (e.g. only ran alerna initwith the latest master), and was greeted withI can confirm that
git subtree add -P packages/build ../build masterworks as intended, so I'm in favor of this change.asharma93 commentedon Apr 5, 2017
If there aren't any objections I'll submit a PR.
issue with import whitespace workaround: lerna/lerna#615
vzaidman commentedon Dec 5, 2017
any updates on this?
i think it solves the #1058 ("issue with importing packages with merge commits") much better then the "--flatten" flag that removes the merges history whatsoever.
vzaidman commentedon Dec 5, 2017
here is how adding multiple packages using
git subtreelooks likechrisdothtml commentedon Sep 4, 2018
In my experience, the subtree import doesn't update the paths in the history of the files (like lerna currently does manually), so it ends up with broken file history. Happy to be proven wrong though
vzaidman commentedon Sep 5, 2018
actually it works quite fine. you can see the history with older paths which was good enough for our usage.
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.