def test_E_NewCommitsDescription(self):
        base, branch_name, branch = self._setup_for_untracked_branch()
        user = '******'
        email = '*****@*****.**'
        self._dev_commit_new_empty_file('Commit 1', user, email)
        self._dev_commit_new_empty_file('Commit 2', user, email)
        self._dev_commit_new_empty_file('Commit 3', user, email)
        self._dev_commit_new_empty_file('Commit 4', user, email)
        phlgit_push.push(self.repo_dev, branch_name, 'origin')
        self.repo_arcyd('fetch', 'origin')

        # [ E] all commits are shown when no arguments are supplied
        new_commits_str = branch.describe_new_commits()
        new_commits = new_commits_str.splitlines()
        self.assertEqual(4, len(new_commits))
        count = 4
        for line in new_commits:
            self.assertTrue(line.endswith('Commit {}'.format(count)))
            count -= 1

        # [ E] number of commits can be limited by max_commits argument
        new_commits_str = branch.describe_new_commits(2)
        new_commits = new_commits_str.splitlines()
        self.assertEqual(3, len(new_commits))
        self.assertTrue(new_commits[0].endswith('Commit 4'))
        self.assertTrue(new_commits[1].endswith('Commit 3'))
        self.assertEqual(new_commits[2], '...2 commits not shown.')

        # [ E] number of commits can be limited by max_size argument
        new_commits_str = branch.describe_new_commits(3, 20)
        new_commits = new_commits_str.splitlines()
        self.assertEqual(2, len(new_commits))
        self.assertTrue(new_commits[0].endswith('Commit 4'))
        self.assertEqual(new_commits[1], '...3 commits not shown.')
    def __init__(self, contributor_count):
        super(CentralisedWithWorkers, self).__init__()
        if contributor_count < 1:
            raise(
                Exception("contributor_count must be 1 or more, got {}".format(
                    contributor_count)))

        self._central_repo = phlsys_git.Repo(tempfile.mkdtemp())
        self._central_repo("init", "--bare")

        self._workers = []
        for i in xrange(contributor_count):
            self._workers.append(
                Worker(phlsys_git.Repo(tempfile.mkdtemp())))
            self.workers[-1].repo("init")
            self.workers[-1].repo(
                "remote", "add", "origin", self._central_repo.working_dir)
            self.workers[-1].repo("fetch")

            if i == 0:
                self.workers[0].commit_new_file('initial commit', 'README')
                phlgit_push.push(self.workers[0].repo, 'master', 'origin')
            else:
                self.workers[i].repo('fetch')
                self.workers[i].repo('checkout', 'master')
    def test_D_AlternatingAuthors(self):
        base, branch_name, branch = self._setup_for_untracked_branch()

        alice_user = '******'
        alice_email = '*****@*****.**'

        bob_user = '******'
        bob_email = '*****@*****.**'

        self._dev_commit_new_empty_file('ALICE1', alice_user, alice_email)
        self._dev_commit_new_empty_file('BOB1', bob_user, bob_email)
        self._dev_commit_new_empty_file('ALICE2', alice_user, alice_email)

        phlgit_push.push(self.repo_dev, branch_name, 'origin')
        self.repo_arcyd('fetch', 'origin')

        author_names_emails = branch.get_author_names_emails()

        self.assertTupleEqual(
            author_names_emails[0],
            (bob_user, bob_email))

        self.assertTupleEqual(
            author_names_emails[1],
            (alice_user, alice_email))
