Skip to content

Instantly share code, notes, and snippets.

@aschempp
Created December 23, 2011 09:26
Show Gist options
  • Save aschempp/1513710 to your computer and use it in GitHub Desktop.
Save aschempp/1513710 to your computer and use it in GitHub Desktop.
Moving a Contao extension into its own GitHub Repository
#!/bin/bash
##
# Useful ressources & links:
# http://john.albin.net/git/convert-subversion-to-git
# http://airbladesoftware.com/notes/moving-a-subdirectory-into-a-separate-git-repository
# http://nathanhoad.net/how-to-delete-a-remote-git-tag
# http://i.justrealized.com/2010/rename-tag-git/
##
##
# Param 1: Old SVN repo URL
# Param 2: New GIT repo name (must be available on GitHub)
# Param 3: Your GitHub username (or organization name)
##
##
# 1: CONVERT THE SVN REPO TO GIT
##
# Run in a temporary directory
mkdir github-convert
cd github-convert
# Create a copy of the SVN to read authors
mkdir old-svn
cd old-svn
svn checkout $1 ./
# Grab all the log messages, pluck out the usernames, eliminate any duplicate usernames, sort the usernames and place them into a “authors-transform.txt” file.
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
# Now edit each line in the file. For example, convert: "jwilkins = jwilkins <jwilkins>" into this: "jwilkins = John Albin Wilkins <[email protected]>"
open -W authors-transform.txt
# Clone the Subversion repository using git-svn
git svn clone $1 --no-metadata -A authors-transform.txt --stdlayout ../new-git
# Convert svn:ignore properties to .gitignore
#cd ../new-git
#git svn show-ignore > .gitignore
#git add .gitignore
#git commit -m 'Convert svn:ignore properties to .gitignore.'
# Push repository to a bare git repository
cd ../new-git
git init --bare ../new-bare.git
cd ../new-bare.git
git symbolic-ref HEAD refs/heads/trunk
cd ../new-git
git remote add bare ../new-bare.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare
# Rename the trunk branch to master
cd ../new-bare.git
git branch -m trunk master
# Clean up branches and tags
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
git tag "$ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";
done
cd ..
##
# 2: FILTER OUR EXTENSION FROM THE NEW GIT REPOSITORY
##
# First we need to clone the GIT-SVN repo.
git clone --no-hardlinks ./new-bare ./$2
# Next we discard everything other than the subdirectory we want, promoting it to the root level.
cd $2
git filter-branch --subdirectory-filter system/modules/$2 HEAD -- --all
git reset --hard
# Now we get rid of the objects we are no longer interested in.
git gc --aggressive
git prune
# Next we replace the reference to the original repo with our new remote repo on GitHub.
git remote rm origin
git remote add origin [email protected]:$3/contao-$2
# Now we can push everything up to GitHub.
git push origin master
# Remove working directory, you can now clone from GitHub
cd ../..
rm -rf github-convert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment