Skip to content

[Bug] Import failing (2.0.0-beta.24) #272

Closed

Description

@ericf

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.

formatjs/intl-messageformat@fb50371

Errored while running ImportCommand.execute
Failed to apply commit fb50371.
Error: Command failed: git am -3
error: Failed to merge in the changes.

formatjs/intl-relativeformat@2495e18

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.

Activity

  1. jamiebuilds commented on Jul 11, 2016

    @jamiebuilds
    Contributor
  2. gigabo commented on Jul 11, 2016

    @gigabo
    Contributor

    Thanks for reporting @ericf. I'll see if I can track down what's going wrong.

  3. gigabo commented on Jul 25, 2016

    @gigabo
    Contributor

    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.

  4. ericf commented on Jul 25, 2016

    @ericf
    Author

    @gigabo thanks for digging deep into this one — definitely a messy Git situation.

    We might wind up needing to squash branches that contain patches that don't apply cleanly.

    I think that seems fine me to as a strategy to employ when there's an issue in a merge commit.

  5. jamiebuilds commented on Jul 25, 2016

    @jamiebuilds
    Contributor

    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

  6. felipernb commented on Oct 21, 2016

    @felipernb

    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-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?

  7. gigabo commented on Oct 21, 2016

    @gigabo
    Contributor

    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 into lerna import.

  8. peduarte commented on Nov 8, 2016

    @peduarte

    Having the same issue here. git rebase --interactive didn't help unfortunately.

  9. 0xR commented on Nov 13, 2016

    @0xR

    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.

  10. changed the title [-]Import failing (2.0.0-beta.24)[/-] [+][Bug] Import failing (2.0.0-beta.24)[/+] on Nov 16, 2016
  11. emirotin commented on Feb 18, 2017

    @emirotin

    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

  12. emirotin commented on Feb 18, 2017

    @emirotin

    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.

  13. trxcllnt commented on Sep 8, 2017

    @trxcllnt

    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):

    git_add_repo()
    {
        repo="$1"
        dir="$(echo "$2" | sed 's/\/$//')"
        path="$(pwd)"
        mkdir -p "$dir"
    
        tmp="$(mktemp -d)"
        remote="$(echo "$tmp" | sed 's/\///g'| sed 's/\./_/g')"
    
        git clone "$repo" "$tmp"
        cd "$tmp"
    
        git filter-branch --index-filter '
            git ls-files -s |
            sed "s,\t,&'"$dir"'/," |
            GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info &&
            mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
        ' HEAD
    
        cd "$path"
        git remote add -f "$remote" "file://$tmp/.git"
        git fetch "$remote"
        git merge --allow-unrelated-histories -m "Merge repo $repo into master" --no-edit "$remote/master"
        git remote remove "$remote"
        rm -rf "$tmp"
    }
    
    export -f git_add_repo

    Then from the root of your lerna mono-repo, run:

    git_add_repo [email protected]:your_user/your-repo.git packages/your-repo

    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!

  14. evocateur commented on Sep 8, 2017

    @evocateur
    Member

    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.

  15. stale commented on Dec 27, 2018

    @stale

    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.

  16. lock commented on Apr 3, 2019

    @lock

    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.

  17. locked as resolved and limited conversation to collaborators on Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions