def initialise(cls,
                   repository,
                   name=None,
                   msg='initialise',
                   switch_to=False):
        """Initialise a Git branch to handle patch stack.

        :param repository: :class:`Repository` where the :class:`Stack` will be created
        :param name: the name of the :class:`Stack`

        """
        if not name:
            name = repository.current_branch_name
        # make sure that the corresponding Git branch exists
        branch = Branch(repository, name)

        stack_state_ref = _stack_state_ref(name)
        if repository.refs.exists(stack_state_ref):
            raise StackException('%s: stack already initialized' % name)

        if switch_to:
            branch.switch_to()

        stack_state = log.StackState.new_empty(branch.head)
        state_commit = stack_state.commit_state(repository, msg)
        repository.refs.set(stack_state_ref, state_commit, msg)

        return repository.get_stack(name)
Esempio n. 2
0
    def initialise(cls, repository, name=None, switch_to=False):
        """Initialise a Git branch to handle patch series.

        @param repository: The L{Repository} where the L{Stack} will be created
        @param name: The name of the L{Stack}
        """
        if not name:
            name = repository.current_branch_name
        # make sure that the corresponding Git branch exists
        branch = Branch(repository, name)

        dir = os.path.join(repository.directory, cls._repo_subdir, name)
        if os.path.exists(dir):
            raise StackException('%s: branch already initialized' % name)

        if switch_to:
            branch.switch_to()

        # create the stack directory and files
        utils.create_dirs(dir)
        compat_dir = os.path.join(dir, 'patches')
        utils.create_dirs(compat_dir)
        PatchOrder.create(dir)
        config.set(stackupgrade.format_version_key(name),
                   str(stackupgrade.FORMAT_VERSION))

        return repository.get_stack(name)
Esempio n. 3
0
    def initialise(cls, repository, name=None, msg='initialise', switch_to=False):
        """Initialise a Git branch to handle patch series.

        @param repository: The L{Repository} where the L{Stack} will be created
        @param name: The name of the L{Stack}
        """
        if not name:
            name = repository.current_branch_name
        # make sure that the corresponding Git branch exists
        branch = Branch(repository, name)

        stack_state_ref = _stack_state_ref(name)
        if repository.refs.exists(stack_state_ref):
            raise StackException('%s: stack already initialized' % name)

        dir = os.path.join(repository.directory, cls._repo_subdir, name)
        if os.path.exists(dir):
            raise StackException('%s: branch already initialized' % name)

        if switch_to:
            branch.switch_to()

        # create the stack directory and files
        utils.create_dirs(dir)
        compat_dir = os.path.join(dir, 'patches')
        utils.create_dirs(compat_dir)
        PatchOrder.create(dir)
        config.set(
            stackupgrade.format_version_key(name), str(stackupgrade.FORMAT_VERSION)
        )

        state_commit = log.StackState(
            repository,
            prev=None,
            head=branch.head,
            applied=[],
            unapplied=[],
            hidden=[],
            patches={},
            message=msg,
        ).commit_state()
        repository.refs.set(stack_state_ref, state_commit, msg)

        return repository.get_stack(name)