def _branches_to_sync(self): '''Get the branches that need to synchronize''' qs = Branch.objects.filter(project=self.project).values('name','project') branches_in_repo = set(( '{0},{1}'.format(self.project.pk, git.clean_remote_branch_name(name)) for name in self.git_repo.remote_branch_names())) return (branch.split(',')[1] for branch in branches_in_repo)
def test_create_local_branch(self): self.git_repo.create_local_branches() local_branch_names = list(self.git_repo.local_branch_names()) self.assertEqual(len(local_branch_names), len(list(self.git_repo.local_branch_names())), 'No local branch is created to track remote branch.') # To see whether all local branch is created to track corresponding # remote branch. remote_branch_names = self.git_repo.remote_branch_names() names = set(git.clean_remote_branch_name(name) for name in remote_branch_names) not_created = names - set(local_branch_names) self.assert_(len(not_created) == 0, '{0} not created.'.format(' '.join(not_created)))
def _new_branches_to_sync(self): '''Get new branches that need to synchronize''' qs = Branch.objects.filter(project=self.project).values('name', 'project') existing_branches = set(( '{0},{1}'.format(branch['project'], branch['name']) for branch in qs.iterator())) # Before checking if there is any new branch appearing in remote # repository, we need to strip the remote spec information from # remote branch name. branches_in_repo = set(( '{0},{1}'.format(self.project.pk, git.clean_remote_branch_name(name)) for name in self.git_repo.remote_branch_names())) new_branches = branches_in_repo - existing_branches return (branch.split(',')[1] for branch in new_branches)