Skip to content

Commit 4900cd4

Browse files
committed
Modifications done as per Ben's suggestions.
A big thank-you to Jean-Noël Avila for his help.
1 parent c85bf5f commit 4900cd4

File tree

2 files changed

+73
-60
lines changed

2 files changed

+73
-60
lines changed

book/09-git-and-other-scms/sections/client-bzr.asc

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
==== Git and Bazaar
22

3+
Among the DVCS, another famous one is http://bazaar.canonical.com/[Bazaar].
4+
Bazaar is free and open source, and is part of the http://www.gnu.org/[GNU Project].
5+
It behaves very differently from Git.
6+
Sometimes, to do the same thing as with Git, you have to use a different keyword, and some keywords that are common don't have the same meaning.
7+
In particular, the branch management is very different and may cause confusion, especially when someone comes from Git's universe.
8+
Nevertheless, it is possible to work on a Bazaar repository from a Git one.
9+
310
There are many projects that allow you to use Git as a Bazaar client.
411
Here we'll use Felipe Contreras' project that you may find at https://github.com/felipec/git-remote-bzr[].
512
To install it, you just have to download the file git-remote-bzr in a folder contained in your `$PATH`:
@@ -10,15 +17,14 @@ $ chmod +x ~/bin/git-remote-bzr
1017
----
1118

1219
You also need to have Bazaar installed.
13-
1420
That's all!
1521

1622
===== Create a Git repository from a Bazaar repository
1723

1824
It is simple to use.
1925
It is enough to clone a Bazaar repository prefixing it by `bzr::`.
20-
If you worked in a local Bazaar repository and pushed to a remote one, it is better to clone the remote.
21-
That will make your work simpler; else you must go through your local repository and you may have problems when pushing to the remote if your Bazaar and Git repositories were not up-to-date.
26+
Since Git and Bazaar both do full clones to your machine, it's possible to attach a Git clone to your local Bazaar clone, but it isn't recommended.
27+
It's much easier to attach your Git clone directly to the same place your Bazaar clone is attached to ‒ the central repository.
2228

2329
Let's suppose that you worked with a remote repository which is at address `bzr+ssh://developer@mybazaarserver:myproject`.
2430
Then you must clone it in the following way:
@@ -28,7 +34,8 @@ $ git clone bzr::bzr+ssh://developer@mybazaarserver:myproject myProject-Git
2834
$ cd myProject-Git
2935
----
3036

31-
You should also clean and compact the created Git repository, especially if it is a big one:
37+
At this point, your Git repository is created but it is not optimized at the point of view of its disk size.
38+
That's why you should also clean and compact your Git repository, especially if it is a big one:
3239
[source,console]
3340
----
3441
$ git gc --aggressive
@@ -40,7 +47,7 @@ Bazaar only allows you to clone branches, but a repository may contain several b
4047
For example, to clone a branch:
4148
[source,console]
4249
----
43-
$ git config remote-bzr.branches 'trunk, xwindow'
50+
$ git clone bzr::bzr://bzr.savannah.gnu.org/emacs/trunk emacs-trunk
4451
----
4552

4653
And to clone the whole repository:
@@ -67,7 +74,7 @@ $ git fetch
6774

6875
===== Ignore what is ignored with .bzrignore
6976

70-
As the format of the .bzrignore file is completely compatible with .gitignore's one, and as you shouldn't make a .gitignore file in your repository, it is enough to make a symbolic link to .bzrignore so that the potential changes of .bzrignore are taken into account:
77+
As the format of the `.bzrignore` file is completely compatible with `.gitignore`'s one, and as you shouldn't make a `.gitignore` file in your repository, it is enough to make a symbolic link to `.bzrignore` so that the potential changes of `.bzrignore` are taken into account:
7178
[source,console]
7279
----
7380
$ ln -s .bzrignore .git/info/exclude
@@ -84,6 +91,8 @@ $ git pull --rebase origin
8491

