Question

(EDIT: Removed my question, leaving a link to the question that confused me, because there's some useful stuff in some of the comments here)

The question here confused me, but was actually answered fully. That question asked how to build a new repository with only a few of the branches of the original repository.

Was it helpful?

Solution

I'm not entirely sure from your post what you're looking for. I'm taking a stab at giving an answer; let me know if that's not what you need.

The following is a simple script to copy all branches from a source to a target repo. Note that it won't work if the branch directory names contain any whitespace. You will have to setup the target repository with bzr init-repo first.

#!/bin/sh
SOURCEREPO=$1
TARGETREPO=$2
if [ ! -d "$TARGETREPO/.bzr" ]; then
  echo "$TARGETREPO is not a Bazaar repository; create one with bzr init-repo"
  exit 1
fi
BRANCHES=`cd "$SOURCEREPO"; find * -name .bzr -exec dirname '{}' ';'`
for branch in $BRANCHES; do
  mkdir -p "$TARGETREPO/$branch"
  if [ ! -d "$TARGETREPO/$branch/.bzr" ]; then
    echo "Cloning $branch"
    bzr branch --use-existing-dir "$SOURCEREPO/$branch" "$TARGETREPO/$branch" \
    && bzr config -d "$TARGETREPO/$branch" --remove parent_location
  else
    echo "Existing branch in $TARGETREPO/$branch"
  fi
done

Basically, it does a bzr branch sourcerepo/branchdir targetrepo/branchdir for all branches and then uses bzr config to get rid of the parent location setting for each copy of a branch (because that location will presumably soon disappear).

OTHER TIPS

I'm not quite sure what you really want here. Adding a remote branch to your local repository and recreating a repository from another are completely different things. The linked question is about the second, and the answers are spot-on, so I will address what you originally intended to do.

First of all, it's confusing when you say "main trunk repository", because "trunk" typically means a "main branch", and branches and repositories are different concepts, so "trunk repository" doesn't really make sense.

It seems to me that you have a shared repository: a container directory for multiple branches. For the sake of clarity: you create a shared repository with the command bzr init-repo, and you create branches in it with bzr init (new empty branch), or with bzr branch (copy of another branch, local or not).

Let's say you have a shared repository organized like this:

└── /tmp/shared/repo
    ├── bugfix123
    ├── feature1
    └── feature2

If you want to add remote branches of your teammates, you can do it with:

bzr branch url_of_remote_branch /tmp/shared/repo/somename

For example if your teammate has a branch at the url lp:~jack/proj/bugfix312 you could get it into your local repository with:

bzr branch lp:~jack/proj/bugfix312 /tmp/shared/repo/bugfix312

If later you decide you don't want to merge this branch, you can get rid of it with the commands:

bzr remove-branch /tmp/shared/repo/bugfix312
rm -fr /tmp/shared/repo/bugfix312

The first command only removes Bazaar's branch data, it keeps the directory intact. The second removes the working directory itself.

Let me know if you are looking for something else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top