def test_integrated_hgrepo_apply_patch_newline_bug(hg_clone): """Test newline bug in Mercurial See https://bugzilla.mozilla.org/show_bug.cgi?id=1541181 for context. This test will be skipped if not using version 5.1 of Mercurial. """ # TODO: update test if version of Mercurial is changed. repo = HgRepo(hg_clone.strpath) with repo, hg_clone.as_cwd(): if ( repo.run_hg(["version"]).split(b"\n")[0] != b"Mercurial Distributed SCM (version 5.1)" ): pytest.skip("Test not relevant for this version of mercurial") # Create a file without a new line and with a trailing `\r` # Note that to reproduce this bug, this file needs to already exist # in the repo and not be imported in a patch. new_file = hg_clone.join("test-file") new_file.write(b"hello\r", mode="wb") repo.run_hg_cmds( [["add", new_file.strpath], ["commit", "-m", "adding file"], ["push"]] ) repo.apply_patch(io.BytesIO(PATCH_DELETE_NO_NEWLINE_FILE)) # Commit created. assert "file removed" in str(repo.run_hg(["outgoing"]))
def test_integrated_hgrepo_can_log(hg_clone): repo = HgRepo(hg_clone.strpath) with repo: assert repo.run_hg_cmds([["log"]])
def test_integrated_hgrepo_clean_repo(hg_clone): # Test is long and checks various repo cleaning cases as the startup # time for anything using `hg_clone` fixture is very long. repo = HgRepo(hg_clone.strpath) with repo, hg_clone.as_cwd(): # Create a draft commits to clean. new_file = hg_clone.join("new-file.txt") new_file.write("text", mode="w+") repo.run_hg_cmds( [["add", new_file.strpath], ["commit", "-m", "new draft commit"]] ) assert repo.run_hg_cmds([["outgoing"]]) # Dirty the working directory. new_file.write("Extra data", mode="a") assert repo.run_hg_cmds([["status"]]) # Can clean working directory without nuking commits repo.clean_repo(strip_non_public_commits=False) assert repo.run_hg_cmds([["outgoing"]]) assert not repo.run_hg_cmds([["status"]]) # Dirty the working directory again. new_file.write("Extra data", mode="a") assert repo.run_hg_cmds([["status"]]) # Cleaning should remove commit and clean working directory. repo.clean_repo() with pytest.raises(HgCommandError, match="no changes found"): repo.run_hg_cmds([["outgoing"]]) assert not repo.run_hg_cmds([["status"]]) # Create a commit and dirty the directory before exiting # the context manager as entering a new context should # provide a clean repo. new_file.write("text", mode="w+") repo.run_hg_cmds( [["add", new_file.strpath], ["commit", "-m", "new draft commit"]] ) new_file.write("extra data", mode="a") assert repo.run_hg_cmds([["outgoing"]]) assert repo.run_hg_cmds([["status"]]) with repo, hg_clone.as_cwd(): # New context should be clean. with pytest.raises(HgCommandError, match="no changes found"): repo.run_hg_cmds([["outgoing"]]) assert not repo.run_hg_cmds([["status"]])