8592
===== Push your work on the remote repository
8693

94+
Because Bazaar supports very well merge commits, there will be no problem if you push a merge commit.
95+
So you can work on a branch, merge the changes into `master` and push your work.
8796
Then, you create your branches, you test and commit your work as usual.
8897
You finally push your work to the Bazaar repository:
8998
[source,console]
@@ -93,10 +102,13 @@ $ git push origin master
93102

94103
===== Caveats
95104

96-
There are some limitations while pushing to a Bazaar repository.
97-
Please refer to the README file of the project's Git repository (https://github.com/felipec/git-remote-bzr[]) for more information about this.
105+
Limitations of the remote-helpers' framework apply. In particular, these commands don't work:
106+
107+
* git push origin :branch-to-delete (Bazaar can't accept ref deletions in this way.)
108+
* git push origin old:new (it will push 'old')
109+
* git push --dry-run origin branch (it will push)
98110

99111
===== Summary
100112

101-
As Git and Bazaar are close, you can work in a Git repository and transparently push your work to a Bazaar repository.
102-
Be careful anyway to the limitations.
113+
Since Git's and Bazaar's models are similar, there isn't a lot of resistance when working across the boundary.
114+
As long as you watch out for the limitations, and are always aware that the remote repository isn't natively Git, you'll be fine.

book/09-git-and-other-scms/sections/import-bzr.asc

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,78 @@
11
==== Bazaar
22
(((Bazaar)))(((Importing, from Bazaar)))
33

4-
Bazaar is a distributed source management content like Git.
5-
It is very easy to convert a Bazaar repository into a Git repository thanks to Bazaar's plugin system.
6-
To convert a Bazaar repository into a Git repository, you have first to import the bzr-fastimport plugin.
7-
Here is the whole procedure if you have not yet imported any plugin:
4+
Bazaar is a DVCS tool much like Git, and as a result it's pretty straightforward to convert a Bazaar repository into a Git one.
5+
To accomplish this, you'll need to import the `bzr-fastimport` plugin.
6+
7+
8+
===== Getting the bzr-fastimport plugin
9+
10+
According to you are using a UNIX-like operating system or Windows, the procedure differs.
11+
If you are using a UNIX-like operating system, the simplest is to install the `bzr-fastimport` package that will install all the required dependencies.
12+
13+
For example, with Debian and derived, you would do the following:
814
[source,console]
915
----
10-
$ mkdir --parents ~/.bazaar/plugins/bzr # creates the necessary folders for the plugins
11-
$ cd ~/.bazaar/plugins/bzr
12-
$ bzr branch lp:bzr-fastimport fastimport # imports the fastimport plugin
13-
$ cd fastimport
14-
$ sudo python setup.py install --record=files.txt
16+
$ sudo apt-get install bzr-fastimport
1517
----
1618

17-
There you go!
18-
You've just installed the fastimport plugin.
19-
20-
21-
===== Case of a project with a single branch
19+
With RHEL, you would do the following:
20+
[source,console]
21+
----
22+
$ sudo yum install bzr-fast-import
23+
----
2224

23-
Now go in the directory that contains your Bazaar repository and initialize the Git repository:
25+
With Fedora, since release 22, the new package manager is dnf:
2426
[source,console]
2527
----
26-
$ cd path/to/the/bzr/repository
27-
$ git init
28+
$ sudo dnf install bzr-fastimport
2829
----
2930

30-
Now, you can simply export your Bazaar repository and convert it into a Git repository using the following command:
31+
If the package is not available, you may install it as a plugin:
3132
[source,console]
3233
----
33-
$ bzr fast-export --plain . | git fast-import
34+
$ mkdir --parents ~/.bazaar/plugins/bzr # creates the necessary folders for the plugins
35+
$ cd ~/.bazaar/plugins/bzr
36+
$ bzr branch lp:bzr-fastimport fastimport # imports the fastimport plugin
37+
$ cd fastimport
38+
$ sudo python setup.py install --record=files.txt # installs the plugin
3439
----
3540

36-
You may get the following error message:
41+
For this plugin to work, you'll also need the `fastimport` Python module.
42+
You can check whether it is present or not and install it with the following commands:
3743
[source,console]
3844
----
39-
bzr: ERROR: Unable to import library "fastimport": bzr-fastimport requires the fastimport python module
45+
$ python -c "import fastimport"
46+
Traceback (most recent call last):
47+
File "<string>", line 1, in <module>
48+
ImportError: No module named fastimport
49+
$ pip install fastimport
4050
----
51+
If it is not available, you can download it at address https://pypi.python.org/pypi/fastimport/.
52+
53+
With Windows, `bzr-fastimport` is automatically installed with the standalone version and the default installation (let all the checkboxes checked).
54+
So in this case you have nothing to do.
4155

42-
This message is displayed because the fastimport python module that the `bzr fast-export` command needs is missing.
43-
Install it from your package manager if you are under GNU/Linux or download it at address https://pypi.python.org/pypi/fastimport/[] if you are under Windows.
44-
For example, with Fedora, you would do the following:
56+
At this point, the way to import a Bazaar repository differs according to that you have a single branch or you are working with a repository that has several branches.
4557

58+
===== Case of a project with a single branch
59+
60+
Now `cd` in the directory that contains your Bazaar repository and initialize the Git repository:
4661
[source,console]
4762
----
48-
$ sudo dnf install python-fastimport
63+
$ cd /path/to/the/bzr/repository
64+
$ git init
4965
----
5066

51-
Now you can export your Bazaar repository to the Git repository.
67+
Now, you can simply export your Bazaar repository and convert it into a Git repository using the following command:
68+
[source,console]
69+
----
70+
$ bzr fast-export --plain . | git fast-import
71+
----
5272

5373
Depending on the size of the project, your Git repository is built in a lapse from a few seconds to a few minutes.
5474

55-
At this point, if you type `git status`, you'll see that the tracked files are now marked as removed for the next commit.
56-
Here is an example:
75+
At this point, the `.git` directory and your working tree are all set up, but Git's index isn't synchronised with the working tree:
5776
[source,console]
5877
----
5978
$ git status
@@ -71,38 +90,20 @@ Untracked files:
7190
.bzrignore
7291
file.txt
7392
----
74-
75-
You can restore the repository in a correct state very simply with the `git reset` command:
93+
Type this to fix that:
7694
[source,console]
7795
----
7896
$ git reset HEAD .
7997
----
8098

8199
Now let us have a look at the files to ignore.
82-
As .bzrignore's format is completely compatible with .gitignore's format, the simplest is to rename your .bzrignore file:
100+
As `.bzrignore`'s format is completely compatible with `.gitignore`'s format, the simplest is to rename your `.bzrignore` file:
83101
[source,console]
84102
----
85103
$ git mv .bzrignore .gitignore
86104
----
87105

88-
Let us check your repository's status:
89-
[source,console]
90-
----
91-
$ git status
92-
On master branch
93-
Changes that will be validated :
94-
(use "git reset HEAD <fichier>..." to unstage)
95-
96-
renamed : .bzrignore -> .gitignore
97-
98-
Untracked files:
99-
(use "git add <fichier>..." to include in what will be validated)
100-
101-
.bzr/
102-
103-
----
104-
105-
Then you have to create a commit that contains those changes for the migration:
106+
Then you have to create a commit that contains this change for the migration:
106107
[source,console]
107108
----
108109
$ git commit -am 'Migration from Bazaar to Git'
@@ -127,7 +128,7 @@ $ ls
127128
myProject.trunk myProject.work
128129
----
129130

130-
Create the Git repository and go into it:
131+
Create the Git repository and `cd` into it:
131132
[source,console]
132133
----
133134
$ git init git-repo

0 commit comments

Comments
 (0)