import os

from fabric.api import run

from braid import package, fails


def install():
    package.install('bzr')


def branch(branch, location):
    if fails('[ -d {}/.bzr ]'.format(location)):
        run('mkdir -p {}'.format(os.path.dirname(location)))
        run('bzr branch {} {}'.format(branch, location))
    else:
        # FIXME (https://github.com/twisted-infra/braid/issues/5)
        # We currently don't check that this the correct branch
        run('bzr update {}'.format(location))

import os

from fabric.api import run

from braid import package, fails


def install():
    package.install('bzr')


def branch(branch, location):
    if fails('[ -d {}/.bzr ]'.format(location)):
        run('mkdir -p {}'.format(os.path.dirname(location)))
        run('bzr branch {} {}'.format(branch, location))
    else:
        run('bzr pull --overwrite -d {} {}'.format(location, branch))

Make bzr always pull from the specified remote.