Created
September 25, 2014 13:35
-
-
Save dlovell/7ed6144e2328a21fcada to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://git-scm.com/book/en/Git-and-Other-Systems-Git-and-Subversion | |
# sudo apt-get install subversion git-svn | |
set -euv | |
function create_local_svn_copy { | |
local svn_dir=$1 | |
local svn_url=$2 | |
# | |
pre_revprop_change_file=$svn_dir/hooks/pre-revprop-change | |
# set up locally | |
mkdir $svn_dir | |
svnadmin create $svn_dir | |
# | |
cat -- > $pre_revprop_change_file <<EOF | |
#!/bin/sh | |
exit 0; | |
EOF | |
chmod +x $pre_revprop_change_file | |
# clone down the repo | |
svnsync init file://$svn_dir $svn_url | |
svnsync sync file://$svn_dir > svnsync_sync.out | |
} | |
function inspect_git_dir { | |
local git_dir=$1 | |
cd $git_dir | |
git branch -a | |
git log --pretty=oneline -n 5 | head | |
} | |
function make_branch_and_commit { | |
local git_dir=$1 | |
local branchname=$2 | |
# create a new branch | |
cd $git_dir | |
git checkout -b $branchname | |
# make some modifications | |
filename=README.txt | |
regex='s/make/break/g' | |
perl -pi.bak -e $regex $filename | |
git commit $filename -m "do $regex" | |
filename=python/google/protobuf/message.py | |
regex='s/object/slobject/g' | |
perl -pi.bak -e $regex $filename | |
git commit $filename -m "do $regex" | |
} | |
function update_git_master { | |
local git_dir=$1 | |
cd $git_dir | |
git checkout master && \ | |
git svn rebase | |
} | |
function merge_branch_and_push { | |
local git_dir=$1 | |
local branchname=$2 | |
update_git_master $git_dir | |
cd $git_dir | |
git checkout master && \ | |
git merge --no-ff $branchname -m "merge $branchname" && \ | |
git svn dcommit | |
} | |
function checkout_svn_and_inspect { | |
local svn_dir=$1 | |
temp_dir=$(mktemp -d) | |
echo "checking out svn to $temp_dir" | |
# verify that was merge in a single commit | |
svn co file://$svn_dir $temp_dir >/dev/null && \ | |
cd $temp_dir && \ | |
svn log -l 2 -v | |
} | |
svn_dir=~/test-svn-repo | |
git_dir=~/test-git-repo | |
svn_url=http://progit-example.googlecode.com/svn/ | |
branchname=mybranch | |
if [ ! -d ${svn_dir}.orig ]; then | |
create_local_svn_copy $svn_dir $svn_url | |
cp -R ${svn_dir} ${svn_dir}.orig | |
else | |
# don't pull from network if you don't have to | |
cp -R ${svn_dir}.orig ${svn_dir} | |
fi | |
# look at svn repo before changes | |
checkout_svn_and_inspect $svn_dir | |
# this gets you a git version of svn at $git_dir | |
git svn clone file://$svn_dir -s $git_dir >git_svn_clone.out 2>git_svn_clone.err | |
# inspect what the git repo looks like | |
inspect_git_dir $git_dir | |
make_branch_and_commit $git_dir $branchname | |
merge_branch_and_push $git_dir $branchname | |
# look at svn repo after changes | |
checkout_svn_and_inspect $svn_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment