Skip to content

Instantly share code, notes, and snippets.

@felixarntz
Created September 22, 2024 19:10
Show Gist options
  • Save felixarntz/cf12fc235a3e8d77753cf46ea1cc3b03 to your computer and use it in GitHub Desktop.
Save felixarntz/cf12fc235a3e8d77753cf46ea1cc3b03 to your computer and use it in GitHub Desktop.
Bash script to manage WordPress git and svn checkouts in the same directory
#!/bin/bash
#
# This scripts updates Git and SVN repos checked out in the same directory.
#
# Pass a branch name like 4.6 as the sole argument to checkout that branch. Otherwise, trunk/trunk is checked out.
#
# Written by Weston Ruter (https://weston.ruter.net/)
cd $( git rev-parse --show-toplevel )
if [[ ! -e .svn ]]; then
echo "Error: Unable to find svn root."
exit 1
fi
if [[ ! -e .git ]]; then
echo "Error: There is no git directory."
exit 1
fi
set -ex
git fetch origin --tags
git_branch=trunk
svn_path='^/trunk'
if [[ ! -z "$1" ]] && [[ "$1" != 'trunk' ]] && [[ "$1" != 'trunk' ]]; then
git_branch="$1"
svn_path="^/branches/$1"
fi
git stash save
svn switch --force "${svn_path}" --ignore-externals
svn revert -R .
git checkout -f "${git_branch}"
git reset --hard "origin/${git_branch}"
svn up --force --accept=theirs-full --ignore-externals
set +x
set +e
echo
echo "----------------------------"
echo "## svn status"
if ! svn status --ignore-externals | grep -Ev '^(\?|\X)'; then
echo 'nothing to commit'
fi
echo
echo "## git status"
git status -uno
@westonruter
Copy link

I just put the script in a standalone repo for better collaboration (still needs a readme): https://github.com/westonruter/svn-git-up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment