~bac/lpsetup/lxc-integration

« back to all changes in this revision

Viewing changes to lpsetup/subcommands/initrepo.py

  • Committer: Brad Crittenden
  • Date: 2012-07-19 14:08:57 UTC
  • Revision ID: bac@canonical.com-20120719140857-uh0p87zbqqlj38r5
Use a novel repository for launchpad branches to not affect any existing ones.  Use 'bzr pull' to refresh the branch if it already exists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    no_trees = '--no-trees' if is_lightweight else None
51
51
    # Initialize the repository.
52
52
    try:
 
53
        # Skip creating the repository if it already exists.  There is the
 
54
        # risk that it is not made with the same `no_trees` option as
 
55
        # specified here.
53
56
        if not os.path.exists(os.path.join(repository, '.bzr')):
54
57
            call('bzr', 'init-repo', '--quiet', repository, no_trees)
55
58
    except subprocess.CalledProcessError as err:
59
62
    branch_dir = os.path.join(repository, branch_name)
60
63
    # Retrieve the branch.
61
64
    try:
62
 
        cmd = ['bzr', 'branch', source, branch_dir]
63
65
        if os.path.exists(branch_dir):
64
 
            cmd.append('--use-existing-dir')
65
 
        print cmd
 
66
            # The branch already exists, so we pull to refresh it rather than
 
67
            # creating it.
 
68
            cmd = ['bzr', 'pull', '--overwrite', '-d', branch_dir, source]
 
69
        else:
 
70
            cmd = ['bzr', 'branch', source, branch_dir]
66
71
        call(*cmd)
67
72
    except subprocess.CalledProcessError as err:
68
73
        msg = 'Error: unable to branch source: '