Skip to content

Instantly share code, notes, and snippets.

@aspiers

aspiers/test.sh Secret

Created October 24, 2012 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspiers/cf334fc594e7f9fab988 to your computer and use it in GitHub Desktop.
Save aspiers/cf334fc594e7f9fab988 to your computer and use it in GitHub Desktop.
#!/bin/bash -ex
# http://stackoverflow.com/questions/12924001/publish-git-repository-to-svn
rm -rf svn-repo svn px2 git-repo
svnadmin create svn-repo
svn_repo=file://`pwd`/svn-repo
svn co $svn_repo svn
cd svn
echo svn1 > svn1
svn add svn1
svn ci -m'add svn1'
cd ..
mkdir px2
git_repo=`pwd`/px2
# first time only: initialize git repo
svn mkdir -m'mkdir fromgit/ProjX' --parents $svn_repo/fromgit/ProjX
(
cd $git_repo
git init
echo git1 > git1
git add git1
git commit -m'add git1'
echo git2 > git2
git add git2
git commit -m'add git2'
git svn init $svn_repo/fromgit/ProjX
git svn fetch
# transplant original git branch onto git-svn branch
root_commit=$( git rev-list --reverse HEAD | head -n1 )
git tag original-git
git reset --hard $root_commit
git reset --soft git-svn
git commit -C $root_commit
# This line requires git >= 1.7.2:
#git cherry-pick $root_commit..original-git
# whereas this should work on old gits:
git rev-list $root_commit..original-git | xargs -n1 git cherry-pick
# As is, this one will move git-svn not master
#git rebase --onto master $root_commit original-git
echo git3 > git3
git add git3
git commit -m'add git3'
)
# simulate new svn check-ins
(
cd svn
svn up
echo svn2 > svn2
svn add svn2
svn ci -m'add svn2'
echo d > fromgit/ProjX/svn3
svn add fromgit/ProjX/svn3
svn ci -m'add fromgit/ProjX/svn3'
)
# fetch latest from svn into git, rebase, and dcommit back to svn
(
cd $git_repo
git svn rebase
git svn dcommit
)
(
cd svn
svn up
svn log -v
)
(
cd $git_repo
gitk --all
)
@skarra
Copy link

skarra commented Feb 27, 2013

Hey, just a quick qn on #L38. There are three occurrences of 'git-svn'; Two are in comments, and L38 is the only other one. When I try to replicate the above commands, I get a "fatal: ambiguous argument 'git-svn': unknown revision or path not in the working tree."

The svn init command I had used in my repo is: git svn init http://agni.cleartrip.com/svn/repos/ct_smallworld/tools/trains-geodata -s. My .git/config looks like this:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[svn-remote "svn"]
url = http://agni.cleartrip.com/svn/repos
fetch = ct_smallworld/tools/trains-geodata/trunk:refs/remotes/trunk
branches = ct_smallworld/tools/trains-geodata/branches/:refs/remotes/
tags = ct_smallworld/tools/trains-geodata/tags/:refs/remotes/tags/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment