def test_commit_commits_all(self): repo = hglib.open(self.main_repo) file_name = "f1" file_path = os.path.join(self.main_repo, file_name) expected_content = "changed content" with open(file_path, "w+") as file: file.write("foo test content") commit_msg = "Test message" repo.add(file_path) repo.commit('Creating file', user="******") with open(file_path, "w+") as file: file.write(expected_content) repository = Repository(self.main_repo) repository.commit(commit_msg) with open(file_path, "w+") as file: file.write('content changed again') repo.update(clean=True) with open(file_path) as file: self.assertEquals(expected_content, file.read()) repo.close()
def test_commit_commits_all_but_removed_files(self): file_name = "f1" file_path = os.path.join(self.main_repo, file_name) commit_msg = "Test message" repository = Repository(self.main_repo) os.remove(file_path) repository.commit(commit_msg) hglibrepo = hglib.open(self.main_repo) hglibrepo.branch(clean=True) self.assertFalse(os.path.exists(file_path))
def test_commit(self): repo = hglib.open(self.main_repo) initial_len = len(repo.log()) file_name = "test_file" file_path = os.path.join(self.main_repo, file_name) with open(file_path, "a") as file: file.write("test content") commit_msg = "Test message" repo.add(file_path) repository = Repository(self.main_repo) repository.commit(commit_msg) self.assertEquals(len(repo.log()), initial_len + 1) self.assertEquals(repo.tip()[5], commit_msg) repo.close() self.assertIsNone(repository.commit(commit_msg))
def test_commit_without_allow_empty_does_not_fail_when_no_changes(self): repo = hglib.open(self.main_repo) initial_len = len(repo.log()) commit_msg = 'foo message' repository = Repository(self.main_repo) result = repository.commit(commit_msg) self.assertIsNone(result) self.assertEquals(len(repo.log()), initial_len) repo.close()
def test_terminate_branch(self): repo_path = self.create_repo(self.environment_path, repo_name="terminate_branch_test") branch_name = "TEST_BRANCH" repo = hglib.open(repo_path) repo.branch(branch_name) file_name = "test_file" file_path = os.path.join(repo_path, file_name) with open(file_path, "a") as file: file.write("test content") commit_msg = "Test message" repo.add(file_path) signature = Signature(user='******') repository = Repository(repo_path) repository.commit(commit_msg, signature) self.assertEquals(len(repo.branches()), 2) self.assertEquals(len(repo.branches(active=True)), 1) self.assertEquals(len(repo.branches(closed=True)), 2) self.mox.StubOutWithMock(repository, "push") repository.terminate_branch(branch_name, signature, None, None) self.assertEquals(len(repo.branches()), 1) self.assertEquals(len(repo.branches(active=True)), 0) self.assertEquals(len(repo.branches(closed=True)), 2) # Closing branch already closed # it shouldn't do anything but warning with a message repository.terminate_branch(branch_name, signature, None, None) repo.close()
def test_terminate_branch(self): repo_path = self.create_repo(self.environment_path, repo_name="terminate_branch_test") branch_name = "TEST_BRANCH" repo = hglib.open(repo_path) repo.branch(branch_name) file_name = "test_file" file_path = os.path.join(repo_path, file_name) with open(file_path, "a") as file: file.write("test content") commit_msg = "Test message" repo.add(file_path) repository = Repository(repo_path) repository.commit(commit_msg) self.assertEquals(len(repo.branches()), 2) self.assertEquals(len(repo.branches(active=True)), 1) self.assertEquals(len(repo.branches(closed=True)), 2) self.mox.StubOutWithMock(repository, "push") repository.terminate_branch(branch_name, None, None) self.assertEquals(len(repo.branches()), 1) self.assertEquals(len(repo.branches(active=True)), 0) self.assertEquals(len(repo.branches(closed=True)), 2) # Closing branch already closed # it shouldn't do anything but warning with a message repository.terminate_branch(branch_name, None, None) repo.close()
def test_commit_with_allow_empty_fails_when_no_changes(self): commit_msg = 'foo message' repository = Repository(self.main_repo) with self.assertRaises(RepositoryError): repository.commit(commit_msg, allow_empty=True)