migrate Hg to Git via "fast-export" in Windows
Asked Answered
S

6

6

I have a project having mercurial HG code source management,and try to migrate it on a VSTS/Git platform.

I read that there is a tool for doing that, "fast-export"... So I tried but not did't achieve to do it working in Windows...

Say I have D:\MyProject containing the .hg directory and the project code files, I

  • downloaded the fast-export files in the "D:\fast-export-master" folder,
  • created a new directory D:\MyProject-git
  • launched in that D:\MyProject-git the git init command (a new .git directory appeared then);
  • now from the same D:\MyProject-git i did
    ..\fast-export-master\hg-fast-export.sh -r "D:\MyProject"

now strange things starts happening, a command line window appeared and disappeared so quickly I didn't understood what happened, so I relaunched the previous command in a hope to see the message... I should try tens of times until able to capture in the printscreen the command-line message, that says strange things:

which: no D:\fast-export-master\hg-fast-export.sh in (/c/Users/xxx/bin:mingw64/bin:/user/local/bin:/usr/bin:/bin/mingw64/bin:/usr/bin:/c/Users/xxx/bin:/c/ProgramData/Oracle/Java/javapath:/c/WINDOWS/system32 [...etc...etc...])

I wonder what is the problem and how to solve it...

EDIT:

Following the @max630 suggestion bellow, I reinstalled Python and update the PATH, so it's recognized in the command

> python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

opened the "GIT Bash" from the start menu then

cd "/D/MyProject-git"
../fast-export-master/hg-fast-export.sh -r "D:\MyProject" --force

that gave:

../fast-export-master/hg-fast-export.sh: line 175: python: command not found
C:\Program Files\Git\mingw64\libexec\git-core\git-fast-import.exe statistics:
---------------------------------------------------------------------
Objects allocated:       5000
...

enter image description here

Singleaction answered 12/3, 2018 at 10:56 Comment(2)
You probably want to add tag "git-for-windows" because this is what you most probably are using. Since there is limitation of at most 5 tags you'd have to remove some.Daloris
I installed git for windows, but I don't really use it, I use Visual Studio Team Services GUI, that uses git in background...Singleaction
I
1

I think your concern is that you imported the "hg-fast-export" into a directory that was not added to your environment variables, according to the error message "D:\fast-export-master\hg-fast-export.sh" was not found in the list of your environment variables, so try to add th following "D:\fast-export-master\"in your environment variables and then try again.

If it does not work out yet, look at this article and follow step by step what was said:

https://www.appveyor.com/blog/2014/02/23/converting-mercurial-repository-to-git-on-windows/

The author has copied the directory "hg-fast-export" into the new directory git (without the .git of "hg-fast-export") and has also added hg, git and python to his environment variables.

good luck

Invalidism answered 13/3, 2018 at 12:27 Comment(1)
I followed the article steps, but at the moment hg-fast-export.sh -r c:\projects\demoapp -A authors.txt it didn't find hg-fast-export, probably because of what your are saying I have no Path EnvironmentVar, so I open the Git Bash in the demoapp_git folder and then did $ /c/projects/demoapp_git/hg-fast-export.sh -r "C:\projects\demoapp" --force and it worked!Singleaction
S
1

Following the @max630 suggestion bellow, I reinstalled Python and update the PATH

Starting with Git 2.24 (Q4 2019), you will have to install Python 3, since the hg-to-git script (in contrib/) has been updated to work with Python 3.

See commit d17ae00 (18 Sep 2019) by Hervé Beraud (4383).
(Merged by Junio C Hamano -- gitster -- in commit 8f53fe1, 07 Oct 2019)

hg-to-git: make it compatible with both python3 and python2

Python 2 is EOL at the end of 2019, many distros and systems now come with python 3 as their default version.

Rewrite features used in hg-to-git that are no longer supported in Python 3, in such a way that an updated code can still be usable with Python 2:

  • print is not a statement; use print() function instead.
  • dict.has_key(key) is no more; use "key in dict" instead.
Semen answered 12/10, 2019 at 20:5 Comment(0)
G
1

