def test_worktree_from_branch(self): """Test whether a working tree is created from a target branch""" new_path = os.path.join(self.tmp_path, 'testworktree') repo = GraalRepository('http://example.git', self.git_path) self.assertIsNone(repo.worktreepath) repo.worktree(new_path, branch='master') self.assertEqual(repo.worktreepath, new_path) self.assertTrue(os.path.exists(repo.worktreepath)) repo.prune() self.assertFalse(os.path.exists(repo.worktreepath))
def test_worktree_already_exists(self): """Test whether a debug info is logged when the worktree already exists""" new_path = os.path.join(self.tmp_path, 'testworktree') repo = GraalRepository('http://example.git', self.git_path) self.assertIsNone(repo.worktreepath) repo.worktree(new_path, branch='master') with self.assertLogs(logger, level='DEBUG') as cm: repo.worktree(new_path, branch='master') self.assertRegex(cm.output[0], 'DEBUG:graal.graal:Git worktree.*not created.*already exists.*') repo.prune() self.assertFalse(os.path.exists(repo.worktreepath))
def test_delete(self): """Test whether files and directories are deleted""" new_path = os.path.join(self.tmp_path, 'testworktree') repo = GraalRepository('http://example.git', self.git_path) repo.worktree(new_path) target_file = os.path.join(new_path, 'perceval/_version.py') target_folder = os.path.join(new_path, 'perceval/backends') self.assertTrue(os.path.exists(target_file)) repo.delete(target_file) self.assertFalse(os.path.exists(target_file)) self.assertTrue(os.path.exists(target_folder)) repo.delete(target_folder) self.assertFalse(os.path.exists(target_folder)) repo.prune() self.assertFalse(os.path.exists(repo.worktreepath))
def test_checkout(self): """Test whether Git checkout commands are correctly executed""" new_path = os.path.join(self.tmp_path, 'testworktree') repo = GraalRepository('http://example.git', self.git_path) self.assertIsNone(repo.worktreepath) repo.worktree(new_path) repo.checkout("075f0c6161db5a3b1c8eca45e08b88469bb148b9") current_commit_hash = self.__git_show_hash(repo) self.assertEqual("075f0c6161db5a3b1c8eca45e08b88469bb148b9", current_commit_hash) repo.checkout("4f3b403d47fb291a9a942a62d62c24faa79244c8") current_commit_hash = self.__git_show_hash(repo) self.assertEqual("4f3b403d47fb291a9a942a62d62c24faa79244c8", current_commit_hash) repo.checkout("825b4da7ca740f7f2abbae1b3402908a44d130cd") current_commit_hash = self.__git_show_hash(repo) self.assertEqual("825b4da7ca740f7f2abbae1b3402908a44d130cd", current_commit_hash) repo.prune() self.assertFalse(os.path.exists(repo.worktreepath))