Skip to content

import failure: "git diff header lacks filename information when removing 1 leading pathname component" #432

Closed

Description

@ericwooley

I'm trying to init a new lerna instance, and import some (very large) old repo's. And I am running into this error.

lerna import ../<some-large-repo>/
Lerna v2.0.0-beta.30
About to import 1947 commits into from ../<some-large-repo>/ into packages/<some-large-repo>
? Are you sure you want to import these commits onto the current branch? Yes
Errored while running ImportCommand.execute
Failed to apply commit a76cb3c23.
Error: Command failed: git am -3
error: git diff header lacks filename information when removing 1 leading pathname component (line 15046)
error: could not build fake ancestor

Rolling back to previous HEAD (commit 3ff03a0).

Activity

  1. gigabo commented on Dec 12, 2016

    @gigabo
    Contributor

    Yikes, that's a new one. Thanks for reporting @ericwooley.

    Is <some-large-repo> up on GitHub, by any chance? Looking for a way to repro this.

  2. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author

    I wish or I would have provided it. Unfortunately its work for a client :(

    I am trying to reproduce on something I can open source.

  3. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author

    @gigabo I found that I am having issues with this (which was the original fork)

    https://github.com/ericwooley/vortigern

    But a different error that simply says,

    lerna import ../vortigern/
    Lerna v2.0.0-beta.30
    About to import 143 commits into from ../vortigern/ into packages/vortigern
    ? Are you sure you want to import these commits onto the current branch? Yes
    Errored while running ImportCommand.execute
    Failed to apply commit 518cae8.
    Error: Command failed: git am -3
    error: Failed to merge in the changes.
    
    Rolling back to previous HEAD (commit 3ff03a0).
    

    EDIT:

    I tried with that repo on v29, because I saw there was some changes

    lerna import ../vortigern/
    Lerna v2.0.0-beta.29
    About to import 143 commits into from ../vortigern/ into packages/vortigern
    ? Are you sure you want to import these commits onto the current branch? Yes
    Errored while running ImportCommand.execute
    Failed to apply commit 223310f.
    Error: Command failed: git am -3
    error: git apply: bad git-diff - inconsistent old filename on line 335
    error: could not build fake ancestor
    
    Rolling back to previous HEAD (commit a3c40c4).
    
  4. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author

    I also took a look at the proprietery commit in question from the original import a76cb3c23

    And it is the addition of 30+ files, with several png's mixed in. Maybe the png files are part of the problem?

  5. gigabo commented on Dec 12, 2016

    @gigabo
    Contributor

    Okay, great. Thanks for tracking down an open repro.

    It looks from the error message like there may just be some filenames that we're failing to convert. The import command does some search-and-replace on patch files produced by git am.

  6. gigabo commented on Dec 12, 2016

    @gigabo
    Contributor

    Like maybe something similar to #346, but for added files?

  7. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author
    It looks from the error message like there may just be some filenames that we're failing to convert. The import command does some search-and-replace on patch files produced by git am.
    

    if I were to git diff a76cb3c23 and a76cb3c23^1 that would be the patch in question right? I'll see if I can find anything funny there

  8. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author
    diff --git a/src/app/components/alert/preview/alert.png b/src/app/components/alert/preview/alert.png
    deleted file mode 100644
    index 1d3fd4e12..000000000
    Binary files a/src/app/components/alert/preview/alert.png and /dev/null differ
    diff --git a/src/app/components/annotation/annotationComponent.css b/src/app/components/annotation/annotationComponent.css
    deleted file mode 100644
    index 0fe3a8696..000000000
    --- a/src/app/components/annotation/annotationComponent.css
    +++ /dev/null
    

    here is an excerpt that seems suspicious since there is a bunch of /dev/null. stuff happening

  9. gigabo commented on Dec 12, 2016

    @gigabo
    Contributor

    Yeah, if you wanted to use the actual command that import uses I think it would be:

    git format-patch -1 a76cb3c23 --stdout
    
  10. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author

    @gigabo Do you have an email or something I can contact you through?

  11. gigabo commented on Dec 12, 2016

    @gigabo
    Contributor

    Easiest is probably to jump on slack.

  12. gigabo commented on Dec 12, 2016

    @gigabo
    Contributor

    Talked with @ericwooley a bit on slack, and it sounds like an added file with a space in the filename may be the culprit here.

    In that case the diff looks like:

    diff --git a/path/too/foo file.png b/path/to/foo file.png
    

    My guess is this is tripping up the replacement pattern here, which looks specifically for non-whitespace in the filename.

  13. ericwooley commented on Dec 12, 2016

    @ericwooley
    Author

    @gigabo figured pointed out that it may have had to do with spaces in the file names, and he is correct.
    an example output with a space is:

    diff --git a/src/app/some thing.png b/src/app/some thing.png
    

    because it searches for the \S+ https://github.com/lerna/lerna/blob/master/src/commands/ImportCommand.js#L97

    it breaks on whitespace.

    EDIT
    @gigabo YOU BEAT ME

  14. ericwooley commented on Dec 13, 2016

    @ericwooley
    Author

    Looking through https://git-scm.com/docs/git-format-patch documentation, I don't see a way to output in a more parseable manner.

    The best possible way to handle this IMO, is to get a list of all files changed in that commit, and look to see if any of them match the last file in the line and use that if so.

    One gotcha to this approach is that you could have folder/file and folder folder/file data/file which could break the algorithm also. So it would be necessary to check longest file names first and work toward shortest.

    If I have time tonight, I'll see if I can do a PR for this.

  15. 2 remaining items

  16. added 2 commits that reference this issue on Dec 13, 2016
    d4766fb
    5dec3a7
  17. ericwooley commented on Dec 13, 2016

    @ericwooley
    Author

    @gigabo

    I implemented my solution in PR #434

    But am running into more problems, and I'm not sure what they are.

    However, I did a little research, and isn't this exactly what git subtree is for? I was able to successfully bring in each repo from the answer here http://stackoverflow.com/questions/6426247/merge-git-repository-in-subdirectory

    git subtree add -P packages/<my repo> ../<my repo>/ develop
    
  18. gigabo commented on Dec 13, 2016

    @gigabo
    Contributor

    Whoa... that move all of the history in to the packages/<my repo> path?

    How is the commit history attached? With a merge commit?

    That sounds really promising!

  19. ericwooley commented on Dec 13, 2016

    @ericwooley
    Author

    It does retain history, but maybe not as well as the original solution, as files are not listed as packages/<package>/folder/... but listed as folder/....

    There is also a giant commit at the HEAD of the repo that adds every file,

    1. blaming the file still seems to work fine everywhere I have looked.

    2. logging the file doesn't seem to work.

  20. gigabo commented on Dec 13, 2016

    @gigabo
    Contributor

    logging the file doesn't seem to work.

    Oh, hmm... would be nice to preserve this. 😖

    But, on the other hand, we've had some issues with this import strategy for a long time. A simpler solution that always works might still be better even if it doesn't provide perfect history?

    Do you have an idea about what the errors you're still seeing with your PR branch might be?

  21. ericwooley commented on Dec 13, 2016

    @ericwooley
    Author

    I updated the PR to use a better show file command, that allowed me to get through a couple hundred more commits but ran into a new one. But I think this issue will be closed by #434.

    I'll see if I can figure out what is wrong with the next commits.

    Patch parsing is aggravating.

  22. gigabo commented on Dec 13, 2016

    @gigabo
    Contributor

    Patch parsing is aggravating.

    Yeah, it is. 😞

    Glad you were able to get past this error. Interested to learn what the next error is.

  23. chrisdothtml commented on Sep 4, 2018

    @chrisdothtml
    Contributor

    Sharing my experience since I ran into a brick wall when getting this issue.

    The problem does indeed seem to be caused by files/folders in the history that have spaces in them (and has to do with this line only checking for non-whitespace \S characters). It seems like a pretty straightforward problem, but doesn't feel like it'd be a straightforward fix.

    The way I got around this was by using the bfg repo cleaner to delete the offending files/folders (with spaces in them) from the history in my repo. Once I did that, lerna was able to import it successfully

  24. evocateur commented on Sep 4, 2018

    @evocateur
    Member

    @chrisdothtml Ooh, yeah, that does look likely.

  25. chrisdothtml commented on Sep 5, 2018

    @chrisdothtml
    Contributor

    Replacing line 161 with

    .replace(/^(diff --git (?! b\/).+ b)/gm, replacement)
    

    actually covers most scenarios. The only ones it doesn't cover is filepaths containing specifically ' b/' (e.g. tests/scenario b/...). All other filespaths with spaces in them are covered, though.

    It feels a little hacky, but I can submit a PR for it if you're interested

  26. evocateur commented on Sep 5, 2018

    @evocateur
    Member

    @chrisdothtml That looks pretty good to me. A PR with a regression test would be great!

    (If we wanted to get suuuuuper finicky, we could actually set the --src-prefix and --dst-prefix to more ...robust? values, but I think that's an edge case we don't have to worry about right now)

  27. lock commented on Dec 27, 2018

    @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.

  28. locked as resolved and limited conversation to collaborators on Dec 27, 2018
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions