Debian/Ubuntu Tips and Tricks

Debuntu

Debian/Ubuntu Tips and Tricks

How-To: Bzr over ssh with no bzr server

Posted by chantra on August 21st, 2008

Bazaar (bzr) is a distributed version control system (VCS) sponsored by Canonical and thus bzr is widely used by the Ubuntu community.

Like any vcs, bzr will let you track the different version of your code locally and let you push the changes to a remote server.

One cool feature of bzr is that you can maintain a remote copy of your code history without having a bzr server running, nor having a copy of bzr on the remote server running and simply by using ssh to transport the data.

This tutorial will not explain how bzr works, but will show the couple few step to create your local repository, add a few files, commit the changes, push them to a remote server and copy the branch newly created to another machine.

1. Client Requirements

In order to use bzr against a bzr server, only bzr is required, but in our case, we want to use ssh to transport the data without the help of a bzr server, e.g. sftp, which will require python-paramiko.

Type the following to install the required package on the client:

$ sudo apt-get install bzr python-paramiko

2. Creating a local bzr branch

First, let's create a directory which will be our branch, create a file and commit it:

$ mkdir testbranch; cd testbranch

$ vi hello.c

#include <stdio.h>
int main(int argc, char** argv){
  fprintf(stdout, "Hello World!\n");
  return 0;
}

Now, let's create the branch, add our file and commit it.

user1@host1: $ bzr init
user1@host1: $ bzr add hello.c
added hello.c
user1@host1: $ bzr commit -m "First commit"
Committing to: /path/to/testbranch/
added hello.c
Committed revision 1.
user1@host1: $ bzr push sftp://ruser1@rhost/path/to/repository/testbranch
Created new branch.

That's it, we now have branch save on rhost at /path/to/repository/testbranch. Let go to another host and fetch a local copy.

3. Importing a copy locally

user2@host2: $ bzr branch sftp://ruser1@rhost/path/to/repository/testbranch
Branched 1 revision(s).
user2@host2: $ cd testbranch
user2@host2: $ bzr log
------------------------------------------------------------
revno: 1
committer: User1 Host1 <user1@host1>
branch nick: testbranch
timestamp: Thu 2008-08-21 18:55:08 +0100
message:
First commit

Now, let's modify hello.c and change "Hello World!\n" to "Hello Bazaar!\n", then commit and push the changes:

user2@host2: $ bzr commit -m "Changed World by Bazaar"
Committing to: /tmp/testbranch/
modified hello.c
Committed revision 2.
user2@host2: $ bzr push sftp://ruser1@rhost/path/to/repository/testbranch
Pushed up to revision 2

4. Importing the new modification

Now back to user1@host1 , let's import the changes locally:

user1@host1: $ bzr pull sftp://ruser1@rhost/path/to/repository/testbranch
M Hello.c
All changes applied successfully.
Now on revision 2.

And check the logs and diff:

user1@host1: $ bzr log
------------------------------------------------------------
revno: 2
committer: User2 Host2 <user2@host2>
branch nick: testbranch
timestamp: Thu 2008-08-21 19:05:37 +0100
message:
Changed World by Bazaar
------------------------------------------------------------
revno: 1
committer: User1 Host1 <user1@host1>
branch nick: testbranch
timestamp: Thu 2008-08-21 18:55:08 +0100
message:
First commit
user1@host1: $ bzr diff -r-2..
=== modified file 'hello.c'
--- hello.c 2008-08-21 17:55:08 +0000
+++ hello.c 2008-08-21 18:05:17 +0000
@@ -3,7 +3,7 @@


int main(int argc, char** argv){


- fprintf(stdout, "Hello World!\n");
+ fprintf(stdout, "Hello Bazaar!\n");
return 0;
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>