Last active
August 29, 2015 14:09
-
-
Save westonruter/c2a54f9f271a6e9023a8 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
/data |
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/bash | |
set -e | |
cd "$1" | |
git_dir="$(pwd)" | |
cd - > /dev/null | |
cd "$2" | |
svn_dir="$(pwd)" | |
cd - > /dev/null | |
cd $git_dir | |
git pull | |
git_commit_hash=$( git rev-parse HEAD | cut -c1-7 ) | |
git_remote_url=$( git config --get remote.origin.url ) | |
cd $svn_dir | |
svn up | |
rsync -avz --delete --exclude='.git*' --exclude='.svn*' $git_dir/ $svn_dir/ | |
if [ 0 == $( svn status | wc -l ) ]; then | |
echo "No changes to commit." | |
exit 0 | |
fi | |
svn status | grep '^\?' | awk "{print \$2}" | xargs svn add | |
svn status | grep '^\!' | awk "{print \$2}" | xargs svn rm | |
if [ -f .gitlasthead ]; then | |
echo -e "Update to $(cat .gitlasthead)...${git_commit_hash} from ${git_remote_url}\n" > .svncommitmsg | |
echo "BEGIN-GIT-LOG" >> .svncommitmsg | |
# @todo | perl -pe '$_ = join "", <>; s/BEGIN-SVN-LOG.+?END-SVN-LOG//sg; print;' | |
git --git-dir="$git_dir/.git" log $(cat .gitlasthead)...${git_commit_hash} -- . | sed 's/^/> /' >> .svncommitmsg | |
echo "END-GIT-LOG" >> .svncommitmsg | |
else | |
echo "Update to ${git_commit_hash} of ${git_remote_url}" > .svncommitmsg | |
fi | |
svn commit -F .svncommitmsg | |
rm .svncommitmsg | |
svn up | |
echo "$git_commit_hash" > .gitlasthead |
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/bash | |
set -e | |
cd "$(dirname $0)" | |
root_directory="$(pwd)" | |
if [ -e data ]; then | |
rm -rf data | |
fi | |
mkdir data | |
cd data | |
svnadmin create --fs-type fsfs svn-origin | |
svn checkout file://$(pwd)/svn-origin svn | |
git init --bare git-origin | |
git clone git-origin git | |
echo "Hello world" > svn/example.txt | |
cp svn/example.txt git | |
cd svn | |
svn add example.txt | |
svn propset svn:ignore -F $root_directory/repo.svnignore . | |
svn commit -m "Initial commit" | |
svn up | |
cd ../git | |
cp $root_directory/repo.gitignore .gitignore | |
git add .gitignore | |
git add example.txt | |
git commit -m "Initial commit" | |
git push | |
# @todo Should there be a config file in the directory above the git and svn clones which indicate their remotes? | |
# @todo We should only do commits to an svn branch in git, and then see if merges succeed |
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
.svn* |
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
.git* | |
README.md | |
CONTRIBUTING.md | |
*.scss | |
*.less | |
*.map | |
.svn* |
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/bash | |
set -e | |
cd "$1" | |
svn_dir="$(pwd)" | |
cd - > /dev/null | |
cd "$2" | |
git_dir="$(pwd)" | |
cd - > /dev/null | |
cd $svn_dir | |
svn up | |
svn_revision=$( svn info | grep 'Last Changed Rev' | awk '{ print $4; }' ) | |
svn_url=$( svn info | grep '^URL:' | awk '{ print $2; }' ) | |
cd $git_dir | |
git pull | |
rsync -avz --delete --exclude='.git*' --exclude='.svn*' $svn_dir/ $git_dir/ | |
git add -A . | |
if [ -f .svnlastrev ]; then | |
echo -e "Update to r$(cat .svnlastrev):${svn_revision} from ${svn_url}\n" > .gitcommitmsg | |
echo "BEGIN-SVN-LOG" >> .gitcommitmsg | |
# @todo | perl -pe '$_ = join "", <>; s/BEGIN-GIT-LOG.+?END-GIT-LOG//sg; print;' | |
svn log -r "$(cat .svnlastrev):${svn_revision}" $svn_url | sed 's/^/> /' >> .gitcommitmsg | |
echo "END-SVN-LOG" >> .gitcommitmsg | |
else | |
echo "Update to r${svn_revision} from ${svn_url}" > .gitcommitmsg | |
fi | |
git commit -F .gitcommitmsg | |
rm .gitcommitmsg | |
git push | |
echo "$svn_revision" > .svnlastrev |
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/bash | |
echo "Adding a file to Git and syncing to SVN..." | |
cd data/git | |
echo food > food.txt | |
git add food.txt | |
git commit -m "Add food.txt" || echo "Nothing to commit" | |
cd - > /dev/null | |
./git-to-svn.sh data/git/ data/svn/ | |
echo "#############################" | |
echo "Adding a file to SVN and syncing to Git..." | |
cd data/svn | |
echo bard > bard.txt | |
svn add bard.txt | |
svn commit -m "Add bard.txt" || echo "Nothing to commit" | |
cd - > /dev/null | |
./svn-to-git.sh data/svn/ data/git/ | |
echo "#############################" | |
echo "Adding a directory to Git and syncing to SVN..." | |
cd data/git | |
mkdir quux | |
echo quux > quux/quux.txt | |
git add quux/quux.txt | |
git commit -m "Add quux" | |
git push | |
cd - > /dev/null | |
./git-to-svn.sh data/git/ data/svn/ | |
echo "#############################" | |
echo "Adding a directory to SVN and syncing to Git..." | |
cd data/svn | |
mkdir baz | |
echo baz > baz/baz.txt | |
svn add baz | |
svn commit -m "Add baz.txt" || echo "Nothing to commit" | |
cd - > /dev/null | |
./svn-to-git.sh data/svn/ data/git/ | |
echo "#############################" | |
echo "Modify a file in Git..." | |
cd data/git | |
echo FOODY > food.txt | |
git add food.txt | |
git commit -m "Make FOODY" || echo "Nothing to commit" | |
cd - > /dev/null | |
./git-to-svn.sh data/git/ data/svn/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment