Moving away from CVS to GIT

  2016-07-29 18_21_42-Edit Post ‹ RedHeadHat —

We are currently at the very start of our DevOps journey, gradually transitioning from legacy development tools, into more modern, platform-independent tools. One of my clients is using the ancient source control system ‘CVS’, and because I want to implement a CI pipeline we had to convert all of our CVS repositories into git repos.

It’s not easy to convince dev people to throw away what they know and start using new tools, no matter how good you explain the benefits. The old statement “Why replace something that’s not broken?” will almost always win any argument. Eventually I was able to persuade the right people.

So if you have a bunch of CVS repositories you want to get rid of, and you like GitLab, checkout this bash script I’ve wrote to convert each CVS directory into a bare git repo, and then push that repo into GitLab.

What’s neat about this script is that it uses GitLab API to programatically create each repo with custom visibility settings (‘Internal Project’) so that developers can get on board quickly. Consider running the ‘Add all users to all projects’ rake task to add all GitLab users to the newly created repos (careful with this, it does not destinguish between imported repos and old repos)

$ gitlab-rake gitlab:import:all_users_to_all_projects

Here are the instructions:

  1. Install cvs2svn & cvs (you can find links below)
  2. cd into the directory holding all your CVS repositories (Where CVSROOT is located)
  3. Create folders “output/git_tmp” in the current folder
  4. Change parameters in to match your environment
  5. chmod +x
  6. Execute ./


And here is the code:



while read LINE ;do
  echo "doing $LINE ..."
  cvs2git --blobfile="$OUTPUT_ROOT_DIR"/"$TMP"/git-blob_"$LINE".dat --dumpfile="$OUTPUT_ROOT_DIR"/"$TMP"/git-dump_"$LINE".dat --username=cvs2git $LINE
  mkdir "$OUTPUT_ROOT_DIR"/"$LINE".git
  cd "$OUTPUT_ROOT_DIR"/"$LINE".git
  git init --bare
  cat ../"$TMP"/git-blob_"$LINE".dat ../"$TMP"/git-dump_"$LINE".dat | git fast-import
  git gc --prune=now
  git remote add origin git@"$GITLAB_HOSTNAME":root/"$LINE_LOWER".git
  curl -H "Content-Type:application/json" http://"$GITLAB_HOSTNAME"/api/v3/projects?private_token="$GITLAB_API_KEY" -d "{ \"name\": \"$LINE\" ,\"visibility_level\": \"10\" }"
  git push --all
  cd ../../
  echo "done with ${LINE}."

done < $REPOS






Published by

Amir Barkal

"Music is the best" - FZ

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s