Beispiel #4
0
    def test_E_NewCommitsDescription(self):
        base, branch_name, branch = self._setup_for_untracked_branch()
        user = '******'
        email = '*****@*****.**'
        self._dev_commit_new_empty_file('Commit 1', user, email)
        self._dev_commit_new_empty_file('Commit 2', user, email)
        self._dev_commit_new_empty_file('Commit 3', user, email)
        self._dev_commit_new_empty_file('Commit 4', user, email)
        phlgit_push.push(self.repo_dev, branch_name, 'origin')
        self.repo_arcyd('fetch', 'origin')

        # [ E] all commits are shown when no arguments are supplied
        new_commits_str = branch.describe_new_commits()
        new_commits = new_commits_str.splitlines()
        self.assertEqual(4, len(new_commits))
        count = 4
        for line in new_commits:
            self.assertTrue(line.endswith('Commit {}'.format(count)))
            count -= 1

        # [ E] number of commits can be limited by max_commits argument
        new_commits_str = branch.describe_new_commits(2)
        new_commits = new_commits_str.splitlines()
        self.assertEqual(3, len(new_commits))
        self.assertTrue(new_commits[0].endswith('Commit 4'))
        self.assertTrue(new_commits[1].endswith('Commit 3'))
        self.assertEqual(new_commits[2], '...2 commits not shown.')

        # [ E] number of commits can be limited by max_size argument
        new_commits_str = branch.describe_new_commits(3, 20)
        new_commits = new_commits_str.splitlines()
        self.assertEqual(2, len(new_commits))
        self.assertTrue(new_commits[0].endswith('Commit 4'))
        self.assertEqual(new_commits[1], '...3 commits not shown.')
    def _setup_for_untracked_branch(self, repo_name='name', branch_url=None):
        base = abdt_naming.EXAMPLE_REVIEW_BRANCH_BASE

        naming = abdt_classicnaming.Naming()

        branch_name = abdt_classicnaming.EXAMPLE_REVIEW_BRANCH_NAME
        self.repo_dev('checkout', '-b', branch_name)
        phlgit_push.push(self.repo_dev, branch_name, 'origin')

        self.repo_arcyd('fetch', 'origin')

        review_branch = naming.make_review_branch_from_name(branch_name)
        review_hash = phlgit_revparse.get_sha1_or_none(
            self.repo_arcyd, review_branch.branch)

        branch = abdt_branch.Branch(
            self.repo_arcyd,
            review_branch,
            review_hash,
            None,
            None,
            None,
            repo_name,
            branch_url)

        # should not raise
        branch.verify_review_branch_base()

        return base, branch_name, branch
Beispiel #6
0
    def __init__(self, contributor_count):
        super(CentralisedWithWorkers, self).__init__()
        if contributor_count < 1:
            raise(
                Exception("contributor_count must be 1 or more, got {}".format(
                    contributor_count)))

        self._central_repo = phlsys_git.Repo(tempfile.mkdtemp())
        self._central_repo("init", "--bare")

        self._workers = []
        for i in xrange(contributor_count):
            self._workers.append(
                Worker(phlsys_git.Repo(tempfile.mkdtemp())))
            self.workers[-1].repo("init")
            self.workers[-1].repo(
                "remote", "add", "origin", self._central_repo.working_dir)
            self.workers[-1].repo("fetch")

            if i == 0:
                self.workers[0].commit_new_file('initial commit', 'README')
                phlgit_push.push(self.workers[0].repo, 'master', 'origin')
            else:
                self.workers[i].repo('fetch')
                self.workers[i].repo('checkout', 'master')
    def _setup_for_untracked_branch(self, repo_name='name', branch_url=None):
        self._create_new_file(self.repo_dev, 'README')
        self.repo_dev.call('add', 'README')
        self.repo_dev.call('commit', '-m', 'initial commit')
        phlgit_push.push(self.repo_dev, 'master', 'origin')

        base = 'master'
        description = 'untracked'

        branch_name = abdt_naming.makeReviewBranchName(description, base)
        self.repo_dev.call('checkout', '-b', branch_name)
        phlgit_push.push(self.repo_dev, branch_name, 'origin')

        self.clone_arcyd.call('fetch', 'origin')
        review_branch = abdt_naming.makeReviewBranchFromName(branch_name)
        review_branch = abdt_gittypes.makeGitReviewBranch(
            review_branch, 'origin')
        branch = abdt_branch.Branch(
            self.clone_arcyd,
            review_branch,
            None,
            None,
            repo_name,
            branch_url)

        # should not raise
        branch.verify_review_branch_base()

        return base, branch_name, branch
    def push(self, branch):
        """Push 'branch' to the remote.

        :branch: string name of the branch to push
        :returns: None

        """
        phlgit_push.push(self._clone, branch, self._remote)
Beispiel #9
0
    def push(self, branch):
        """Push 'branch' to the remote.

        :branch: string name of the branch to push
        :returns: None

        """
        phlgit_push.push(self, branch, self._remote)
Beispiel #10
0
def ensure_reserve_branch(repo):
    """Ensure that the supplied 'repo' remote has the reserve branch.

    To prevent the problem where someone pushes branch 'dev', which blocks
    arcyd's tracker branches from being created.

    :repo: a callable supporting git commands, e.g. repo("status")
    :returns: None

    """
    reserve_name = phlgitu_ref.Name(_RESERVE_BRANCH_FQ_NAME)
    if not is_remote_reserve_branch_present(repo):
        phlgit_checkout.orphan_clean(repo, reserve_name.short)
        phlgit_commit.allow_empty(repo, _RESERVE_BRANCH_MESSAGE)
        phlgit_push.push(repo, reserve_name.short, 'origin')
        phlgit_checkout.previous_branch(repo)
        phlgit_branch.force_delete(repo, reserve_name.short)
Beispiel #11
0
def ensure_reserve_branch(repo):
    """Ensure that the supplied 'repo' remote has the reserve branch.

    To prevent the problem where someone pushes branch 'dev', which blocks
    arcyd's tracker branches from being created.

    :repo: a callable supporting git commands, e.g. repo("status")
    :returns: None

    """
    reserve_name = phlgitu_ref.Name(_RESERVE_BRANCH_FQ_NAME)
    if not is_remote_reserve_branch_present(repo):
        phlgit_checkout.orphan_clean(repo, reserve_name.short)
        phlgit_commit.allow_empty(repo, _RESERVE_BRANCH_MESSAGE)
        phlgit_push.push(repo, reserve_name.short, 'origin')
        phlgit_checkout.previous_branch(repo)
        phlgit_branch.force_delete(repo, reserve_name.short)
 def push_new_review_branch(self, identifier):
     branch_name = 'r/master/{}'.format(identifier)
     self._git_worker.commit_new_file_on_new_branch(
         branch=branch_name,
         message='Making review for {}'.format(identifier),
         relative_path=identifier,
         base='origin/master')
     return phlgit_push.push(self._repo, branch_name, 'origin')
def land(conduit, wb, gitContext, branch):
    clone = gitContext.clone
    print "landing " + wb.remote_branch + " onto " + wb.remote_base
    name, email, user = abdt_conduitgit.getPrimaryNameEmailAndUserFromBranch(
        clone, conduit, wb.remote_base, wb.remote_branch)
    d = phlcon_differential
    with phlsys_conduit.act_as_user_context(conduit, user):
        phlgit_checkout.new_branch_force_based_on(
            clone, wb.base, wb.remote_base)

        # compose the commit message
        message = d.get_commit_message(conduit, wb.id)

        try:
            with phlsys_fs.nostd():
                squashMessage = phlgit_merge.squash(
                    clone,
                    wb.remote_branch,
                    message,
                    name + " <" + email + ">")
        except phlsys_subprocess.CalledProcessError as e:
            clone.call("reset", "--hard")  # fix the working copy
            raise abdt_exception.LandingException(
                '\n' + e.stdout, branch, wb.base)

        print "- pushing " + wb.remote_base
        phlgit_push.push(clone, wb.base, gitContext.remote)
        print "- deleting " + wb.branch
        phlgit_push.delete(clone, wb.branch, gitContext.remote)
        print "- deleting " + branch
        phlgit_push.delete(clone, branch, gitContext.remote)

    print "- commenting on revision " + str(wb.id)
    commenter = abdcmnt_commenter.Commenter(conduit, wb.id)
    commenter.landedReview(branch, wb.base, squashMessage)

    authorPHID = d.query(conduit, [wb.id])[0].authorPHID
    authorUser = phlcon_user.query_usernames_from_phids(
        conduit, [authorPHID])[0]
    # TODO: there's a potential race condition on the author here
    with phlsys_conduit.act_as_user_context(conduit, authorUser):
        d.close(conduit, wb.id)
    def push_new_review_branch(self, identifier, message=None):
        branch_name = 'r/master/{}'.format(identifier)

        if message is None:
            message = 'Making review for {}'.format(identifier)

        self._git_worker.commit_new_file_on_new_branch(
            branch=branch_name,
            message=message,
            relative_path=identifier,
            base='origin/master')
        return phlgit_push.push(self._repo, branch_name, 'origin')
