-
-
Save DavidSouther/8dfc6575f4d3a293be7c to your computer and use it in GitHub Desktop.
Full script for David's git svn hooks experiments.
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
#!/bin/sh | |
rm -rf ~/devel/$USER/git-experiments/svnhooks | |
killall svnserve | |
ROOT=~/devel/$USER/git-experiments/svnhooks | |
mkdir $ROOT ; cd $ROOT | |
svnadmin create svn | |
cd svn | |
cat >| conf/svnserve.conf <<SVN | |
[general] | |
anon-access = write | |
SVN | |
cd .. | |
svn mkdir --parents file://$ROOT/svn/experiments/{trunk,branches,tags} -m 'Initial structure' | |
svnserve -d -r $ROOT/svn | |
svn co svn://localhost/experiments/ svnwork | |
cd svnwork/trunk | |
echo "Mashed Potatoes" >> recipe | |
svn add recipe | |
svn commit -m 'Added recipe.' | |
cd $ROOT | |
git svn clone -s svn://localhost/experiments/ upstream | |
cd upstream | |
rm .git/hooks/* | |
git symbolic-ref HEAD refs/heads/stage | |
rm .git/index | |
git clean -fdx | |
touch .empty | |
git add .empty | |
git ci -am 'Empty stage.' | |
cd $ROOT | |
git clone upstream/ work | |
cd work | |
git checkout master #Get up to date | |
cd $ROOT | |
cat >| build <<BUILD | |
#!/bin/sh | |
grep 'Servings:' recipe >/dev/null 2>&1 | |
BUILD | |
chmod a+x $ROOT/build | |
cat >| $ROOT/upstream/.git/hooks/post-update <<POST | |
#!/bin/bash | |
echo "post-update" | |
DIR=\$(pwd) | |
echo "In \$DIR" | |
export GIT_DIR="\$DIR" | |
export GIT_WORK_TREE="\${DIR%/.git}" | |
echo "GIT: \$GIT_DIR; in \$GIT_WORK_TREE (\`pwd\`)" | |
cd \$GIT_WORK_TREE | |
git checkout master | |
$ROOT/build #CHANGE THIS TO YOUR BUILD LINE | |
BUILT=\$? | |
echo "Build finished with \$BUILT" | |
if [ \$BUILT -eq 0 ] | |
then | |
git svn dcommit | |
else | |
echo "Could not build, not pushing to SVN." | |
fi | |
git checkout stage >/dev/null 2>&1 | |
POST | |
chmod a+x $ROOT/upstream/.git/hooks/post-update | |
cd $ROOT/work | |
cat >> recipe <<ing | |
4 Potatoes, diced | |
salt, 4 cups | |
water, 1 tablespoon | |
ing | |
git ci -am 'Added ingredients list.' | |
git push 2>&1 | tee $ROOT/tmp | |
fgrep "remote: Could not build, not pushing to SVN." $ROOT/tmp || echo "Couldn't find fail line" | |
cd $ROOT/work | |
cat >> recipe <<ing | |
Servings: 3 | |
ing | |
git ci -am 'Added Serving size.' | |
git push 2>&1 | tee $ROOT/tmp | |
fgrep "remote: Resetting to the latest" $ROOT/tmp || echo "Couldn't find fail line" | |
cat >| $ROOT/upstream/.git/hooks/pre-receive <<PRE | |
#!/bin/bash | |
echo "pre-receive" | |
DIR="\$(pwd)" | |
export GIT_DIR="\$DIR" | |
export GIT_WORK_TREE="\${DIR%/.git}" | |
CUR=\$(git rev-list master | wc -l) | |
echo "Before rebase, had \$CUR commits" | |
cd \$GIT_WORK_TREE | |
git checkout master | |
git svn rebase | |
REBASED=\$? | |
git checkout stage >/dev/null 2>&1 | |
if [ -not \$REBASED -eq 0 ] | |
then | |
echo "Rebase failed" | |
exit $REBASED | |
fi | |
POST=\$(git rev-list master | wc -l) | |
echo "After rebase, have \$POST commits" | |
echo "Object counts were \$CUR::\$POST" | |
if [ ! \$CUR = \$POST ] | |
then | |
echo "New changes from SVN, please merge." | |
exit 1 | |
fi | |
echo "pre-receive found SVN is up to date." | |
exit 0 | |
PRE | |
chmod a+x $ROOT/upstream/.git/hooks/pre-receive | |
cd $ROOT/svnwork/trunk | |
svn update | |
cat >| shopping <<LIST | |
Potatoes | |
LIST | |
svn add shopping | |
svn commit -m 'Started a shopping list.' | |
cd $ROOT/work | |
cat >> recipe <<INST | |
Begin by adding salt to the water and bringing it to a boil. | |
INST | |
git ci -am "Added step 1" | |
git pull --rebase #Get upstream changes | |
git push 2>&1 | tee $ROOT/tmp | |
fgrep "New changes from SVN, please merge." $ROOT/tmp || echo "SVN Should be more recent" | |
git pull --rebase | |
git push 2>&1 | tee $ROOT/tmp | |
fgrep "pre-receive found SVN is up to date" $ROOT/tmp || echo "SVN Should be up to date" | |
cd $ROOT/svnwork/trunk | |
svn update | |
sed -i 's/salt, 4 cups/Salt, 4 tablespoons/' recipe | |
svn commit -m 'Reduced the salt level.' | |
cd $ROOT/work | |
git pull --rebase | |
sed -i 's/salt, 4 cups/Salt, 1 tablespoon/' recipe | |
sed -i 's/water, 1 tablespoon/Water, 1 cup/' recipe | |
git ci -am 'Fixed salt/water qty mismatch' | |
git push 2>&1 | tee $ROOT/tmp | |
git pull --rebase | |
ed -s recipe <<ED | |
3d | |
4,6d | |
4s/1/4/ | |
5d | |
w | |
q | |
ED | |
git add recipe | |
git rebase --continue | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment