def create_repository(): sandbox = path(tempfile.mkdtemp(suffix="-unittest")) origin_repo_path = sandbox / "repo.git" origin_repo_path.mkdir() origin_repo = GitRepo(origin_repo_path) origin_repo.run_git("init", "--bare") repo = GitRepo.clone(origin_repo.path, sandbox / "repo", "--no-hardlinks") create_file(repo.path / "dummy") repo.add("dummy") repo.commit("created") repo.run_git("push", "origin", "master:master") return sandbox, origin_repo, repo
def test_merge_conflict(self): # Create a file and push it conflict = "conflict" open(conflict, "w").write("Foo") self.repository.add(conflict) self.repository.commit("msg") self.repository.run_git("push", "origin", "master:master") # Clone the repository and modify 'conflict' repo2_path = self.sandbox / "repo2" repo2 = GitRepo.clone(self.origin_repository.path, repo2_path) open(repo2_path / "conflict", "w").write("Repo2") repo2.add(conflict) repo2.commit("msg") # Push to remote repository repo2.run_git("push", "origin", "master:master") # Modify 'conflict' in self.repository open(conflict, "w").write("Local") self.repository.add(conflict) self.repository.commit("msg2") # Try to merge self.repository.run_git("fetch") try: self.repository.merge("origin/master") except HandlerConflictError, exc: self.assertEqual(exc.conflicting_files, ["conflict"])
def test_need_merge(self): self.assert_(not self.repository.need_merge()) other_repo_path = self.sandbox / "other_repo" other_repo = GitRepo.clone(self.origin_repository.path, other_repo_path) create_file(other_repo.path / "new_from_other_repo") other_repo.add("new_from_other_repo") other_repo.commit("commit from other repo") other_repo.run_git("push", "origin", "master:master") self.repository.run_git("fetch") self.assert_(self.repository.need_merge())