def checkout_make_raw_diff(self, from_branch, to_branch, max_diff_size_utf8_bytes): """Return an abdt_differ.DiffResult of the changes on the branch. If the diff would exceed the pre-specified max diff size then take measures to reduce the diff. Potentially checkout onto the 'to_branch' so that changes to .gitattributes files will be considered. :from_branch: string name of the merge-base of 'branch' :to_branch: string name of the branch to diff :max_diff_size_utf8_bytes: the maximum allowed size of the diff as utf8 :returns: the string diff of the changes on the branch """ if not phlgitu_ref.is_fq(from_branch): raise ValueError("not fully qualifed: {}".format(from_branch)) if not phlgitu_ref.is_fq(to_branch): raise ValueError("not fully qualifed: {}".format(from_branch)) key = self._make_key(from_branch, to_branch, max_diff_size_utf8_bytes) if key in self._diff_results: raise self._diff_results[key] # checkout the 'to' branch, otherwise we won't take into account any # changes to .gitattributes files phlgit_checkout.branch(self._repo, to_branch) try: return abdt_differ.make_raw_diff(self._repo, from_branch, to_branch, max_diff_size_utf8_bytes) except abdt_differ.NoDiffError as e: self._diff_results[key] = e raise
def _checkout_archive_ref_branch( self, short_branch_name, fq_branch_name, initial_message): if self._is_ref(fq_branch_name): phlgit_checkout.branch(self, short_branch_name) else: phlgit_checkout.orphan_clean(self, short_branch_name) phlgit_commit.allow_empty(self, initial_message)
def _checkout_archive_ref_branch(self, short_branch_name, fq_branch_name, initial_message): if self._is_ref(fq_branch_name): phlgit_checkout.branch(self, short_branch_name) else: phlgit_checkout.orphan_clean(self, short_branch_name) phlgit_commit.allow_empty(self, initial_message)
def checkout_master_fetch_special_refs(repo, remote): # fetch the 'landed' and 'abandoned' refs, if they exist # We must checkout master before fetching the special refs to the # local branches. Otherwise we might be attempting to overwrite the # current branch with fetch, which would fail. phlgit_checkout.branch(repo, 'master') branch_refspec = '+refs/heads/*:refs/remotes/origin/*' arcyd_refspec = '+{refspace}/*:refs/heads/{branchspace}/*'.format( refspace=_ARCYD_REFSPACE, branchspace=_PRIVATE_ARCYD_BRANCHSPACE) refspec_list = [branch_refspec, arcyd_refspec] phlgit_fetch.prune_safe(repo, remote, refspec_list)
def checkout_master_fetch_special_refs(repo, remote): # fetch the 'landed' and 'abandoned' refs, if they exist # We must checkout master before fetching the special refs to the # local branches. Otherwise we might be attempting to overwrite the # current branch with fetch, which would fail. phlgit_checkout.branch(repo, 'master') ref_list = set(repo('ls-remote').split()[1::2]) special_refs = [ (ARCYD_ABANDONED_REF, ARCYD_ABANDONED_BRANCH_FQ), (ARCYD_LANDED_REF, ARCYD_LANDED_BRANCH_FQ), ] for ref in special_refs: if ref[0] in ref_list: # Allow non-ff fetches so that we enable users to prune the special # refs if they're getting too large. repo('fetch', remote, '+{}:{}'.format(ref[0], ref[1]))
def make_raw_diff(self): """Return an abdt_differ.DiffResult of the changes on the branch. If the diff would exceed the pre-specified max diff size then take measures to reduce the diff. """ # checkout the 'to' branch, otherwise we won't take into account any # changes to .gitattributes files phlgit_checkout.branch(self._repo, self._review_branch.remote_branch) try: return abdt_differ.make_raw_diff( self._repo, self._review_branch.remote_base, self._review_branch.remote_branch, _MAX_DIFF_SIZE) except abdt_differ.NoDiffError: raise abdt_exception.NoDiffException( self.base_branch_name(), self.review_branch_name(), self.review_branch_hash())
def checkout_make_raw_diff(self, from_branch, to_branch, max_diff_size_utf8_bytes): """Return an abdt_differ.DiffResult of the changes on the branch. If the diff would exceed the pre-specified max diff size then take measures to reduce the diff. Potentially checkout onto the 'to_branch' so that changes to .gitattributes files will be considered. :from_branch: string name of the merge-base of 'branch' :to_branch: string name of the branch to diff :max_diff_size_utf8_bytes: the maximum allowed size of the diff as utf8 :returns: the string diff of the changes on the branch """ if not phlgitu_ref.is_fq(from_branch): raise ValueError('not fully qualifed: {}'.format(from_branch)) if not phlgitu_ref.is_fq(to_branch): raise ValueError('not fully qualifed: {}'.format(from_branch)) key = self._make_key(from_branch, to_branch, max_diff_size_utf8_bytes) if key in self._diff_results: raise self._diff_results[key] # checkout the 'to' branch, otherwise we won't take into account any # changes to .gitattributes files phlgit_checkout.branch(self._repo, to_branch) try: return abdt_differ.make_raw_diff(self._repo, from_branch, to_branch, max_diff_size_utf8_bytes) except abdt_differ.NoDiffError as e: self._diff_results[key] = e raise
def test_B_RawDiffNewCommits(self): base, branch_name, branch = self._setup_for_tracked_branch() self.assertIs(branch.has_new_commits(), False) # push a new commit on branch as dev phlgit_checkout.branch(self.repo_dev, branch_name) filename = 'new_on_branch' self._create_new_file(self.repo_dev, filename) self.repo_dev('add', filename) phlgit_commit.index(self.repo_dev, message=filename) phlgit_push.branch(self.repo_dev, branch_name) branch = self._get_updated_branch(branch_name) # check for new stuff as arcyd self.assertIs(branch.has_new_commits(), True) branch.describe_new_commits() # just exercise self.assertIn(filename, branch.make_raw_diff().diff) branch.mark_ok_in_review() self.assertIs(branch.has_new_commits(), False) branch.describe_new_commits() # just exercise # exercise queries a bit self.assertIn(filename, branch.make_raw_diff().diff) self.assertIn(filename, branch.make_message_digest()) self.assertEqual( branch.get_commit_message_from_tip().strip(), filename) self.assertTrue(len(branch.get_any_author_emails()) > 0) self.assertTrue(len(branch.get_author_names_emails()) > 0) # make a new commit on master as dev phlgit_checkout.branch(self.repo_dev, 'master') filename = 'new_on_master' self._create_new_file(self.repo_dev, filename) self.repo_dev('add', filename) phlgit_commit.index(self.repo_dev, message=filename) phlgit_push.branch(self.repo_dev, 'master') # refresh the branch branch = self._get_updated_branch(branch_name) self.assertIs(branch.has_new_commits(), False) # merge master into branch, check for new stuff as arcyd phlgit_checkout.branch(self.repo_dev, branch_name) phlgit_merge.no_ff(self.repo_dev, 'master') phlgit_push.branch(self.repo_dev, branch_name) # check for new stuff as arcyd self.assertIs(branch.has_new_commits(), False) branch = self._get_updated_branch(branch_name) self.assertNotIn(filename, branch.make_raw_diff().diff) branch.mark_ok_in_review() self.assertIs(branch.has_new_commits(), False) # rebase branch onto master phlgit_checkout.branch(self.repo_dev, branch_name) phlgit_rebase.onto_upstream(self.repo_dev, 'master') phlgit_push.force_branch(self.repo_dev, branch_name) # check for new stuff as arcyd self.assertIs(branch.has_new_commits(), False) branch = self._get_updated_branch(branch_name) self.assertIs(branch.has_new_commits(), True) branch.describe_new_commits() # just exercise branch.mark_ok_in_review() self.assertIs(branch.has_new_commits(), False)
def test_B_RawDiffNewCommits(self): base, branch_name, branch = self._setup_for_tracked_branch() self.assertIs(branch.has_new_commits(), False) # push a new commit on branch as dev phlgit_checkout.branch(self.repo_dev, branch_name) filename = 'new_on_branch' self._create_new_file(self.repo_dev, filename) self.repo_dev('add', filename) phlgit_commit.index(self.repo_dev, message=filename) phlgit_push.branch(self.repo_dev, branch_name) branch = self._get_updated_branch(branch_name) # check for new stuff as arcyd self.assertIs(branch.has_new_commits(), True) branch.describe_new_commits() # just exercise self.assertIn(filename, branch.make_raw_diff().diff) branch.mark_ok_in_review() self.assertIs(branch.has_new_commits(), False) branch.describe_new_commits() # just exercise # exercise queries a bit self.assertIn(filename, branch.make_raw_diff().diff) self.assertIn(filename, branch.make_message_digest()) self.assertEqual(branch.get_commit_message_from_tip().strip(), filename) self.assertTrue(len(branch.get_any_author_emails()) > 0) self.assertTrue(len(branch.get_author_names_emails()) > 0) # make a new commit on master as dev phlgit_checkout.branch(self.repo_dev, 'master') filename = 'new_on_master' self._create_new_file(self.repo_dev, filename) self.repo_dev('add', filename) phlgit_commit.index(self.repo_dev, message=filename) phlgit_push.branch(self.repo_dev, 'master') # refresh the branch branch = self._get_updated_branch(branch_name) self.assertIs(branch.has_new_commits(), False) # merge master into branch, check for new stuff as arcyd phlgit_checkout.branch(self.repo_dev, branch_name) phlgit_merge.no_ff(self.repo_dev, 'master') phlgit_push.branch(self.repo_dev, branch_name) # check for new stuff as arcyd self.assertIs(branch.has_new_commits(), False) branch = self._get_updated_branch(branch_name) self.assertNotIn(filename, branch.make_raw_diff().diff) branch.mark_ok_in_review() self.assertIs(branch.has_new_commits(), False) # rebase branch onto master phlgit_checkout.branch(self.repo_dev, branch_name) phlgit_rebase.onto_upstream(self.repo_dev, 'master') phlgit_push.force_branch(self.repo_dev, branch_name) # check for new stuff as arcyd self.assertIs(branch.has_new_commits(), False) branch = self._get_updated_branch(branch_name) self.assertIs(branch.has_new_commits(), True) branch.describe_new_commits() # just exercise branch.mark_ok_in_review() self.assertIs(branch.has_new_commits(), False)