def test_current_branch(self): contents = [{'A': '1'}] commits = self.create_repo(contents) self.assertEqual('master', subject.current_branch(self.scratch)) subject.git_op(['checkout', '-b', 'newbranch'], self.scratch) branch_contents = [{'B': '1'}] branch_commits = self.create_commits(branch_contents) self.assertEqual('newbranch', subject.current_branch(self.scratch))
def create_repos(self, count, common_contents): self.i = 0 self.scratch = [tempfile.mkdtemp(prefix='.scratch_', dir='.') for x in range(count)] subject.git_op(['init'], self.scratch[0]) commits = self.create_commits(0, common_contents) for x in range(1, count): shutil.rmtree(self.scratch[x]) subject.git_op(['clone', os.path.abspath(self.scratch[0]), self.scratch[x]]) return commits
def test_commit_on_branch(self): repo_contents = [ {'A': 1}, {'A': 2}, {'A': 3} ] branch_contents = [ {'B': 1}, {'B': 2} ] commits = self.create_repo(repo_contents) subject.git_op(['checkout', '-t', 'master', '-b', 'newbranch'], self.scratch) branch_commits = self.create_commits(branch_contents) self.assertTrue(subject.commit_on_branch(self.scratch, commits[2], 'master')) self.assertTrue(subject.commit_on_branch(self.scratch, commits[2], 'newbranch')) self.assertFalse(subject.commit_on_branch(self.scratch, branch_commits[1], 'master')) self.assertTrue(subject.commit_on_branch(self.scratch, branch_commits[1], 'newbranch'))
def test_determine_cherry_pick_master_number(self): repo_contents = [ {'A': 1}, {'A': 2}, {'A': 3} ] branch_contents = [ {'A': 1}, {'A': 2} ] commits = self.create_repo(repo_contents) subject.git_op(['checkout', '-t', 'master', '-b', 'newbranch'], self.scratch) branch_commits = self.create_commits(branch_contents) subject.git_op(['checkout', 'master'], self.scratch) subject.git_op(['merge', 'newbranch', '--no-ff'], self.scratch) merge_commit = subject.get_rev(self.scratch) #raise Exception((merge_commit, self.scratch)) self.assertEqual( '-m1', subject.determine_cherry_pick_master_number( self.scratch, merge_commit, 'master' ) ) self.assertEqual( None, subject.determine_cherry_pick_master_number( self.scratch, commits[2], 'master' ) )
def create_commits(self, contents): commits = [] for change in contents: commit_time = "%d +0000" % (self.i + 1000000000) env = { 'GIT_AUTHOR_DATE': commit_time, 'GIT_COMMITTER_DATE': commit_time } for fn in list(change.keys()): filename = os.path.join(self.scratch, fn) with open(filename, 'w+') as f: f.write(str(change[fn])) subject.git_op(['add'] + list(change.keys()), self.scratch) subject.git_op( ['commit', '-m', 'commit-%d' % self.i] + list(change.keys()), self.scratch, env=env) subject.git_op(['tag', str(self.i)], self.scratch) commits.append(subject.git_op(['rev-parse', 'HEAD'], self.scratch).strip()) self.i += 1 return commits
def create_repo(self, contents): self.i = 0 subject.git_op(['init'], self.scratch) return self.create_commits(contents)
def test_git_op(self): output = subject.git_op(['version'], self.scratch) self.assertTrue(output.strip().startswith('git version'))