Mirroring branches

Mirroring branches can be useful in many ways, typically to transfer branches between computers, which is essential when collaborating with others. Another common use is to mirror a branch to an external disk or an archive server as a backup measure.

We have already seen that the bzr branch command can create a perfect replica of a branch. However, as the original branch evolves, the replica becomes outdated. Using one of the mirroring commands, it is possible to bring another branch up to date, in sync with the original branch.

Mirroring from another branch

The bzr pull command updates the current branch from another one that is some versions ahead, but not diverged. This is useful when the current branch is used as a mirror of another branch, and no revisions are added to it except when updating from the source branch.

We can simulate such a scenario by creating a branch based on an older revision of another branch. For example:

$ cd /sandbox/hello
$ bzr branch fix-c/ -r-2 sample-for-pull
Branched 7 revisions.

The sample-for-pull branch is now one revision behind the fix-c branch. We can bring it up-to-date by pulling from its parent branch:

$ cd sample-for-pull/
$ bzr pull
Using saved parent location: /sandbox/hello/fix-c/
 M  hello.c                                                                    
All changes applied successfully.                                              
Now on revision 8.

Since we did not specify the branch to pull from, Bazaar used the parent location as a sensible default. As a result, the missing revisions are copied into the current branch and the branch history is also updated accordingly, to be identical to the source branch.

The two branches are now identical, which we can confirm by using the bzr missing command:

$ bzr missing ../fix-c/
Branches are up to date.

When using bzr pull without parameters, Bazaar uses the remembered parent branch. To pull from a different branch and remember that location as the new parent branch, use the --remember flag. For example:

$ bzr pull ../trunk/ --remember
All changes applied successfully.                                              
Now on revision 7.

We can confirm that the parent location has been changed by using the bzr info command:

$ bzr info
Repository tree (format: 2a)
Location:
  shared repository: /sandbox/hello
  repository branch: .

Related branches:
  parent branch: /sandbox/hello/trunk

Mirroring from the current branch

The bzr push command updates another branch based on the current branch to bring it up-to-date, if it has not diverged. This is useful when the other branch is used as a mirror of the current branch, and no revisions are added to it except when updating from the current branch.

We can simulate such a scenario by creating a branch based on an older revision of another branch. For example:

$ cd /sandbox/hello
$ bzr branch fix-c/ -r-2 push-sample
Branched 7 revisions.

The push-sample branch is now one revision behind the fix-c branch. We can bring it up-to-date by pushing to it from the fix-c branch:

$ cd fix-c/
$ bzr push ../push-sample/
All changes applied successfully.                                              
Pushed up to revision 8.

As a result, the missing revisions are copied into the target branch and the branch history is also updated accordingly, to be identical to the source branch.

The two branches are now identical, which we can confirm by using the bzr missing command:

$ bzr missing ../push-sample/
Branches are up to date.

When pushing a branch to another location for the first time, Bazaar remembers to target location as the push branch. We can confirm that by using the bzr info command:

$ bzr info
Repository tree (format: 2a)
Location:
  shared repository: /sandbox/hello
  repository branch: .

Related branches:
    push branch: /sandbox/hello/push-sample
  parent branch: /sandbox/hello/trunk

If you want to push to the same location again, you can use bzr push without parameters.

To push to a different location and remember that location as the new push branch use the --remember flag. For example:

$ bzr push /tmp/push-test --remember
Created new branch.

We can confirm that the push location has been changed:

$ bzr info
Repository tree (format: 2a)
Location:
  shared repository: /sandbox/hello
  repository branch: .

Related 

branches:
    push branch: /tmp/push-test
  parent branch: /sandbox/hello/trunk
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.44.229