예제 #1
0
def create_commit_message(repo):
    git = utils.get_git()
    message = messages.CommitMessage()
    try:
        commit = repo.head.commit
    except ValueError:
        raise NoGitHeadError('On initial commit, no HEAD yet.')
    try:
        repo.git.diff('--quiet')
        has_unstaged_changes = False
    except git.exc.GitCommandError:
        has_unstaged_changes = True
    message.has_unstaged_changes = has_unstaged_changes
    message.sha = commit.hexsha
    message.message = commit.message
    try:
        message.branch = repo.head.ref.name
    except TypeError:
        # Allow operating in an environment with a detached HEAD.
        pass
    message.author = messages.AuthorMessage(
        name=commit.author.name, email=commit.author.email)
    return message
예제 #2
0
 def __init__(self, *args, **kwargs):
     super(GitDestination, self).__init__(*args, **kwargs)
     self.adds = set()
     self.deletes = set()
     self._original_branch_name = None
     self._git = common_utils.get_git()
예제 #3
0
    def stream(cls, theirs, content_generator, repo=None, is_partial=False):
        """Render the content and create a diff passing on only the changed content."""
        index = Index.create()
        if repo:
            Index.add_repo(index, repo)
        paths_to_content = {}
        git = common_utils.get_git()
        diff = messages.DiffMessage()
        diff.is_partial = is_partial
        diff.indexes = []
        diff.indexes.append(theirs or messages.IndexMessage())
        diff.indexes.append(index or messages.IndexMessage())

        index_paths_to_shas = {}
        their_paths_to_shas = {}

        for file_message in theirs.files:
            their_paths_to_shas[file_message.path] = file_message.sha

        for path, rendered in content_generator:
            index_paths_to_shas[path] = Index.add_file(index, path, rendered).sha

            if path in their_paths_to_shas:
                if index_paths_to_shas[path] == their_paths_to_shas[path]:
                    file_message = messages.FileMessage()
                    file_message.path = path
                    file_message.deployed = theirs.deployed
                    file_message.deployed_by = theirs.deployed_by
                    diff.nochanges.append(file_message)
                else:
                    file_message = messages.FileMessage()
                    file_message.path = path
                    file_message.deployed = theirs.deployed
                    file_message.deployed_by = theirs.deployed_by
                    diff.edits.append(file_message)
                    paths_to_content[path] = rendered
                del their_paths_to_shas[path]
            else:
                file_message = messages.FileMessage()
                file_message.path = path
                diff.adds.append(file_message)
                paths_to_content[path] = rendered

        # When doing partial diffs we do not have enough information to know
        # which files have been deleted.
        if not is_partial:
            for path, _ in their_paths_to_shas.iteritems():
                file_message = messages.FileMessage()
                file_message.path = path
                file_message.deployed = theirs.deployed
                file_message.deployed_by = theirs.deployed_by
                diff.deletes.append(file_message)

        # What changed in the pod between deploy commits.
        if (repo is not None and index.commit and index.commit.sha and theirs.commit
                and theirs.commit.sha):
            try:
                what_changed = repo.git.log(
                    '--date=short',
                    '--pretty=format:[%h] %ad <%ae> %s',
                    '{}..{}'.format(theirs.commit.sha, index.commit.sha))
                if isinstance(what_changed, unicode):
                    what_changed = what_changed.encode('utf-8')
                diff.what_changed = what_changed.decode('utf-8')
            except git.exc.GitCommandError:
                logging.info('Unable to determine changes between deploys.')

        # If on the original deploy show commit log messages only.
        elif (repo is not None
              and index.commit and index.commit.sha):
            what_changed = repo.git.log(
                '--date=short',
                '--pretty=format:[%h] %ad <%ae> %s')
            if isinstance(what_changed, unicode):
                what_changed = what_changed.encode('utf-8')
            diff.what_changed = what_changed.decode('utf-8')

        return diff, index, paths_to_content
