Пример #1
0
def main():
    # Get values from ENV Variables
    repo_location = os.environ.get("INPUT_REPO_LOCATION", ".") + "/.git"
    current_commit = os.environ.get("INPUT_CURRENT_COMMIT", "")
    pretty = os.environ.get("INPUT_PRETTY_OUTPUT", "false")

    # Find commit values from Repository.
    if current_commit == "":
        current_commit = git.current_commit(repo_location)

    parent_commits = git.commit_parents(repo_location, current_commit)

    # Define empty commits list to store commits in build history.
    commits = []

    # Get all of the commits in the branch since it seperated from the 
    # current branch.
    if len(parent_commits) > 1:
        merge_base_commit = git.commit_merge_base(
            repo_location, 
            parent_commits[0], 
            parent_commits[1]
        )

        # Iterate over the git history like a linked list
        # adding every commit
        current = [parent_commits[1]]
        while (merge_base_commit not in current):
            commits = commits + current
            current = git.commit_parents(repo_location, current[0])

    print(f"""::set-output name=commits::{json.dumps(commits)}""")
    if pretty.lower() == "true":
        print("Merge Commits:")
        for merge_commit in commits:
            print("   --> " + merge_commit)
Пример #2
0
    def base_rev_for_display(self):
        """The rev as reference to determine what changed in this commit.

        RETURN VALUE
            The reference commit's SHA1, or None if this commit does not
            have a parent (root commit).
        """
        # Make sure we use each commits's first parent as the base
        # commit.  This is important for merge commits, or commits
        # imported by merges.
        #
        # Consider for instance the following scenario...
        #
        #                    <-- origin/master
        #                   /
        #    C1 <-- C2 <-- C3 <-- M4 <-- master
        #      \                  /
        #        <-- B1 <-- B2 <-+
        #
        # ... where the user merged his changes B1 & B2 into
        # his master branch (as commit M4), and then tries
        # to push this merge.
        #
        # There are 3 new commits in this case to be checked,
        # which are B1, B2, and M4, with C3 being the update's
        # base rev.
        #
        # If not careful, we would be checking B1 against C3,
        # rather than C1, which would cause these scripts
        # to think that all the files modified by C2 and C3
        # have been modified by B1, and thus must be checked.
        #
        # Similarly, we would be checking M4 against B2,
        # whereas it makes more sense in that case to be
        # checking it against C3.
        if self.parent_revs is None:
            self.parent_revs = commit_parents(self.rev)
        if self.parent_revs:
            return self.parent_revs[0]
        else:
            return None
Пример #3
0
    def base_rev_for_display(self):
        """The rev as reference to determine what changed in this commit.

        RETURN VALUE
            The reference commit's SHA1, or None if this commit does not
            have a parent (root commit).
        """
        # Make sure we use each commits's first parent as the base
        # commit.  This is important for merge commits, or commits
        # imported by merges.
        #
        # Consider for instance the following scenario...
        #
        #                    <-- origin/master
        #                   /
        #    C1 <-- C2 <-- C3 <-- M4 <-- master
        #      \                  /
        #        <-- B1 <-- B2 <-+
        #
        # ... where the user merged his changes B1 & B2 into
        # his master branch (as commit M4), and then tries
        # to push this merge.
        #
        # There are 3 new commits in this case to be checked,
        # which are B1, B2, and M4, with C3 being the update's
        # base rev.
        #
        # If not careful, we would be checking B1 against C3,
        # rather than C1, which would cause these scripts
        # to think that all the files modified by C2 and C3
        # have been modified by B1, and thus must be checked.
        #
        # Similarly, we would be checking M4 against B2,
        # whereas it makes more sense in that case to be
        # checking it against C3.
        if self.parent_revs is None:
            self.parent_revs = commit_parents(self.rev)
        if self.parent_revs:
            return self.parent_revs[0]
        else:
            return None
