Skip to content

Instantly share code, notes, and snippets.

@cebe
Created August 19, 2011 14:32
Show Gist options
  • Save cebe/1156937 to your computer and use it in GitHub Desktop.
Save cebe/1156937 to your computer and use it in GitHub Desktop.
script to mirror svn repository
# subversion
.subversion
# mirror dirs
/mirror/*
/tmp/*
<?php
$authors = `svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq`;
$known = array(
'(no author)' => 'nobody <[email protected]>',
);
$found = array();
$authors = explode("\n", $authors);
foreach($authors as $author) {
$author = trim($author);
if (empty($author)) {
continue;
}
$key = $author;
if (substr($author, -10, 10) == '@gmail.com') {
$author = substr($author, 0, -10);
}
if (isset($known[$author])) {
$found[$key] = $known[$author];
} elseif (($pos = strpos($author, '@')) !== false) {
$found[$key] = substr($author, 0, $pos) . ' <' . $author . '>';
} else {
$found[$key] = $author . ' <' . $author . '@gmail.com>';
}
}
foreach($found as $old => $new) {
echo $old . ' = ' . $new . "\n";
}
#!/bin/sh
#
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "git > svn mirror script by CeBe <[email protected]>"
echo ""
echo "usage: $0 svnurl [giturl]"
echo ""
echo " svnurl base url to svn repo, NOT url to trunk! must end with /"
echo " giturl url of git repo to push code to. this repo should be empty"
echo " if not specified, you have to push repo in ./mirror yourself"
echo ""
echo "requires git, svn, php and svn2git (https://github.com/nirvdrum/svn2git)"
echo ""
exit 1;
fi
# create empty tmp dir
if [ -d ./tmp ] ; then
rm -rf ./tmp
fi
mkdir ./tmp
cd ./tmp
svn checkout $1 svn
# generate authors file
touch authors.txt
cd svn
php ../../authors.php > ../authors.txt
cd ../../
mkdir mirror
cd mirror
svn2git $1 -m -v --authors ../tmp/authors.txt
if ! [ "$2" = "" ] ; then
git remote add gitmirror $2
git push -u --all gitmirror
git push --tags gitmirror
fi
cd ..
#!/bin/sh
#
cd mirror
svn2git --rebase
ret=$?
if [ $ret -eq 0 ] ; then
git push -u --all gitmirror
ret=$?
fi
if [ $ret -eq 0 ] ; then
git push --tags gitmirror
ret=$?
fi
cd ..
exit $ret
@cebe
Copy link
Author

cebe commented Aug 19, 2011

make sure to have your git config set up correctly before running the script. It needs the user.name and user.email settings to be set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment