def create_empty_repo_branch(git_dir):
    '''
    Create and switch to branch empty_repo.

    This avoids Git errors when pushing to a brand-new empty repo which
    prohibits pushes to master.

    We'll switch to master and delete this branch later, when there's
    something in the repo and we can now safely detach HEAD from master.
    '''
    for branch in ['master', p4gf_const.P4GF_BRANCH_EMPTY_REPO]:
        p4gf_util.popen(['git', '--git-dir=' + git_dir, 'checkout', '-b', branch])
예제 #2
0
def create_empty_repo_branch(git_dir):
    '''
    Create and switch to branch empty_repo.

    This avoids Git errors when pushing to a brand-new empty repo which
    prohibits pushes to master.

    We'll switch to master and delete this branch later, when there's
    something in the repo and we can now safely detach HEAD from master.
    '''
    for branch in ['master', p4gf_const.P4GF_BRANCH_EMPTY_REPO]:
        p4gf_util.popen(
            ['git', '--git-dir=' + git_dir, 'checkout', '-b', branch])
예제 #3
0
    def copy_commit(self, commit):
        """copy a single commit"""

        self._reset_for_new_commit()

        #OG.debug("dump commit {}".format(commit))
        LOG.debug("for  commit {}".format(commit['mark']))
        LOG.debug("with description: {}".format(commit['data']))
        LOG.debug("files affected: {}".format(commit['files']))

        # Reject merge commits. Not supported in 2012.1.
        if 'merge' in commit:
            self.revert_and_raise(("Merge commit {} not permitted." +
                                   " Rebase to create a linear" +
                                   " history.").format(commit['sha1']))

        # strip any enclosing angle brackets from the email address
        email = commit['author']['email'].strip('<>')
        user = self.usermap.lookup_by_email(email)
        LOG.debug("for email {} found user {}".format(email, user))
        if (user is None) or (not self.usermap.p4user_exists(user[0])):
            # User is not a known and existing Perforce user, and the
            # unknown_git account is not set up, so reject the commit.
            self.revert_and_raise(
                "User '{}' not permitted to commit".format(email))
        author_p4user = user[0]

        for blob in commit['files']:
            err = check_valid_filename(blob['path'])
            if err:
                self.revert_and_raise(err)

        with self.perf.timer[GIT_CHECKOUT]:
            d = p4gf_util.popen_no_throw(['git', 'checkout', commit['sha1']])
            if d['Popen'].returncode:
                # Sometimes git cannot distinquish the revision from a path...
                p4gf_util.popen(
                    ['git', 'reset', '--hard', commit['sha1'], '--'])

        with self.perf.timer[CHECK_PROTECTS]:
            self.check_protects(author_p4user, commit['files'])

        try:
            self.copy_blobs(commit['files'])
        except P4.P4Exception as e:
            self.revert_and_raise(str(e))

        with self.perf.timer[COPY_BLOBS_2]:
            pusher_p4user = self.ctx.authenticated_p4user
            LOG.debug("Pusher is: {}, author is: {}".format(
                pusher_p4user, author_p4user))
            desc = change_description(commit, pusher_p4user, author_p4user)

            try:
                opened = self.ctx.p4.run('opened')
                if opened:
                    changenum = p4_submit(self.ctx.p4, desc, author_p4user,
                                          commit['author']['date'])
                    LOG.info("Submitted change @{} for commit {}".format(
                        changenum, commit['sha1']))
                else:
                    LOG.info("Ignored empty commit {}".format(commit['sha1']))
                    return None
            except P4.P4Exception as e:
                self.revert_and_raise(str(e))
            return ":" + str(changenum) + " " + commit['sha1']
    def copy_commit(self, commit):
        """copy a single commit"""

        self._reset_for_new_commit()

        #OG.debug("dump commit {}".format(commit))
        LOG.debug("for  commit {}".format(commit['mark']))
        LOG.debug("with description: {}".format(commit['data']))
        LOG.debug("files affected: {}".format(commit['files']))

        # Reject merge commits. Not supported in 2012.1.
        if 'merge' in commit:
            self.revert_and_raise(("Merge commit {} not permitted."
                                   +" Rebase to create a linear"
                                   +" history.").format(commit['sha1']))

        # strip any enclosing angle brackets from the email address
        email = commit['author']['email'].strip('<>')
        user = self.usermap.lookup_by_email(email)
        LOG.debug("for email {} found user {}".format(email, user))
        if (user is None) or (not self.usermap.p4user_exists(user[0])):
            # User is not a known and existing Perforce user, and the
            # unknown_git account is not set up, so reject the commit.
            self.revert_and_raise("User '{}' not permitted to commit".format(email))
        author_p4user = user[0]

        for blob in commit['files']:
            err = check_valid_filename(blob['path'])
            if err:
                self.revert_and_raise(err)

        with self.perf.timer[GIT_CHECKOUT]:
            d = p4gf_util.popen_no_throw(['git', 'checkout', commit['sha1']])
            if d['Popen'].returncode:
                # Sometimes git cannot distinquish the revision from a path...
                p4gf_util.popen(['git', 'reset', '--hard', commit['sha1'], '--'])

        with self.perf.timer[CHECK_PROTECTS]:
            self.check_protects(author_p4user, commit['files'])

        try:
            self.copy_blobs(commit['files'])
        except P4.P4Exception as e:
            self.revert_and_raise(str(e))

        with self.perf.timer[COPY_BLOBS_2]:
            pusher_p4user = self.ctx.authenticated_p4user
            LOG.debug("Pusher is: {}, author is: {}".format(pusher_p4user, author_p4user))
            desc = change_description(commit, pusher_p4user, author_p4user)

            try:
                opened = self.ctx.p4.run('opened')
                if opened:
                    changenum = p4_submit(self.ctx.p4, desc, author_p4user,
                                          commit['author']['date'])
                    LOG.info("Submitted change @{} for commit {}".format(changenum, commit['sha1']))
                else:
                    LOG.info("Ignored empty commit {}".format(commit['sha1']))
                    return None
            except P4.P4Exception as e:
                self.revert_and_raise(str(e))
            return ":" + str(changenum) + " " + commit['sha1']