Created
April 5, 2013 22:13
-
-
Save itsananderson/5323079 to your computer and use it in GitHub Desktop.
Git Bash (Windows) compatible script for publishing Git projects to 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 | |
# args | |
MSG=${1-'deploy from git'} | |
BRANCH=${2-'trunk'} | |
DRY=${3-''} | |
# paths | |
SRC_DIR=$(git rev-parse --show-toplevel) | |
DIR_NAME=$(basename $SRC_DIR) | |
DEST_DIR=../../svn/$DIR_NAME/$BRANCH | |
# build first | |
if [ -f "$SRC_DIR/bin/build" ]; then | |
$SRC_DIR/bin/build | |
fi | |
# make sure we're deploying from the right dir | |
if [ ! -d "$SRC_DIR/.git" ]; then | |
echo "$SRC_DIR doesn't seem to be a git repository" | |
exit | |
fi | |
echo 'Making sure we are up to date' | |
#git pull origin master | |
# make sure the destination dir exists | |
svn mkdir $DEST_DIR 2> /dev/null | |
svn add $DEST_DIR 2> /dev/null | |
# delete everything except .svn dirs | |
for file in $(find $DEST_DIR/* -not -path "*.svn*") | |
do | |
rm -rf $file 2> /dev/null | |
done | |
# copy everything over from git | |
shopt -s extglob | |
cp -R $SRC_DIR/!(*.git*) $DEST_DIR | |
#cp -vR $SRC_DIR/*.md $DEST_DIR | |
cd $DEST_DIR | |
# check .svnignore | |
for file in $(cat "$SRC_DIR/.svnignore" 2> /dev/null) | |
do | |
rm $DEST_DIR/$file -rf | |
done | |
# Transform the readme if one doesn't already exist | |
#if [ -f readme.md ] && [ ! -f readme.txt ]; then | |
# echo 'Converting readme.md' | |
# sed -e 's/^# \(.*\)$/=== \1 ===/' -e 's/ #* ===$/ ===/' -e 's/^## \(.*\)$/== \1 ==/' -e 's/ #* ==$/ ==/' -e 's/^### \(.*\)$/= \1 =/' -e 's/ #* =$/ =/' readme.md > readme.txt | |
# rm readme.md | |
#fi | |
# svn addremove | |
if [ ! -z $DRY ] | |
then | |
echo "Dry Run" | |
svn stat | |
else | |
svn stat | awk '/^\?/ {print $2}' | xargs svn add > /dev/null 2>&1 | |
svn stat | awk '/^\!/ {print $2}' | xargs svn rm --force > /dev/null 2>&1 | |
svn stat | |
svn ci -m "$MSG" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment