How to work with bazaar on the command line

From OpenPetra Wiki
Jump to navigation Jump to search

Alternative: use the GUI for bazaar

If the command line is not your prefered way of doing things, please see How to work with bazaar through the GUI on Windows

Setup your environment

Install bazaar.

Set your E-Mail address:

bzr whoami "John Doe <john.doe@gmail.com>"

Create a directory where you want to store all bazaar checkout you are using with openpetra, e.g. C:\openpetra\bzr. Especially when using Windows 7 it is recommended to create a local directory (e.g. on C:) and not one on the network as otherwise compiling with NAnt can give problems.Compiling from a network drive gave the following error on Windows 7:

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, ... failed

Go into this directory and create a shared repository for holding all branches you checkout:

C:\openpetra\bzr>bzr init-repo --no-trees ./
Shared repository (format: 2a)
Location:
  shared repository: .
C:\openpetra\bzr>

On windows set environment variable BZR_SSH for using plink.exe from putty instead of ssh. If plink is in the path, you could use

BZR_SSH=plink

Otherwise you should set BZR_SSH with the absolut path to plink:

BZR_SSH=c:\programs\putty\plink

NOTE: if you path contains a space character, eg. C:\Program Files\PuTTY\plink: you need to replace the part of the path that contains the space character with the 8.3 (MS-DOS)-style name of that directory (e.g. C:\Progra~1\PuTTY\plink) to avoid strange errors when connecting to the Bazaar Server!

If you tortoisebzr is showing a strange language, then you selected perhaps German and you see a different language. Just remove the different languages except for en in %ProgramFiles%\Bazaar\locale\. If the local-folder is not available on your computer you can also set the LANG environment variable to the required language code.

Line Ending issues

To avoid problems with the line endings, and the code generators, on Windows create the file C:\Documents and Settings\My User\Application Data\bazaar\2.0\rules (on Windows 7: C:\Users\My User\AppData\Roaming\bazaar\2.0\rules) and on Linux $BZR_HOME/.bazaar/rules with this content:

[name *.cs]
eol = native
[name *.csproj]
eol = native
[name *.sln]
eol = native
[name *.yaml]
eol = native
[name *.xml]
eol = native
[name *.config]
eol = native
[name *.build]
eol = native
[name *.js]
eol = native
[name *.html]
eol = native
[name *.htm]
eol = native
[name *.sql]
eol = native

See also http://doc.bazaar.canonical.com/development/en/user-reference/eol-help.html

Get files

In our example we will use the URL bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/ for the developer repository. For anonymous access you could use the URL http://bzr.openpetra.org:8008/openpetra/ instead.

With the command

bzr explorer bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/

You could see the history of all active branches

Now you could checkout a branch. The master branch is called trunk (like in subversion) in the shared repo from above, e.g. C:\openpetra\bzr:

bzr checkout bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/trunk

If you want to checkout another branch, just exchange trunk with the branch name

See changed files

bzr status

Graphical Interface

Call the explorer in directory of the branch you are interested in:

bzr explorer ./


Branches

See all branches in OpenPetra:

bzr branches bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/

Alternatively, you can go to this website, which might well be faster as the commandline command is rather slow.

Add a new branch (the directory, where the command is executed, is not relevant):

bzr branch bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/trunk bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/dev_id_whatever

Our naming convention for branches is to use dev_0000<Mantis Issue number>_<keywords to describe the issue>.

Afterwards you need to checkout it out with the command described above (Get files)

For info about your branch, execute in the directory of your checkout:

bzr info

You can branch on a specific revision by using the -r parameter, eg.

bzr branch bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/trunk -r1026.1.4 bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/rel_0.2.6

Rebase branch

For this commands you need to be in the directory, where the checkout files are in.

For the first rebase of the branch, you need to add the info, from where to merge:

bzr merge bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/trunk

This information you see on the operation

bzr info

For the next rebase merges, following command is working:

bzr merge

Checkin the changes:

bzr commit --fixes op:<Mantis Tracker id of the bug that was fixed in this commit>

Update a branch with the newest info from remote

Needed for the getting the newest changes for trunk or for branches, where more then one person is working on:

bzr update


Resolve conflicts during merge or update

http://doc.bazaar.canonical.com/bzr.2.2/en/user-reference/conflict-types-help.html and http://doc.bazaar.canonical.com/bzr.2.2/en/user-guide/resolving_conflicts.html include an overview about problems, which could arise and how they are fixed.

The command

bzr conflicts

shows all conflicts, the command

bzr resolve

marks conflicts as resolved.

Merge to trunk

  1. Checkout or update the trunk branch
  2. Go to the directory of the trunk
  3. Merge in the branch:
    bzr merge bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/dev_id_whatever
  4. Resolve conflicts
  5. bzr commit

Drop a branch

Sometimes a branch has been created by mistake and should be deleted/removed.

bzr rmbranch bzr+ssh://bazaar@bzr.openpetra.org:2208/openpetra/my_wrong_branch

Back out a commit

Backing out a commit is done by merging. First, you should identify the revision number, e.g. 284. Then you are able to undo the commit by merging the difference between 284 and 283:

bzr merge -r 284..283 ./
bzr commit

Commiting to launchpad

If you don't have write privilages on bzr.openpetra.org you can also commit to launchpad. Please see How to commit to launchpad.