* git-svn and "svn move" of an entire project
@ 2008-12-14 23:14 Jukka Zitting
0 siblings, 0 replies; only message in thread
From: Jukka Zitting @ 2008-12-14 23:14 UTC (permalink / raw)
To: git
Hi,
I'm hosting git-svn mirrors of many Apache projects [1] and every now
and then I need to deal with cases where an entire project (trunk,
tags, branches, everything) is moved from one location to another
within the svn server. For example in revision 723328 [2] the Apache
Abdera project was moved from incubator/abdera to just abdera.
At [3] I found instructions on how to cope with such situations when
git-svn is used to follow only the svn trunk of a project. Based on
that I came up with the bash script below that allows me to update a
full (init -s) git-svn mirror to point to a new location in svn.
The script seems to work fine but I'm wondering if there's an easier
way to achieve this (and if there are any obvious mistakes in my
script). One alternative is of course to recreate the full git-svn
mirror, but that risks breaking the git history if someone has
meanwhile modified a commit message in svn or changed an author name.
Ideally I'd just run "git svn init" again with the new location and
let git-svn take care of the rest. Unfortunately that doesn't seem to
work and I'm not familiar enough with git-svn internals to know where
to start implementing something like this.
[1] http://jukka.zitting.name/git/
[2] http://svn.apache.org/viewvc?view=rev&revision=723328
[3] http://duncan.mac-vicar.com/blog/archives/282
BR,
Jukka Zitting
----
#!/bin/bash
# Location of the authors file
AUTHORS=/home/jukka/git/authors.txt
# Example:
# move-svn-project.sh /var/git/abdera.git 723328 incubator/abdera abdera
DIR=$1
REV=$2
OLD=$3
NEW=$4
# Set GIT_DIR so all git commands know which repo to use
export GIT_DIR=$DIR
# This function is the main workhorse of this script.
# It takes an existing git-svn branch and updates it
# to point to the first corresponding post-move revision
# in svn. If the branch no longer exists in svn, it is
# removed from here as well.
map() {
REF=$1
URL=$2
echo "Mapping $REF to $URL"
# Keep a backup copy of the original git-svn metadata
cp "$GIT_DIR/svn/.metadata" "$GIT_DIR/svn/.metadata.bak"
# Set up a temporary git-svn remote for just this subtree
git svn init -R tmp -i tmp-git-svn-map-branch "$URL"
# Get the first post-move version of this subtree and modify the branch
git svn fetch -r "$REV" --authors-file "$AUTHORS" tmp
if git rev-parse --verify --quiet refs/remotes/tmp-git-svn-map-branch; then
git update-ref "$REF" refs/remotes/tmp-git-svn-map-branch
else
git update-ref -d "$REF"
fi
# Remove all the temporary git-svn settings
git update-ref -d refs/remotes/tmp-git-svn-map-branch
git config --remove-section svn-remote.tmp
rm -rf $GIT_DIR/svn/tmp-git-svn-map-branch
mv $GIT_DIR/svn/.metadata.bak $GIT_DIR/svn/.metadata
}
# Map all git-svn branches to corresponding new URLs
BASE=$(git config svn-remote.svn.url)
git for-each-ref refs/remotes | cut -d / -f 3- | while read REF; do
case "$REF" in
*@*)
echo "Skipping $REF"
;;
trunk)
map "refs/remotes/trunk" "$BASE/$NEW/trunk"
;;
tags/*)
map "refs/remotes/$REF" "$BASE/$NEW/$REF"
;;
*)
map "refs/remotes/$REF" "$BASE/$NEW/branches/$REF"
;;
esac
done
# Update git-svn configuration to point to the new URLs
for NAME in fetch branches tags; do
VALUE="$(git config svn-remote.svn.$NAME)"
git config "svn-remote.svn.$NAME" "${VALUE/#$OLD/$NEW}"
done
# Clean the old git-svn directory, it'll be regenerated on next update
rm -r "$GIT_DIR/svn"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-12-14 23:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-14 23:14 git-svn and "svn move" of an entire project Jukka Zitting
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.