Created
September 22, 2024 19:10
-
-
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
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 | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just put the script in a standalone repo for better collaboration (still needs a readme): https://github.com/westonruter/svn-git-up