Beispiel #15
0
    def test_D_AlternatingAuthors(self):
        base, branch_name, branch = self._setup_for_untracked_branch()

        alice_user = '******'
        alice_email = '*****@*****.**'

        bob_user = '******'
        bob_email = '*****@*****.**'

        self._dev_commit_new_empty_file('ALICE1', alice_user, alice_email)
        self._dev_commit_new_empty_file('BOB1', bob_user, bob_email)
        self._dev_commit_new_empty_file('ALICE2', alice_user, alice_email)

        phlgit_push.push(self.repo_dev, branch_name, 'origin')
        self.repo_arcyd('fetch', 'origin')

        author_names_emails = branch.get_author_names_emails()

        self.assertTupleEqual(author_names_emails[0], (bob_user, bob_email))

        self.assertTupleEqual(author_names_emails[1],
                              (alice_user, alice_email))
    def setUp(self):
        self.repo_central = phlsys_git.GitClone(tempfile.mkdtemp())
        self.repo_dev = phlsys_git.GitClone(tempfile.mkdtemp())
        sys_clone = phlsys_git.GitClone(tempfile.mkdtemp())
        self.clone_arcyd = abdt_git.Clone(sys_clone, 'origin', 'myrepo')

        self.repo_central.call("init", "--bare")

        self.repo_dev.call("init")
        self.repo_dev.call(
            "remote", "add", "origin", self.repo_central.working_dir)
        self.repo_dev.call("fetch")

        self._create_new_file(self.repo_dev, 'README')
        self.repo_dev.call('add', 'README')
        self.repo_dev.call('commit', '-m', 'initial commit')
        phlgit_push.push(self.repo_dev, 'master', 'origin')

        self.clone_arcyd.call("init")
        self.clone_arcyd.call(
            "remote", "add", "origin", self.repo_central.working_dir)
        self.clone_arcyd.call("fetch")
    def _setup_for_untracked_branch(self, repo_name='name', branch_url=None):
        base = abdt_naming.EXAMPLE_REVIEW_BRANCH_BASE

        naming = abdt_classicnaming.Naming()

        branch_name = abdt_classicnaming.EXAMPLE_REVIEW_BRANCH_NAME
        self.repo_dev('checkout', '-b', branch_name)
        phlgit_push.push(self.repo_dev, branch_name, 'origin')

        self.repo_arcyd('fetch', 'origin')

        review_branch = naming.make_review_branch_from_name(branch_name)
        review_hash = phlgit_revparse.get_sha1_or_none(self.repo_arcyd,
                                                       review_branch.branch)

        branch = abdt_branch.Branch(self.repo_arcyd, review_branch,
                                    review_hash, None, None, None, repo_name,
                                    branch_url)

        # should not raise
        branch.verify_review_branch_base()

        return base, branch_name, branch
    def push_review_update(self, identifier, to_append):
        self._git_worker.commit_append_to_file(
            identifier, identifier, to_append)

        branch_name = 'r/master/{}'.format(identifier)
        phlgit_push.push(self._repo, branch_name, 'origin')
 def push_initial_commit(self):
     self._git_worker.commit_new_file('initial commit', 'README')
     phlgit_push.push(self._repo, 'master', 'origin')
 def push_initial_commit(self):
     self._git_worker.commit_new_file('initial commit', 'README')
     phlgit_push.push(self._repo, 'master', 'origin')
    def push_review_update(self, identifier, to_append):
        self._git_worker.commit_append_to_file(identifier, identifier,
                                               to_append)

        branch_name = 'r/master/{}'.format(identifier)
        phlgit_push.push(self._repo, branch_name, 'origin')