added svn relocate scripts

This commit is contained in:
Steffen Vogel 2014-07-13 12:40:04 +02:00
parent 8de50b5fe0
commit 88c602082c
2 changed files with 77 additions and 0 deletions

21
bash/git-svn-relocate.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
# Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ]
then
echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
exit $E_NO_ARGS
fi
# Prepare URLs for regex search and replace.
oldUrl=`echo $1 | awk '{gsub("[\\\.]", "\\\\\\\&");print}'`
newUrl=`echo $2 | awk '{gsub("[\\\&]", "\\\\\\\&");print}'`
filter="sed \"s|^git-svn-id: $oldUrl|git-svn-id: $newUrl|g\""
git filter-branch --msg-filter "$filter" -- --all
sed -i.backup -e "s|$oldUrl|$newUrl|g" .git/config
rm -rf .git/svn
git svn rebase

56
bash/git-svn-relocate2.sh Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
# git-svn-switch
# by Justen Hyde based on this blog post:
#
# http://translate.org.za/blogs/wynand/en/content/changing-your-svn-repository-address-git-svn-setup
#
# Use at your own risk. For the love of cthulhu, back
# your repo up before letting this loose on it.
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` {new subversion url}"
exit -1
fi
if [[ $1 = "--help" || $1 = "-h" ]]
then
echo
echo "Usage: `basename $0` {new subversion url}"
echo
echo " Changes the url of the subversion repository a git-svn repo is connected to."
echo " Analogous to svn switch. Potentially a weapon of mass destruction. Use with care."
echo " Run this from within your git repo. You only need one argument: the new url of the svn repo."
echo " git-svn-switch will attempt to verify that the url is at least a svn repo before starting the switch"
echo " but don't depend on it to stop you from doing summat daft."
echo
exit 1
fi
# get the current subversion url
SRC=`git svn info --url`
if [ -n "$SRC" ]
then
FROM=`echo $SRC | sed "s|/trunk||"`
REPO=`svn info $1`
echo "Checking $REPO is actually a subversion repository..."
if [ -n "$REPO" ]
then
echo "The new URL looks valid."
echo "Rewriting the git history with the new url..."
SED_FILTER="sed 's;git-svn-id: "$FROM";git-svn-id: "$1";g'"
git gc
git filter-branch --msg-filter "$SED_FILTER" $(cat .git/packed-refs | awk '// {print $2}' | grep -v 'pack-refs')
#Couple of pointless checkouts - on some repos the log changes seem to need flushing by an operation like this
git checkout trunk
git checkout master
echo "Rebuild git-svn internals and updating the repo"
rm -rf .git/svn
sed -i~ 's|'$FROM'|'$1'|g' .git/config
git svn rebase
else
echo "Error: $1 Does not appear to be a subversion repository."
fi
else
echo "Error: This doesn't appear to be a git working directory, or it's a git repo that hasn't been created using a git-svn bridge"
fi