In case it helps anyone, it took me a while to get hg-fast-export to work, but I eventually got there. Here are some issues I ran into:

  • I needed to install Python and also had to add the Python binary directory to the system PATH.
  • The instructions say to run hg-fast-export from a git bash window. On my first attempt I could not even cd to the correct directory, because my bash shell had me "jailed" to my home directory hierarchy. I changed the git bash shortcut to Run as Administrator, removed the --cd-to-home argument, and set it start in C:. Note that once you start the shell, paths will start with /c/.
  • After issuing command git init to create an empty repo, I also had to issue git config core.ignoreCase false before the export would go further.
    • Next I got the error "ImportError: No module named mercurial". I had done a binary install of TortoiseHg but it needed sources. I downloaded Mercurial sources and added the root source directory to the system environment variable PYTHONPATH. Then I re-launched git bash.
    • Now the git-fast-export worked!
    • As documented, git status will show all files as "deleted". Issue the command git checkout HEAD, repeat git status, and it should show "nothing to commit, working tree clean".
Grande answered 30/10, 2019 at 0:42 Comment(0)
D
1

I spent hours and hours trying many of the above solutions, and nothing worked well for me. I tried the fast-export and the hggit in tortoisehg in numerous variations.

In the end I used the GitHub Importer to import all of my mercurial repository into GitHub.

I just needed to provide the URL of the repository (mine was in BitBucket), and it was a very smooth and easy process. Much smoother than trying to get python working in git bash, path variables, etc!

I also had some significant local changes that I could not push to bitbucket because they're not allowing pushes. So I had to copy those files manually into the git repository.

I also could not get teamcity to detect the changes when switching from VCS roots from bitbucket to github. So I created a new project in team city.

I hope this helps anybody who is facing these challenges.

Density answered 7/8, 2020 at 19:39 Comment(0)
D
0

There seems to be a bug in the bash bundled with git. It does not initialize "$@" properly if started from directly running .sh file from cmd.

Open "GIT Bash" from start menu, then issue commands:

cd "/D/MyProject-git"

to navigate to D:\MyProject-git, and

../fast-export-master/hg-fast-export.sh -r "D:\MyProject"

to run your script

Daloris answered 12/3, 2018 at 14:39 Comment(5)
"Error: The option core.ignoreCase is set to true in the git repository. This will produce empty changesets for renames that just change the case of the file name" so I used --force to skip this check, but then "../fast-export-master/hg-fast-export.sh: line 175: python: command not found"Singleaction
i reinstalled Python, restarted the PC, retried: but anyway ../fast-export-master/hg-fast-export.sh: line 175: python: command not found... checked the hg-fast-export.sh on the line 175, there is a comment there, any "python" command...Singleaction
it should be in you PATH. Also I don't know if python for windows would work in msys environmentDaloris
I added in the Path, now it recognizes "python" in the command line, however the error message in git batch is the same... I found similar issue here #17970841 but is crazy i should also clone the Hg-Git extension...Singleaction
You could try to install g4w sdk, where you could install python built for msys2, not the windows one. But it might be that the script you picked is not that ready for use. I cannot say in general how to convert repositories, I have done it only once, with some hg extension, and the repository was small so that it did not require involving with fast anything.Daloris
S
0

Since you already installed TortoiseHg, there has an easier way to migrate hg to git.

First, enable hggit in TortoiseHg:

TortoiseHg -> global setting -> Extensions Tab -> select hggit -> OK.

enter image description here

Then use below commands to migarte and push to VSTS git repo:

# In an empty folder
mkdir git
cd git
git init
cd ..
hg clone <URL for Hg repo>
cd hgrepo
hg bookmarks ../git
cd ..
cd git
git checkout hg
git remote add origin <VSTS git repo URL>
git push origin --all
Safe answered 13/3, 2018 at 9:19 Comment(3)
Thanks. After hg clone there should'n be cd <repo name>?Singleaction
C:\mygit\git>git checkout hg error: pathspec 'hg' did not match any file(s) known to git.Singleaction
Oh, yeah, it should use cd <hg repo name> after hg clone. I updated it in my answer, please try again.Safe

© 2022 - 2024 — McMap. All rights reserved.