Ejemplo n.º 1
0
    def already_synced(self, strategy):
        """Check if already synced

        Check if we are already up to date or if there are changes to
        be applied.
        """

        # if last commit in the strategy was a merge, then the additional
        # branches that were merged in previously can be extracted based on
        # the commits merged.
        if len(strategy) > 0:
            prev_import_merge = strategy[-1]
        else:
            # no changes carried?
            prev_import_merge = None

        additional_commits = None
        if prev_import_merge and len(prev_import_merge.parents) > 1:
            additional_commits = {
                commit for commit in prev_import_merge.parents
                if commit.hexsha != strategy.previous_upstream.hexsha}

            if (additional_commits and
                    len(self.extra_branches) != len(additional_commits)):
                self.log.warning("""
                    **************** WARNING ****************
                    Previous import merged additional branches but none have
                    been specified on the command line for this import.\n""")

        # detect if nothing to do
        if (strategy.previous_upstream.hexsha ==
                self.git.rev_parse(self.upstream)):
            self.log.notice("%s already at latest upstream commit: '%s'",
                            self.branch, strategy.previous_upstream)
            if additional_commits is None:
                self.log.notice("Nothing to be imported")
                return True
            else:
                new_additional_commits = {Commit.new(self.repo, branch)
                                          for branch in self.extra_branches}
                if new_additional_commits == additional_commits:
                    self.log.notice(
                        """
                        No updated additional branch given, nothing to be done
                        """)
                    return True

        return False
Ejemplo n.º 2
0
    def _check_tree_state(self):

        expected = getattr(self, 'expect_found', None)
        # even if empty want to confirm that find no changes applied,
        # otherwise confirm we find the expected number of changes.
        if expected is not None:
            if len(list(Commit.new(self.repo,
                                   self.target_branch).parents)) > 1:
                changes = list(
                    Commit.iter_items(
                        self.repo,
                        '%s..%s^2' %
                        (self.upstream_branch, self.target_branch),
                        topo_order=True))
            else:
                # allow checking that nothing was rebased
                changes = []
            self.assertThat(
                len(changes), Equals(len(expected)),
                "should only have seen %s changes, got: %s" %
                (len(expected), ", ".join([
                    "%s:%s" % (commit.hexsha, commit.message.splitlines()[0])
                    for commit in changes
                ])))

            # expected should be listed in order from oldest to newest, so
            # reverse changes to match as it would be newest to oldest.
            changes.reverse()
            for commit, node in zip(changes, expected):
                if node == "MERGE":
                    continue
                subject = commit.message.splitlines()[0]
                node_subject = self.gittree.graph[node].message.splitlines()[0]
                self.assertThat(
                    subject, Equals(node_subject),
                    "subject '%s' of commit '%s' does not match "
                    "subject '%s' of node '%s'" %
                    (subject, commit.hexsha, node_subject, node))
Ejemplo n.º 3
0
    def _check_tree_state(self):

        expected = getattr(self, 'expect_found', None)
        # even if empty want to confirm that find no changes applied,
        # otherwise confirm we find the expected number of changes.
        if expected is not None:
            if len(list(Commit.new(self.repo,
                                   self.target_branch).parents)) > 1:
                changes = list(Commit.iter_items(
                    self.repo,
                    '%s..%s^2' % (self.upstream_branch, self.target_branch),
                    topo_order=True))
            else:
                # allow checking that nothing was rebased
                changes = []
            self.assertThat(
                len(changes), Equals(len(expected)),
                "should only have seen %s changes, got: %s" %
                (len(expected),
                 ", ".join(["%s:%s" % (commit.hexsha,
                                       commit.message.splitlines()[0])
                           for commit in changes])))

            # expected should be listed in order from oldest to newest, so
            # reverse changes to match as it would be newest to oldest.
            changes.reverse()
            for commit, node in zip(changes, expected):
                if node == "MERGE":
                    continue
                subject = commit.message.splitlines()[0]
                node_subject = self.gittree.graph[node].message.splitlines()[0]
                self.assertThat(subject, Equals(node_subject),
                                "subject '%s' of commit '%s' does not match "
                                "subject '%s' of node '%s'" % (
                                    subject, commit.hexsha, node_subject,
                                    node))