예제 #4
0
    def create(cls, index, theirs, repo=None):
        git = common_utils.get_git()
        diff = messages.DiffMessage()
        diff.indexes = []
        diff.indexes.append(theirs or messages.IndexMessage())
        diff.indexes.append(index or messages.IndexMessage())

        index_paths_to_shas = {}
        their_paths_to_shas = {}

        for file_message in index.files:
            index_paths_to_shas[file_message.path] = file_message.sha
        for file_message in theirs.files:
            their_paths_to_shas[file_message.path] = file_message.sha

        for path, sha in index_paths_to_shas.iteritems():
            if path in their_paths_to_shas:
                if index_paths_to_shas[path] == their_paths_to_shas[path]:
                    file_message = messages.FileMessage()
                    file_message.path = path
                    file_message.deployed = theirs.deployed
                    file_message.deployed_by = theirs.deployed_by
                    diff.nochanges.append(file_message)
                else:
                    file_message = messages.FileMessage()
                    file_message.path = path
                    file_message.deployed = theirs.deployed
                    file_message.deployed_by = theirs.deployed_by
                    diff.edits.append(file_message)
                del their_paths_to_shas[path]
            else:
                file_message = messages.FileMessage()
                file_message.path = path
                diff.adds.append(file_message)

        for path, sha in their_paths_to_shas.iteritems():
            file_message = messages.FileMessage()
            file_message.path = path
            file_message.deployed = theirs.deployed
            file_message.deployed_by = theirs.deployed_by
            diff.deletes.append(file_message)

        # What changed in the pod between deploy commits.
        if (repo is not None
            and index.commit and index.commit.sha
            and theirs.commit and theirs.commit.sha):
            try:
                what_changed = repo.git.log(
                    '--date=short',
                    '--pretty=format:[%h] %ad <%ae> %s',
                    '{}..{}'.format(theirs.commit.sha, index.commit.sha))
                if isinstance(what_changed, unicode):
                  what_changed = what_changed.encode('utf-8')
                diff.what_changed = what_changed.decode('utf-8')
            except git.exc.GitCommandError:
                logging.info('Unable to determine changes between deploys.')

        # If on the original deploy show commit log messages only.
        elif (repo is not None
              and index.commit and index.commit.sha):
            what_changed = repo.git.log(
                  '--date=short',
                  '--pretty=format:[%h] %ad <%ae> %s')
            if isinstance(what_changed, unicode):
              what_changed = what_changed.encode('utf-8')
            diff.what_changed = what_changed.decode('utf-8')

        return diff
예제 #5
0
 def __init__(self, *args, **kwargs):
     super(GitDestination, self).__init__(*args, **kwargs)
     self.adds = set()
     self.deletes = set()
     self._original_branch_name = None
     self._git = common_utils.get_git()
예제 #6
0
파일: indexes.py 프로젝트: drGrove/grow
    def create(cls, index, theirs, repo=None, is_partial=False):
        git = common_utils.get_git()
        diff = messages.DiffMessage()
        diff.is_partial = is_partial
        diff.indexes = []
        diff.indexes.append(theirs or messages.IndexMessage())
        diff.indexes.append(index or messages.IndexMessage())

        index_paths_to_shas = {}
        their_paths_to_shas = {}

        for file_message in index.files:
            index_paths_to_shas[file_message.path] = file_message.sha
        for file_message in theirs.files:
            their_paths_to_shas[file_message.path] = file_message.sha

        for path, sha in index_paths_to_shas.iteritems():
            if path in their_paths_to_shas:
                if index_paths_to_shas[path] == their_paths_to_shas[path]:
                    file_message = messages.FileMessage()
                    file_message.path = path
                    file_message.deployed = theirs.deployed
                    file_message.deployed_by = theirs.deployed_by
                    diff.nochanges.append(file_message)
                else:
                    file_message = messages.FileMessage()
                    file_message.path = path
                    file_message.deployed = theirs.deployed
                    file_message.deployed_by = theirs.deployed_by
                    diff.edits.append(file_message)
                del their_paths_to_shas[path]
            else:
                file_message = messages.FileMessage()
                file_message.path = path
                diff.adds.append(file_message)

        # When doing partial diffs we do not have enough information to know
        # which files have been deleted.
        if not is_partial:
            for path, sha in their_paths_to_shas.iteritems():
                file_message = messages.FileMessage()
                file_message.path = path
                file_message.deployed = theirs.deployed
                file_message.deployed_by = theirs.deployed_by
                diff.deletes.append(file_message)

        # What changed in the pod between deploy commits.
        if (repo is not None and index.commit and index.commit.sha and theirs.commit
                and theirs.commit.sha):
            try:
                what_changed = repo.git.log(
                    '--date=short',
                    '--pretty=format:[%h] %ad <%ae> %s',
                    '{}..{}'.format(theirs.commit.sha, index.commit.sha))
                if isinstance(what_changed, unicode):
                    what_changed = what_changed.encode('utf-8')
                diff.what_changed = what_changed.decode('utf-8')
            except git.exc.GitCommandError:
                logging.info('Unable to determine changes between deploys.')

        # If on the original deploy show commit log messages only.
        elif (repo is not None
              and index.commit and index.commit.sha):
            what_changed = repo.git.log(
                '--date=short',
                '--pretty=format:[%h] %ad <%ae> %s')
            if isinstance(what_changed, unicode):
                what_changed = what_changed.encode('utf-8')
            diff.what_changed = what_changed.decode('utf-8')

        return diff