7

After solving countless problems with the hg-fast-export tool on Windows (from finicky python version needed to cleaning up mercurial repository to satisfy the tool) I have stumbled upon a n error that I cannot solve:

master: Exporting full revision 1/98 with 142/0/0 added/changed/removed files
fatal: Branch name doesn't conform to GIT standards: refs/heads/master
fast-import: dumping crash report to .git/fast_import_crash_5956
Traceback (most recent call last):
  File "../fast-export/hg-fast-export.py", line 388, in <module>
    options.statusfile,authors=a,sob=options.sob,force=options.force))
  File "../fast-export/hg-fast-export.py", line 322, in hg2git
    c=export_commit(ui,repo,rev,old_marks,max,c,authors,sob,brmap)
  File "../fast-export/hg-fast-export.py", line 214, in export_commit
    export_file_contents(ctx,man,added)
  File "../fast-export/hg-fast-export.py", line 126, in export_file_contents
    wr(d)
  File "../fast-export/hg-fast-export.py", line 28, in wr
    print msg
  File "c:\Python26\lib\site-packages\mercurial\windows.py", line 70, in write
    raise IOError(errno.EPIPE, 'Broken pipe')
IOError: [Errno 32] Broken pipe

The error seems to be: Branch name doesn't conform to GIT standards: refs/heads/master

Does anyone have a clue on how to solve this issue?

My mercurial repository is clean and working properly, with only one head, all nice and hot ready to be exported.

EDIT:

I solved the problem by using TortoiseHG combined with hg-git. For anyone looking for a way to export a mercurial rep. to git or vice-versa, just follow the steps described here: http://www.ffuts.org/blog/accessing-a-git-repository-with-tortoisehg-on-windows/

Adabada
  • 303
  • 3
  • 15

1 Answers1

9

I just solved this problem for myself.

It turns out that Python was forcing there to be a '\r\n' at the end of every line that was output by hg-fast-export. This meant that the branch names were being interpreted like 'refs/heads/master\r', which is invalid.

The answer to this questsion...

Make Python stop emitting a carriage return when writing newlines to sys.stdout

...can be placed at the top of the hg-fast-export file, in order to switch to a binary mode.

EDIT:
The code to add is:

if sys.platform == "win32":
   import os, msvcrt
   msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

Just place it at the top of hg-fast-export.py and make sure you have an import sys at the top.

Community
  • 1
  • 1
John Gietzen
  • 48,783
  • 32
  • 145
  • 190
  • Although I never touched the hg-export file. I'm marking this as an answer but I strongly recommend anyone wanting to mix mercurial and git to go with the TortoiseHG and hg-git route. It's easier, faster and even has a nice UI you can use. – Adabada Apr 15 '12 at 22:51
  • It worked for me. msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) at the top hg-fast-export.py worked like a charm. – Tim Swast May 02 '12 at 18:35
  • Worked for me too. Just only do what Tim Swast said. – Aurelien Ribon Sep 05 '12 at 17:18
  • 1
    Note for Bazaar (bzr) users: The same error may be raised when doing a `bzr fast-export` and `git fast-import` on Windows, using PowerShell. To avoid the problem, simply use the `cmd.exe` shell instead of PowerShell (which seems to mess with line endings). – bdoering Sep 16 '15 at 13:05