Skip to content

Instantly share code, notes, and snippets.

@aheritier
Created March 18, 2012 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aheritier/2081003 to your computer and use it in GitHub Desktop.
Save aheritier/2081003 to your computer and use it in GitHub Desktop.
SVN -> GIT
#!/bin/bash -eu
svn_repo_url=$1
git_repo_path=$2
git_repo_name=$3
git_repo_desc=$4
git_repo_owner=$5
# If something wasn't removed by a previous job
rm -rf $SWF_TMP_DIR/$git_repo_name.git
# Create the target repository
git init --bare --shared $SWF_TMP_DIR/$git_repo_name.git
cd $SWF_TMP_DIR/$git_repo_name.git;
git symbolic-ref HEAD refs/heads/trunk;
git config http.receivepack true
git config user.name "SWF Team"
git config user.email exo-swf@exoplatform.com
git --bare update-server-info
cp $SWF_TMP_DIR/$git_repo_name.git/hooks/post-update.sample $SWF_TMP_DIR/$git_repo_name.git/hooks/post-update
chmod a+x $SWF_TMP_DIR/$git_repo_name.git/hooks/post-update
# Clone the original Subversion repository to a temp repository.
git svn clone --stdlayout --quiet --no-metadata --authors-file $authors_file --authors-prog=${SWF_BASE_DIR}/bin/svn-lookup-author.sh $svn_repo_url $SWF_TMP_DIR/$git_repo_name.svn;
cd $SWF_TMP_DIR/$git_repo_name.svn;
# Create .gitignore file.
echo "Converting svn:ignore properties into .gitignore." >&2;
git config user.name "SWF Team"
git config user.email exo-swf@exoplatform.com
echo "#" >> .gitignore;
echo "# Ignores generated by SVN2GIT conversion" >> .gitignore;
echo "#" >> .gitignore;
echo "" >> .gitignore;
git svn show-ignore --id trunk >> .gitignore;
cat ${SWF_BASE_DIR}/etc/${SWF_NAME}/default.gitignore >> .gitignore;
git add .gitignore;
git commit --author='SWF Team <exo-swf@exoplatform.com>' -m 'Convert svn:ignore properties to .gitignore.';
# Push to final bare repository and remove temp repository.
git remote add bare $SWF_TMP_DIR/$git_repo_name.git;
git config remote.bare.push 'refs/remotes/*:refs/heads/*';
git push bare;
# Push the .gitignore commit that resides on master.
git push bare master:trunk;
cd -
rm -rf $SWF_TMP_DIR/$git_repo_name.svn;
cd $SWF_TMP_DIR/$git_repo_name.git;
# Rename Subversion's "trunk" branch to Git's standard "master" branch.
git branch -m trunk master;
# Remove bogus branches of the form "name@REV".
git for-each-ref --format='%(refname)' refs/heads | grep '@[0-9][0-9]*' | cut -d / -f 3- | while read ref; do
git branch -D "$ref";
done
# Convert git-svn tag branches to proper tags.
git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 | while read ref; do
git tag -a "$ref" -m "Convert "$ref" to proper git tag." "refs/heads/tags/$ref";
git branch -D "tags/$ref";
done
# Call GC to manual clean/compress the repo
git gc --aggressive --prune=now;
cd -
if [ ! -e $git_repo_path ]; then
mkdir -p ${GIT_REPOS_DIR}/$git_repo_path
fi;
mv $SWF_TMP_DIR/$git_repo_name.git ${GIT_REPOS_DIR}/$git_repo_path
rm -f $authors_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment