def execute(
        self,
        msg,
        iw=None,
        set_head=True,
        allow_bad_head=False,
        print_current_patch=True,
    ):
        """Execute the transaction.

        Will either succeed, or fail (with an exception) and do nothing.

        """
        self._check_consistency()
        log_external_mods(self.stack)

        # Set branch head.
        if set_head:
            if iw:
                try:
                    self._checkout(self.head.data.tree, iw, allow_bad_head)
                except CheckoutException:
                    # We have to abort the transaction.
                    # The only state we need to restore is index+worktree.
                    self._checkout(self.stack.head.data.tree,
                                   iw,
                                   allow_bad_head=True)
                    raise TransactionAborted()
            self.stack.set_head(self.head, msg)

        if self._error:
            if self._conflicts:
                out.error(*([self._error] + self._conflicts))
            else:
                out.error(self._error)

        old_applied = self.stack.patchorder.applied
        if self._conflicts:
            msg = '%s (CONFLICT)' % (msg, )

        # Write patches.
        for pn, commit in self.patches.items():
            if pn in self.stack.patches:
                if commit is None:
                    self.stack.patches.delete(pn)
                else:
                    self.stack.patches.update(pn, commit, msg)
            else:
                self.stack.patches.new(pn, commit, msg)
        self.stack.patchorder.set_order(self._applied, self._unapplied,
                                        self._hidden)
        log_stack_state(self.stack, msg)

        if print_current_patch:
            _print_current_patch(old_applied, self._applied)

        if self._error:
            return utils.STGIT_CONFLICT
        else:
            return utils.STGIT_SUCCESS
示例#2
0
    def run(self,
            iw=None,
            set_head=True,
            allow_bad_head=False,
            print_current_patch=True):
        """Execute the transaction. Will either succeed, or fail (with an
        exception) and do nothing."""
        self.__check_consistency()
        log.log_external_mods(self.__stack)
        new_head = self.head

        # Set branch head.
        if set_head:
            if iw:
                try:
                    self.__checkout(new_head.data.tree, iw, allow_bad_head)
                except git.CheckoutException:
                    # We have to abort the transaction.
                    self.abort(iw)
                    self.__abort()
            self.__stack.set_head(new_head, self.__msg)

        if self.__error:
            if self.__conflicts:
                out.error(*([self.__error] + self.__conflicts))
            else:
                out.error(self.__error)

        # Write patches.
        def write(msg):
            for pn, commit in self.__patches.items():
                if self.__stack.patches.exists(pn):
                    p = self.__stack.patches.get(pn)
                    if commit is None:
                        p.delete()
                    else:
                        p.set_commit(commit, msg)
                else:
                    self.__stack.patches.new(pn, commit, msg)
            self.__stack.patchorder.applied = self.__applied
            self.__stack.patchorder.unapplied = self.__unapplied
            self.__stack.patchorder.hidden = self.__hidden
            log.log_entry(self.__stack, msg)

        old_applied = self.__stack.patchorder.applied
        if not self.__conflicts:
            write(self.__msg)
        else:
            write(self.__msg + ' (CONFLICT)')
        if print_current_patch:
            _print_current_patch(old_applied, self.__applied)

        if self.__error:
            return utils.STGIT_CONFLICT
        else:
            return utils.STGIT_SUCCESS
示例#3
0
    def run(self,
            iw=None,
            set_head=True,
            allow_bad_head=False,
            print_current_patch=True):
        """Execute the transaction.

        Will either succeed, or fail (with an exception) and do nothing.

        """
        self._check_consistency()
        log_external_mods(self.stack)
        new_head = self.head

        # Set branch head.
        if set_head:
            if iw:
                try:
                    self._checkout(new_head.data.tree, iw, allow_bad_head)
                except CheckoutException:
                    # We have to abort the transaction.
                    self.abort(iw)
                    self._abort()
            self.stack.set_head(new_head, self._msg)

        if self._error:
            if self._conflicts:
                out.error(*([self._error] + self._conflicts))
            else:
                out.error(self._error)

        old_applied = self.stack.patchorder.applied
        msg = self._msg + (' (CONFLICT)' if self._conflicts else '')

        # Write patches.
        for pn, commit in self.patches.items():
            if pn in self.stack.patches:
                if commit is None:
                    self.stack.patches.delete(pn)
                else:
                    self.stack.patches.update(pn, commit, msg)
            else:
                self.stack.patches.new(pn, commit, msg)
        self.stack.patchorder.set_order(self._applied, self._unapplied,
                                        self._hidden)
        log_stack_state(self.stack, msg)

        if print_current_patch:
            _print_current_patch(old_applied, self._applied)

        if self._error:
            return utils.STGIT_CONFLICT
        else:
            return utils.STGIT_SUCCESS
示例#4
0
    def run(self, iw = None, set_head = True, allow_bad_head = False,
            print_current_patch = True):
        """Execute the transaction. Will either succeed, or fail (with an
        exception) and do nothing."""
        self.__check_consistency()
        log.log_external_mods(self.__stack)
        new_head = self.head

        # Set branch head.
        if set_head:
            if iw:
                try:
                    self.__checkout(new_head.data.tree, iw, allow_bad_head)
                except git.CheckoutException:
                    # We have to abort the transaction.
                    self.abort(iw)
                    self.__abort()
            self.__stack.set_head(new_head, self.__msg)

        if self.__error:
            if self.__conflicts:
                out.error(*([self.__error] + self.__conflicts))
            else:
                out.error(self.__error)

        # Write patches.
        def write(msg):
            for pn, commit in self.__patches.iteritems():
                if self.__stack.patches.exists(pn):
                    p = self.__stack.patches.get(pn)
                    if commit == None:
                        p.delete()
                    else:
                        p.set_commit(commit, msg)
                else:
                    self.__stack.patches.new(pn, commit, msg)
            self.__stack.patchorder.applied = self.__applied
            self.__stack.patchorder.unapplied = self.__unapplied
            self.__stack.patchorder.hidden = self.__hidden
            log.log_entry(self.__stack, msg)
        old_applied = self.__stack.patchorder.applied
        write(self.__msg)
        if self.__conflicting_push != None:
            self.__patches = _TransPatchMap(self.__stack)
            self.__conflicting_push()
            write(self.__msg + ' (CONFLICT)')
        if print_current_patch:
            _print_current_patch(old_applied, self.__applied)

        if self.__error:
            return utils.STGIT_CONFLICT
        else:
            return utils.STGIT_SUCCESS