August 10th, 2007

Adventures with bzr (part 2)

So, after the great success I had converting my existing repository, I decided to try out some scenarios which gave git-svn a hard time.

Scenario 1: Branch from svn into bzr. Make some changes in bzr. Also make some changes in svn. Now, commit changes from bzr back to svn.

Initial test: FAILED. Here's the test case.

#!/bin/sh
set -e
set -x

mkdir test-bzr-svn
cd test-bzr-svn

BASE=$PWD

# Create SVN repository
svnadmin create svnrepo
svn co file://$BASE/svnrepo/ svn
cd svn
echo "asdf" > foo
svn add foo
svn ci -m "first commit"

# Make a branch in BZR, and commit stuff to it:
cd $BASE
bzr branch file://$BASE/svnrepo bzr
cd bzr
echo "sdfg" >> foo
bzr add foo
bzr ci -m "bzr add to foo"
cd ..

# Make a commit in svn.
cd $BASE/svn
echo "newfile!" > newfile
svn add newfile
svn ci -m "added newfile with svn"

cd $BASE/bzr
bzr merge file://$BASE/svnrepo/
bzr ci -m "Merge from svn"
# THIS FAILS with error:
# bzr: ERROR: These branches have diverged.  Try using "merge" and then "push".
bzr push file://$BASE/svnrepo/



A helpful person on #bzr suggested that, while this was likely a bug in bzr-svn, I could probably work around it by using "bzr checkout" to keep a "clean" branch of svn in bzr, and doing all the actual work on a secondary branch.

Test result: PASSED (yay! bzr-svn works!)

#!/bin/sh
set -e
set -x

mkdir test-bzr-svn
cd test-bzr-svn

BASE=$PWD


svnadmin create svnrepo
svn co file://$BASE/svnrepo svn
cd svn
echo "asdf" > foo
svn add foo
svn ci -m "first commit"

cd $BASE
# --dirstate-with-subtree is a secret option that makes bzr-svn
# work inside a shared repository
bzr init-repo --dirstate-with-subtree bzr
cd bzr
bzr checkout file://$BASE/svnrepo trunk
bzr branch trunk branch
cd branch
echo "sdfg" >> foo
bzr ci -m "bzr add to foo"
cd ..

cd $BASE/svn
echo "newfile!" > newfile
svn add newfile
svn ci -m "added newfile with svn"

cd $BASE/bzr/trunk
bzr update
bzr merge ../branch
bzr ci -m "Merge from svn"


Okay, so, we're looking good.

Next up: more complicate branching and merging, simulating multiple developers all using bzr-svn, merging between them, and committing back to svn.

Update: Bug was filed.