Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Created January 24, 2012 22:42
Show Gist options
  • Select an option

  • Save subtleGradient/1673196 to your computer and use it in GitHub Desktop.

Select an option

Save subtleGradient/1673196 to your computer and use it in GitHub Desktop.
Convert a Git repo into a new Subversion repo using brute force commit copying
#!/usr/bin/env bash -l
die () {
echo "[ERROR] $@" 1>&2
exit 1
}
GIT_SRC="$HOME/Projects/Sencha/SDK"
GIT_ROOT="$GIT_SRC-copy"
SVN_REPO="$HOME/Projects/Sencha/sdk-svn-repo"
if [[ ! -d "$SVN_REPO" ]]; then
echo svnadmin-create-init
"$HOME/Projects/SubtleGradient/mirror-github-subversion/bin/svnadmin-create-init" "$SVN_REPO"
fi
if [[ ! -d "$GIT_ROOT" ]]; then
echo "Creating the svn repo" >&2
git clone "$GIT_SRC" "$GIT_ROOT"
cd "$GIT_ROOT"
git svn init --stdlayout "file://$SVN_REPO" "$GIT_ROOT"
git svn fetch
git checkout refs/remotes/trunk -b svn-trunk
git-cherry-punch.sh extjs4.1.0-beta1 > ${TMPDIR}cherry-punch-extjs4.tmp.sh
git update-ref cherry-punched extjs4.1.0-beta1
else
echo > ${TMPDIR}cherry-punch-extjs4.tmp.sh
fi
next-hashes () {
git log --reverse --pretty=format:%H cherry-punched..extjs-4.1.0 2> /dev/null
}
next-hash () {
next-hashes |head -1
}
cd "$GIT_ROOT"
git log -1 cherry-punched > /dev/null || die cherry-punched
git log -1 cherry-punched..extjs-4.1.0 > /dev/null || die cherry-punched..extjs-4.1.0
# NEXT_HASH=$(next-hash)
# git-cherry-punch.sh $NEXT_HASH >> ${TMPDIR}cherry-punch-extjs4.tmp.sh
# for hash in $(next-hashes|head -12); do
for hash in $(next-hashes); do
git-cherry-punch.sh $hash >> ${TMPDIR}cherry-punch-extjs4.tmp.sh
done
cd "$GIT_ROOT"
bash ${TMPDIR}cherry-punch-extjs4.tmp.sh
# mate ${TMPDIR}cherry-punch-extjs4.tmp.sh
echo "Push to svn" >&2
git checkout -f
git svn dcommit --add-author-from
## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
HASH=%H
export GIT_AUTHOR_NAME="%an"; export GIT_AUTHOR_EMAIL="%ae"; export GIT_AUTHOR_DATE="%ad"
export GIT_COMMITTER_NAME="%cn"; export GIT_COMMITTER_EMAIL="%ce"; export GIT_COMMITTER_DATE="%cd"
if [[ ! $(git diff HEAD $HASH) ]]; then
echo "[WARNING] No difference, skipping $HASH" >&2
else
NEW_HASH=$(git log $HASH -1 --pretty=format:"%%B
Commit: %%H
Date: %%aD" | git commit-tree $HASH^{tree} -p HEAD)
git update-ref $(git symbolic-ref HEAD) $NEW_HASH
echo "$NEW_HASH duplicates $HASH"
if [[ $(git diff $HASH $NEW_HASH) ]]; then
echo "Bad diff" >&2
exit 1
fi
if [[ ! $(git log -1 --pretty=format:"%%an") == $GIT_AUTHOR_NAME ]]; then
echo "Bad author" >&2
exit 1
fi
fi
git update-ref cherry-punched $HASH
#!/usr/bin/env bash
git log "$@" -1 --pretty=format:"$(cat "$(dirname "$0")/git-cherry-punch.format.sh")
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment