Skip to content

budavariam/migrate-hg-to-git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Migrate mercurial to git

Bitbucket stops supporting mercurial repositories in 2020.

My first version control was Mercurial, so I had a bunch of repositories, and bitbucket was my main repository holder while I learned to code. I decided to save the files stored in those repositories, but I did not want to do all that by hand, and until this day there is no one/click solution to migrate those repositories.

I Used OSX 10.15.2, bash, jq, and fast-export for this task.

Prepare

I did not script these steps:

  • brew install mercurial, jq
  • Add my public ssh key to bitbucket
  • Get a json of my mercurial repositories. Into repos/repos.json. (bitbucket api or network inspector).
  • create new repositories with some name prefix e.g: g_ (bitbucket api or by hand)

How the script works

It is based on the git documentation about migration.

  1. Clone fast-export
  2. Parse the provided repos/repo.json file
  3. Clone the hg repositories into repos
  4. Prepare the PYTHON2 environment that is necessary for fast-export
  5. Create a newrepos folder, and init git repositories over there.
  6. Migrate repos to the new location
  7. Add new git origin, push

Run

./script.sh BITBUCKET_USERNAME

This script does not delete anything, and works only in this folder hierarchy, but I advise you to review it without starting it. I might have missed something that is necessary for different repositories, I am happy with my result.

Troubleshooting

Illegal byte sequence error

One of my repositories contained a binary file with accented characters in its name from windows. HG would not clone these for me with this error: abort: Illegal byte sequence.

I checked that repo out in windows, renamed the file and committed a change with the new name. It fixed my problem.

IMPROVEMENT IDEAS

  • script bitbucket api for getting and creating repositories
  • keep the projects instead of adding everything to the user, would need to parse url, or get that info with jq