Ejemplo n.º 1
0
    def test_index(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)
        assert commit_list.index(mocked_commit) == 0
Ejemplo n.º 2
0
    def test_index(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)
        assert commit_list.index(mocked_commit) == 0
Ejemplo n.º 3
0
    def test_len(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)

        assert len(commit_list) == 1
Ejemplo n.º 4
0
    def test_repr(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)

        assert repr(commit_list) == repr([mocked_commit])
Ejemplo n.º 5
0
    def test_getitem(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)
        assert commit_list[:1].hashes == ["hexish"]
        assert commit_list[:1].commits == [mocked_commit]
Ejemplo n.º 6
0
    def test_len(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)

        assert len(commit_list) == 1
Ejemplo n.º 7
0
    def test_repr(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)

        assert repr(commit_list) == repr([mocked_commit])
Ejemplo n.º 8
0
    def test_getitem(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)
        assert commit_list[:1].hashes == ["hexish"]
        assert commit_list[:1].commits == [mocked_commit]
Ejemplo n.º 9
0
    def find_diverge_commits(self, first_branch, second_branch):
        """
        Take two branches and find diverge commits.

             2--3--4--5
            /
        1--+              Return:
            \               - common parent: 1
             6              - first list of commits: (2, 3, 4, 5)
                            - second list of commits: (6)

        :param first_branch: first branch to look for common parent
        :type first_branch: `pygit2.Branch`
        :param second_branch: second branch to look for common parent
        :type second_branch: `pygit2.Branch`
        :returns: a namedtuple with common parent, a list of first's branch
        commits and another list with second's branch commits
        :rtype: DivergeCommits (namedtuple)
        """

        common_parent = None
        first_commits = CommitsList()
        second_commits = CommitsList()

        walker = self.walk_branches(GIT_SORT_TOPOLOGICAL, first_branch,
                                    second_branch)

        for first_commit, second_commit in walker:
            if (first_commit in second_commits
                    or second_commit in first_commits):
                break

            if first_commit not in first_commits:
                first_commits.append(first_commit)
            if second_commit not in second_commits:
                second_commits.append(second_commit)

            if second_commit.hex == first_commit.hex:
                break

        try:
            index = second_commits.index(first_commit)
        except ValueError:
            pass
        else:
            second_commits = second_commits[:index]
            common_parent = first_commit

        try:
            index = first_commits.index(second_commit)
        except ValueError:
            pass
        else:
            first_commits = first_commits[:index]
            common_parent = second_commit

        return DivergeCommits(common_parent, first_commits, second_commits)
Ejemplo n.º 10
0
    def find_diverge_commits(self, first_branch, second_branch):
        """
        Take two branches and find diverge commits.

             2--3--4--5
            /
        1--+              Return:
            \               - common parent: 1
             6              - first list of commits: (2, 3, 4, 5)
                            - second list of commits: (6)

        :param first_branch: first branch to look for common parent
        :type first_branch: `pygit2.Branch`
        :param second_branch: second branch to look for common parent
        :type second_branch: `pygit2.Branch`
        :returns: a namedtuple with common parent, a list of first's branch
        commits and another list with second's branch commits
        :rtype: DivergeCommits (namedtuple)
        """

        common_parent = None
        first_commits = CommitsList()
        second_commits = CommitsList()

        walker = self.walk_branches(GIT_SORT_TOPOLOGICAL,
                                    first_branch, second_branch)

        for first_commit, second_commit in walker:
            if (first_commit in second_commits or
               second_commit in first_commits):
                break

            if first_commit not in first_commits:
                first_commits.append(first_commit)
            if second_commit not in second_commits:
                second_commits.append(second_commit)

            if second_commit.hex == first_commit.hex:
                break

        try:
            index = second_commits.index(first_commit)
        except ValueError:
            pass
        else:
            second_commits = second_commits[:index]
            common_parent = first_commit

        try:
            index = first_commits.index(second_commit)
        except ValueError:
            pass
        else:
            first_commits = first_commits[:index]
            common_parent = second_commit

        return DivergeCommits(common_parent, first_commits, second_commits)
Ejemplo n.º 11
0
    def test_iter(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)
        commit_list.append(mocked_commit)

        for commit in commit_list:
            assert commit == mocked_commit
Ejemplo n.º 12
0
    def test_iter(self):
        mocked_commit = MagicMock()
        mocked_commit.hex = "hexish"

        commit_list = CommitsList()
        commit_list.append(mocked_commit)
        commit_list.append(mocked_commit)

        for commit in commit_list:
            assert commit == mocked_commit