4

(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.

Community
  • 1
  • 1
RufusVS
  • 4,008
  • 3
  • 29
  • 40
  • You could reword your question at the top, and keep the old question at the bottom for reference. The top should always be the most relevant part of both questions and answers. And btw it's still really not clear what you're asking for. – janos Jan 07 '14 at 19:34
  • Maybe you can create a new question that explains better what you want. – janos Jan 08 '14 at 21:34
  • your bazaar question is phrased in a bizarre way :-) – S.C. Madsen Jan 08 '14 at 22:29

2 Answers2

2

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).

Reimer Behrends
  • 8,600
  • 15
  • 19
  • Nice script! Just a tiny thing, I would use `$()` style instead of backtick expansion – janos Nov 05 '13 at 14:59
  • Thanks. When I asked the original question, I hadn't realized that the new repository was being automatically repopulated in the act of creating the branches from the old repo. – RufusVS Jan 07 '14 at 19:25
1

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.

janos
  • 120,954
  • 29
  • 226
  • 236
  • One problem with `bzr remove-branch` is that it won't actually remove the revisions from the shared repository. It only affects data within the branch directory. You can still see the old revisions with, e.g., `bzr heads --all`. – Reimer Behrends Nov 05 '13 at 13:05
  • @ReimerBehrends crap. Yeah I was wondering about that. It seems pretty pointless then :( Good you checked! – janos Nov 05 '13 at 14:57
  • 1
    Well, `bzr remove-branch` exists to remove branch directories on a server (where `rm -r` won't work). So, not quite pointless, just a different use case. – Reimer Behrends Nov 05 '13 at 15:05
  • Thanks for the additional information. When I asked the original question, I hadn't realized that the new repository was being automatically repopulated in the act of creating the branches from the old repo. – RufusVS Jan 07 '14 at 19:26