Example #1
0
    def commit(self, mutable_tree):
        # BUG: not run recursively if in above branch not have changes
        if disable_hooks or not self.read_config():
            return

        from bzrlib.workingtree import WorkingTree
        snapshot = []
        for arg in self.config: # url directory [revisionspec]
            wt = WorkingTree.open(pathjoin(self.root, arg[1]))
            if wt.has_changes(wt.basis_tree()):
                cmd = ['ci']
                os.chdir(wt.basedir)
                try:
                    run_bzr_catch_user_errors(cmd)
                finally:
                    os.chdir(self.cwd)

            if len(arg) < 3:
                arg.append('')
            arg[2] = 'revid:' + wt.last_revision()
            arg[1] = self._quoted_if_need(arg[1])
            snapshot.append(' '.join(arg).encode('utf-8'))

        path = pathjoin(self.root, SNAPSHOT_PATH)
        f = open(path, 'w')
        try:
            f.write('\n'.join(snapshot))
        finally:
            f.close()
Example #2
0
    def run(self, from_location, to_location, revision=None):
        branch = Branch.open_containing('.')[0]
        root = local_path_from_url(branch.base)

        # select what do it
        if isdir(pathjoin(root, to_location, '.bzr')) or isdir(pathjoin(root, to_location, '.svn')):
            if branch.get_bound_location():
                cmd = ['update', to_location]
            else:
                cmd = ['pull', from_location, '--directory', to_location]
        else:
            if branch.get_bound_location():
                cmd = ['checkout', from_location, to_location]
            else:
                cmd = ['branch', from_location, to_location]

            # command branch don't create recursive directory
            dirs = to_location.rpartition('/')
            if dirs[0] != '' and not isdir(dirs[0]):
                os.makedirs(dirs[0].encode(get_user_encoding()))

        # if use revision options but not for 'update'
        if revision is not None:# and cmd[0] != 'update':
            cmd += ['--revision', revision[0].user_spec]

        note('Add external ' + ' '.join(cmd))
        run_bzr_catch_user_errors(cmd)

        bzrmeta = pathjoin(root, '.bzrmeta')
        if not isdir(bzrmeta):
            os.mkdir(bzrmeta)

        # add new branch to config and snapshot files
        line = from_location + ' ' + self._quoted_if_need(to_location)
        if revision:
            line += ' ' + revision[0].user_spec
        self._add_to_file(root, externals.CONFIG_PATH, line)
        self._add_to_file(root, externals.SNAPSHOT_PATH, line)

        # add ignore mask
        from bzrlib import IGNORE_FILENAME
        self._add_to_file(root, IGNORE_FILENAME, './' + to_location)

        # add config files to repository
        cmd = ['add',
            '.bzrignore',
            '.bzrmeta/externals',
            '.bzrmeta/externals-snapshot']
        run_bzr_catch_user_errors(cmd)
Example #3
0
    def run(self, command_list, externals_only=False, shell=False, dry_run=False):
        # TODO: support setting the base location with -d
        externals.disable_hooks = True
        (tree, branch, relpath) = BzrDir.open_containing_tree_or_branch('.')

        global _main_base
        if _main_base is None:
            _main_base = branch.base

        ex = externals.Externals(branch, branch.last_revision(),
            root=tree.basedir)
        if ex.read_config():
            # run ecmd command in each externals for multilevel
            ecmd = ['ecmd']
            if shell:
                ecmd += ['--shell']
            if dry_run:
                ecmd += ['--dry-run']
            ex.adjust_verbosity(ecmd)

            for location, rel_path, revision in ex.branch_iterator(): #@UnusedVariable
                os.chdir(os.path.join(ex.cwd, rel_path))
                run_bzr_catch_user_errors(ecmd + ['--'] + command_list)

        if not externals_only:
            # parse arguments of command and execute
            if not is_quiet():
                if branch.base != _main_base:
                    note('Run command in external: ' + self._relpath(ex.root))
                else:
                    note('Run command in main branch:')
            command_list = self._substitute_in_commandlist(
                command_list, self._relpath(ex.root))
            ex.adjust_verbosity(command_list)
            if not dry_run:
                os.chdir(ex.root)
                if shell:
                    os.system(' '.join(command_list))
                else:
                    run_bzr_catch_user_errors(command_list)

        os.chdir(ex.cwd)
Example #4
0
    def push(self, target):
        if disable_hooks or not self.read_config():
            return

        for location, path, revision in self.branch_iterator(target):
            if location == path:
                # don't push into itself
                continue

            # XXX: maybe he should rather decorate the push command
            # so that we can get the commandline args
            # alternatively the plugin infrastructure must provide it to us?!
            cmd = ['push', location, '--directory', path, '--no-strict']

            if revision is not None:
                # not push if use revision
                continue

            self.adjust_verbosity(cmd)
            self._report(cmd)
            run_bzr_catch_user_errors(cmd)
Example #5
0
    def pull(self):
        if disable_hooks:
            return

        # need use merged config from repository and working tree
        # because new added external branch from repository or working tree
        # need pull/update for correct snapshot
        self.read_config()
        self.read_config_from_repository()
        if len(self.config) == 0:
            return

        for location, path, revision in self.branch_iterator():
            if location == path:
                # not create feature branch for directory above the root
                continue

            # select what do it
            if isdir(pathjoin(path, '.bzr')) or isdir(pathjoin(path, '.svn')):
                if self.bound:
                    cmd = ['update', path]
                else:
                    cmd = ['pull', location, '--directory', path]
            else:
                if self.bound:
                    cmd = ['checkout', location, path]
                else:
                    cmd = ['branch', location, path]

                # command branch don't create recursive directory
                dirs = path.rpartition('/')
                if dirs[0] != '' and not isdir(dirs[0]):
                    os.makedirs(dirs[0].encode(get_user_encoding()))

            # if use revision options but not for 'update'
            if revision is not None:# and cmd[0] != 'update':
                cmd += ['--revision', revision]
            self.adjust_verbosity(cmd)
            self._report(cmd)
            run_bzr_catch_user_errors(cmd)