Пример #4
0
    def __get_added_commits(self):
        """Return a list of CommitInfo objects added by our update.

        RETURN VALUE
            A list of CommitInfo objects, or the empty list if
            the update did not introduce any new commit.
        """
        if is_null_rev(self.new_rev):
            return []

        # Compute the list of commits that are not accessible from
        # any of the references.  These are the commits which are
        # new in the repository.
        #
        # Note that we do not use the commit_info_list function for
        # that, because we only need the commit hashes, and a list
        # of commit hashes is more convenient for what we want to do
        # than a list of CommitInfo objects.

        exclude = [
            '^%s' % self.all_refs[ref_name]
            for ref_name in self.all_refs.keys() if ref_name != self.ref_name
        ]
        if not is_null_rev(self.old_rev):
            exclude.append('^%s' % self.old_rev)

        new_repo_revs = git.rev_list(self.new_rev,
                                     *exclude,
                                     reverse=True,
                                     _split_lines=True)

        # If this is a reference creation (base_rev is null), try to
        # find a commit which can serve as base_rev.  We try to find
        # a pre-existing commit making the base_rev..new_rev list
        # as short as possible.
        base_rev = self.old_rev
        if is_null_rev(base_rev):
            if len(new_repo_revs) > 0:
                # The ref update brings some new commits.  The first
                # parent of the oldest of those commits, if it exists,
                # seems like a good candidate.  If it does not exist,
                # we are pushing an entirely new headless branch, and
                # base_rev should remain null.
                parents = commit_parents(new_repo_revs[0])
                if parents:
                    base_rev = parents[0]
            else:
                # This reference update does not bring any new commits
                # at all. This means new_rev is already accessible
                # through one of the references, thus making it a good
                # base_rev as well.
                base_rev = self.new_rev

        # Expand base_rev..new_rev to compute the list of commits which
        # are new for the reference.  If there is no actual base_rev
        # (Eg. a headless branch), then expand to all commits accessible
        # from that reference.
        if not is_null_rev(base_rev):
            commit_list = commit_info_list(self.new_rev, '^%s' % base_rev)
            base_rev = commit_rev(base_rev)
        else:
            commit_list = commit_info_list(self.new_rev)
            base_rev = None

        # Iterate over every commit, and set their pre_existing_p attribute.
        for commit in commit_list:
            commit.pre_existing_p = commit.rev not in new_repo_revs

        debug('update base: %s' % base_rev)

        return commit_list
Пример #5
0
    def __get_added_commits(self):
        """Return a list of CommitInfo objects added by our update.

        RETURN VALUE
            A list of CommitInfo objects, or the empty list if
            the update did not introduce any new commit.
        """
        if is_null_rev(self.new_rev):
            return []

        # Compute the list of commits that are not accessible from
        # any of the references.  These are the commits which are
        # new in the repository.
        #
        # Note that we do not use the commit_info_list function for
        # that, because we only need the commit hashes, and a list
        # of commit hashes is more convenient for what we want to do
        # than a list of CommitInfo objects.

        exclude = ['^%s' % self.all_refs[ref_name]
                   for ref_name in self.all_refs.keys()
                   if ref_name != self.ref_name]
        if not is_null_rev(self.old_rev):
            exclude.append('^%s' % self.old_rev)

        new_repo_revs = git.rev_list(self.new_rev, *exclude, reverse=True,
                                     _split_lines=True)

        # If this is a reference creation (base_rev is null), try to
        # find a commit which can serve as base_rev.  We try to find
        # a pre-existing commit making the base_rev..new_rev list
        # as short as possible.
        base_rev = self.old_rev
        if is_null_rev(base_rev):
            if len(new_repo_revs) > 0:
                # The ref update brings some new commits.  The first
                # parent of the oldest of those commits, if it exists,
                # seems like a good candidate.  If it does not exist,
                # we are pushing an entirely new headless branch, and
                # base_rev should remain null.
                parents = commit_parents(new_repo_revs[0])
                if parents:
                    base_rev = parents[0]
            else:
                # This reference update does not bring any new commits
                # at all. This means new_rev is already accessible
                # through one of the references, thus making it a good
                # base_rev as well.
                base_rev = self.new_rev

        # Expand base_rev..new_rev to compute the list of commits which
        # are new for the reference.  If there is no actual base_rev
        # (Eg. a headless branch), then expand to all commits accessible
        # from that reference.
        if not is_null_rev(base_rev):
            commit_list = commit_info_list(self.new_rev, '^%s' % base_rev)
            base_rev = commit_rev(base_rev)
        else:
            commit_list = commit_info_list(self.new_rev)
            base_rev = None

        # Iterate over every commit, and set their pre_existing_p attribute.
        for commit in commit_list:
            commit.pre_existing_p = commit.rev not in new_repo_revs

        debug('update base: %s' % base_rev)

        return commit_list