Created
October 9, 2013 03:05
-
-
Save harawata/6895575 to your computer and use it in GitHub Desktop.
A shell script to perform 'svn switch --relocate' in a git-svn repository. - does not require old repo to be accessible.
- does not require any new commit in the new repo. Example usage:
git-svn-relocate "http://oldhost.olddomain.org/" "https://newhost.newdomain.net/" Note: - You need an account for the new repository.
- Backup the local repo (i…
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/sh | |
GIT_CONFIG=".git/config" | |
SVN_DIR=".git/svn" | |
OLD_URL=$1 | |
NEW_URL=$2 | |
if [ -z "$OLD_URL" -o -z "$NEW_URL" ]; then | |
echo "git-svn-relocate OLD_URL NEW_URL" | |
exit 1 | |
fi | |
if [ ! -f $GIT_CONFIG ]; then | |
echo "$GIT_CONFIG not found." | |
exit 1 | |
fi | |
if [ ! -d $SVN_DIR ]; then | |
echo "$SVN_DIR not found." | |
exit 1 | |
fi | |
# STEP 1 : git gc | |
echo "Performing git gc..." | |
git gc | |
if [ $? -ne 0 ]; then | |
echo "git gc failed." | |
exit 1 | |
fi | |
# STEP 2 : Rewrite URL in the history. | |
echo "Rewriting history..." | |
git filter-branch --msg-filter "sed \"s%git-svn-id: ${OLD_URL}%git-svn-id: ${NEW_URL}%g\"" -f $(cat .git/packed-refs | awk '// {print $2}' | grep -v 'pack-refs') | |
if [ $? -ne 0 ]; then | |
echo "git filter-branch failed." | |
exit 1 | |
fi | |
# STEP 3 : Remove svn dir | |
echo "Removing svn directory..." | |
rm -rf "$SVN_DIR" | |
# STEP 4 : Rewrite URL in the config. | |
echo "Rewritng URL in the git config..." | |
sed -i -e "s%${OLD_URL}%${NEW_URL}%g" "$GIT_CONFIG" | |
if [ $? -ne 0 ]; then | |
echo "Failed to rewrite config." | |
exit 1 | |
fi | |
# STEP 5 : Rebase | |
echo "Performing git svn rebase..." | |
git svn rebase | |
if [ $? -ne 0 ]; then | |
echo "git svn rebase failed." | |
exit 1 | |
fi | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment