Klarre Klarre - 10 months ago 49
Git Question

hg convert abort: '\n' and '\r' disallowed in filenames:

I'm about to convert my git repo into a hg repo. The problem is that a few months ago there was a file added named 'favicons/Icon\r' to the git repo, which is fine for git. The file has been deleted, but since it is in the history I get this output when running the hg convert extension:

816 Favicons
transaction abort!
rollback completed
abort: '\n' and '\r' disallowed in filenames: 'favicons/Icon\r'!

Is there a way to work around this or do I have to stay with my git repo? Thanks a lot!

Answer Source

Since that path-name is invalid in Mercurial, you must do one or more of the following:

  • convert the Git repository with code that skips the "bad" commits and/or files
  • convert the Git repository with code that substitutes in a "good" file name instead
  • copy the Git repository to an altered Git repository, in which the file name does not appear (removing or altering commits that have that file, a la the prior two methods, but doing it within Git rather than during the conversion to Mercurial).

The first two may be easy to achieve directly using hg convert. For instance, the documentation mentions the ability to exclude or rename files by file-name. I have not actually tried this myself, though.

The last is relatively easy since you can use git filter-branch to achieve it. The "relative" in "relatively easy" is very relative: filter-branch is not particularly easy to use correctly (it's just easier than writing a new Git-to-Mercurial converter).

See How to remove/delete a large file from commit history in Git repository? and Completely remove file from all Git repository commit history for examples. Note that Greg Bacon's answer correctly uses --tag-name-filter to adjust tags (this is necessary if you have tags that point into history at or beyond the point at which commits are altered during the copying).