def setUp(self): self.t = time.time() repo_path = create_test_repo() config = Config(config_file=utils.testdata('good_git.cfg')) config["git"]["base_repo_url"] = repo_path remote_branch = config["test"]["remote_branch"] remote_name = config["test"]["remote_name"] remote_url = repo_path self.repo = Git(remote_name=remote_name, remote_url=remote_url, remote_branch=remote_branch, config=config)
class GitTestCase(utils.TestHelper): def setUp(self): self.t = time.time() repo_path = create_test_repo() config = Config(config_file=utils.testdata('good_git.cfg')) config["git"]["base_repo_url"] = repo_path remote_branch = config["test"]["remote_branch"] remote_name = config["test"]["remote_name"] remote_url = repo_path self.repo = Git(remote_name=remote_name, remote_url=remote_url, remote_branch=remote_branch, config=config) def tearDown(self): print "%s: %f" % (self.id(), time.time() - self.t) def test_clone_repo_with_good_config(self): self.assertTrue(self.repo) def test_enter_repo_with_good_config(self): self.repo.repo.create_head(self.repo.remote_branch) self.assertTrue(self.repo.__enter__()) self.assertTrue(self.repo.branch('master').checkout()) self.assertFalse(self.repo.__exit__()) def test_clean_merge_with_good_config(self): self.repo.repo.create_head(self.repo.remote_branch) with self.repo as repo: self.assertTrue(repo.merge('master')) self.assertTrue(repo.branch('master').checkout()) def test_clean_squash_merge_with_good_Config(self): branch = self.repo.remote_branch self.repo.repo.create_head(branch) self.repo.branch(branch).checkout() curdir = os.getcwd() os.chdir(self.repo.clonepath) with open("testfile", "w") as test: test.write("this is just a test") self.repo.repo.git.execute(('git', 'add', 'testfile')) self.repo.repo.git.execute(("git", "commit", "-m", "test_commit")) self.repo.branch("master").checkout() self.assertTrue(self.repo.merge(branch, squash=True)) os.chdir(curdir) def test_clean_squash_merge_with_good_config_but_no_squash_message(self): branch = self.repo.remote_branch self.repo.repo.create_head(branch) self.repo.branch(branch).checkout() curdir = os.getcwd() os.chdir(self.repo.clonepath) with open("testfile", "w") as test: test.write("this is just a test") self.repo.repo.git.execute(('git', 'add', 'testfile')) self.repo.repo.git.execute(("git", "commit", "-m", "test_commit")) self.repo.branch("master").checkout() self.repo.clonepath="/i/am/a/fake/path/" self.assertTrue(self.repo.merge(branch, squash=True)) os.chdir(curdir) def test_merge_fails_for_some_reason_should_raise(self): class FakeGit(git.Repo): """ A fake git class """ def execute(self, command): """ No matter what, we raise a git.exc.GitCommandError """ raise git.exc.GitCommandError(command, -9999) def reset(self, *args, **kwargs): """ Pretend to reset a failed merge. """ pass self.repo.repo.create_head(self.repo.remote_branch) self.repo.repo.git = FakeGit() self.assertRaises(GitException, self.repo.merge, "master") try: self.assertCalled(self.repo.repo.git.reset, self.repo.merge, "master") except GitException, e: pass