Apr 26, 2017

Convert a SubVersion Repository to GIT

Git has an extension command git-svn which allows to directly interact with a SubVersion repository.


To do the conversion to git completely, I started a container with Fedora as the base image:

docker run -it --name fed --hostname=fed fedora bash

Install git and the remote-hg extension in the container

dnf install git-svn.x86_64 git.x86_64

Clone the mercurial repo:

mkdir <repodir>
cd <repodir>
git svn init --stdlayout --username=<svnuser> --include-paths=<path2include> http://svn.server.h
ome/svn/<repo>
git svn fetch --all



To get the branches, checkout them locally:

for remote in `git branch -r |grep -v tags | sed -e 's#origin/##'`; do
  git checkout --track -b $remote
done

Now create the tags, which are branches from the import from SVN:
for remote in `git branch -r |grep tags`; do
  ref=`git show-ref $remote |awk '{print $1}'`;
  tag=`echo $remote |awk -F / '{print $(NF)}'`;
  git tag $tag $ref;
done

Add the new GIT repo as a remote and push the branches and the tags:

git remote add <name> http://git.server.home/scm/git/<targetRepoInGit>
git push --all <name>
git push --tags <name> 


Now the Repo is on the GIT-Server http://git.server.home/.



Apr 25, 2017

Converting Mercurial (hg) repositories to GIT

Git has an extension command remote-hg which allows to directly interact with an HG (mercurial) repository.

To keep the repository as a mercurial repo you can directly checkout with git and work as if the
repo would be a git repo:

git clone hg::http//hg.server.home/repo

To do the conversion to git completely, I started a container with Fedora as the base image:

docker run -it --name fed --hostname=fed fedora bash

Install git and the remote-hg extension in the container

dnf install git-remote-hg.noarch git.x86_64

Clone the mercurial repo:

git clone hg::http://hg.server.home/repo


To get the branches, checkout them locally:

for remote in `git branch -r |grep branches | sed -e 's#origin/##'`; do
git checkout --track -b $remote
done

Now rename the branches  if you like

for b in `git branch -l | grep branches | sed -e 's#branches/##'`; do
git branch -m branches/$b $b;
done

Add the new GIT repo as a remote and push the branches and the tags:

git remote add <name> http://git.server.home/scm/git/<targetRepoInGit>
git push --all <name>
git push --tags <name> 


Now the Repo is on the GIT-Server http://git.server.home/.




Conversion of a CVS repository to GIT

After detecting an old CVS (Concurrent Version System) , we'd like to convert this repository with
multiple modules to a GIT repository.

There is a module in git named git-cvsimport to import a CVS Repository.
The basic command is:
git cvsimport -o <targetbranch> -d <CVSROOT like :pserver:<host>:/repo <cvs-module>   
The problem is, that this command converts one CVS-Module (see CVS/module file) of the
repository.

On the repository I'm working on, there are multiple modules and they belong together. After
a little search, I found a script handling multiple modules:
see: http://max.romantschuk.fi/blog/2009/dec/29/importing-cvs-modules-single-git-repo/

The script linked in this page named git-cvsmod2subdir.sh is doing the job for me.
Bring in the script to the docker container.

Startup an interactive  docker container with e.g. CentOS as the image

docker run -it --name centos centos bash
yum -y install git git-cvs cvs cvsps 

git config --global user.email "email@domain"
git config --global user.name "Your Name"
 git init <gitrepo>  cd <gitrepo>

Before using the script, a local git repository has to be initialized as shown above, after this,
the CVSROOT has to be modified in git-cvsmod2subdir.sh and convert all repos with the
following command.


../git-cvsmod2subdir.sh <module1> <module2> <module3>

This sequence converts each module and merges it into the new GIT-Repository with a merge commit.