Created
November 21, 2018 14:47
-
-
Save georgestephanis/2647f3c7249673dc960723c99bc169fe to your computer and use it in GitHub Desktop.
Make deploying from Git repositories to SVN a bit easier.
This file contains hidden or 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 | |
if [ $# -eq 0 ]; then | |
echo "Run this script from within the root of the git repository that you'd like to deploy." | |
echo "You can only deploy something that's already been tagged in git." | |
echo 'Usage: `deploy-to-svn.sh <tag | HEAD>`' | |
exit 1 | |
fi | |
GIT_DIR=$( pwd ) | |
PLUGIN=$( basename $GIT_DIR ) | |
SVN_DIR="/tmp/wp-plugins/$PLUGIN" | |
TARGET=$1 | |
cd $GIT_DIR | |
# Make sure we don't have uncommitted changes. | |
if [[ -n $( git status -s --porcelain ) ]]; then | |
echo "Uncommitted changes found." | |
echo "Please deal with them and try again clean." | |
exit 1 | |
fi | |
if [ "$TARGET" != "HEAD" ]; then | |
# Make sure we're trying to deploy something that's been tagged. Don't deploy non-tagged. | |
if [ -z $( git tag | grep "^$TARGET$" ) ]; then | |
echo "Tag $TARGET not found in git repository." | |
echo "Please try again with a valid tag." | |
exit 1 | |
fi | |
else | |
read -p "You are about to deploy a change from an unstable state 'HEAD'. This should only be done to update string typos for translators. Are you sure? [y/N]" -n 1 -r | |
if [[ $REPLY != "y" && $REPLY != "Y" ]] | |
then | |
exit 1 | |
fi | |
fi | |
git checkout $TARGET | |
# Prep a home to drop our new files in. Just make it in /tmp so we can start fresh each time. | |
rm -rf $SVN_DIR | |
echo "Checking out SVN shallowly to $SVN_DIR" | |
svn -q checkout "https://plugins.svn.wordpress.org/$PLUGIN/" --depth=empty $SVN_DIR | |
echo "Done!" | |
cd $SVN_DIR | |
echo "Checking out SVN trunk to $SVN_DIR/trunk" | |
svn -q up trunk | |
echo "Done!" | |
echo "Checking out SVN tags shallowly to $SVN_DIR/tags" | |
svn -q up tags --depth=empty | |
echo "Done!" | |
echo "Deleting everything in trunk except for .svn directories" | |
for file in $(find $SVN_DIR/trunk/* -not -path "*.svn*"); do | |
rm $file 2>/dev/null | |
done | |
echo "Done!" | |
echo "Rsync'ing everything over from Git except for .git stuffs and stuff in .svnignore" | |
rsync -r --exclude-from "$GIT_DIR/.svnignore" $GIT_DIR/* $SVN_DIR/trunk | |
echo "Done!" | |
echo "Updating stable tag in readme.txt" | |
perl -pi -e "s/Stable tag: .*/Stable tag: $TARGET/" trunk/readme.txt | |
echo "Now, your turn. Go to $SVN_DIR and add handle adding or removing any files, then tag and commit." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep a
.svnignore
file in your git directory with files and paths that shouldn't get shoved across to svn. It'll probably look something like this: