示例#1
0
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"]))
示例#2
0
def test_integrated_hgrepo_apply_patch(hg_clone):
    repo = HgRepo(hg_clone.strpath)

    # We should refuse to apply patches that are missing a
    # Diff Start Line header.
    with pytest.raises(NoDiffStartLine), repo:
        repo.apply_patch(io.BytesIO(PATCH_WITHOUT_STARTLINE))

    # Patches with conflicts should raise a proper PatchConflict exception.
    with pytest.raises(PatchConflict), repo:
        repo.apply_patch(io.BytesIO(PATCH_WITH_CONFLICT))

    with repo:
        repo.apply_patch(io.BytesIO(PATCH_NORMAL))
        # Commit created.
        assert repo.run_hg(["outgoing"])

    with repo:
        repo.apply_patch(io.BytesIO(PATCH_UNICODE))
        # Commit created.

        log_output = repo.run_hg(["log"])
        assert "こんにちは" in log_output.decode("utf-8")
        assert repo.run_hg(["outgoing"])

    with repo:
        repo.apply_patch(io.BytesIO(PATCH_FAIL_HEADER))
        # Commit created.
        assert repo.run_hg(["outgoing"])