Skip to content

Instantly share code, notes, and snippets.

@johnpbloch
Created July 4, 2014 04:39
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save johnpbloch/6b96bcd7a88b1d01f7c7 to your computer and use it in GitHub Desktop.
#!/bin/bash
function clean_dir() {
files_to_remove=`ls | grep -v 'composer\.json'`
if [[ "$files_to_remove" ]]; then
rm -r $files_to_remove > /dev/null 2>&1
fi
}
LOCK_FILE='/tmp/updating_wordpress'
if [ -e $LOCK_FILE ]; then
howold=$(($(date +%s) - $(stat -c %Y /tmp/updating_wordpress)))
if [ $howold -lt 2101 ]; then
exit 0
fi
kill -15 $(cat $LOCK_FILE)
rm $LOCK_FILE
fi
echo $$ > $LOCK_FILE
if [ $# -gt 0 ]; then
WP_DIR="$1"
else
WP_DIR='/home/johnpbloch/WP2'
fi
cd $WP_DIR;
# Get all WP Branches
WP_BRANCHES=`curl http://core.svn.wordpress.org/branches/ 2>/dev/null | sed -r 's/.+>([0-9]+(\.[0-9]+)+)\/<.+/\1/;tx;d;:x' | sort -V`
# Get all WP Tags
WP_TAGS=`curl http://core.svn.wordpress.org/tags/ 2>/dev/null | sed -r 's/.+>([0-9]+(\.[0-9]+)+)\/<.+/\1/;tx;d;:x' | sort -V`
# Get all local branches
BRANCHES=`git branch | sed -r 's/.* ([a-zA-Z0-9\.\-\_\/]+).*/\1/' | sort -V`
# Get all local tags
TAGS=`git tag | sort -V`
STARTING_POINT='e653290b75a52096497a85fefd444f647590c06c'
for branch in $WP_BRANCHES; do
if [[ ! `echo "$BRANCHES" | grep -P "^$branch$"` ]]; then
git branch $branch $STARTING_POINT > /dev/null 2>&1
fi
git checkout $branch > /dev/null 2>&1
branch_tags=`echo "$WP_TAGS" | grep -P "^$branch"`
for tag in $branch_tags; do
if [[ ! `echo "$TAGS" | grep -P "^$tag$"` ]]; then
clean_dir
svn export --force --ignore-externals "http://core.svn.wordpress.org/tags/$tag/" . > /dev/null 2>&1
git add -A . > /dev/null 2>&1
git commit -m "Importing version $tag" > /dev/null 2>&1
git tag "$tag" > /dev/null 2>&1
fi
done
clean_dir
svn export --force --ignore-externals "http://core.svn.wordpress.org/branches/$branch/" . > /dev/null 2>&1
git add -A . > /dev/null 2>&1
git commit -m "Updating $branch branch head" > /dev/null 2>&1
done
git checkout master > /dev/null 2>&1
clean_dir
svn export --force --ignore-externals "http://core.svn.wordpress.org/trunk/" . > /dev/null 2>&1
git add -A . #> /dev/null 2>&1
git commit -m "Update trunk" > /dev/null 2>&1
git push > /dev/null 2>&1
git push --tags > /dev/null 2>&1
rm $LOCK_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment