def test_managed_git_state_stash_with_conflict(tmp_git: Path):
    """Conflicts made during visits are NOT handled, but the stash maintains history."""
    filename = tmp_git / "README.md"

    filename.open("w+").write("test")
    diff = run("git diff")
    assert len(diff) > 0, run("git status")

    assert git_stash_size() == 0
    with pytest.raises(subprocess.CalledProcessError) as excinfo:
        with managed_git_state():
            assert git_stash_size() == 1
            run("git checkout HEAD~1")
            filename.open("w+").write("test1")
        assert "apply" in str(excinfo.value)

    assert git_stash_size() == 1
def test_managed_git_state_stash(tmp_git: Path):
    """Assert that top level stash is maintained when no changes are made during visits of revisions."""
    filename = tmp_git / "README.md"

    original = run("git rev-parse HEAD")
    filename.open("w+").write("test")
    diff = run("git diff")
    assert len(diff) > 0, run("git status")

    assert git_stash_size() == 0
    with managed_git_state():
        assert git_stash_size() == 1
        run("git checkout HEAD~1")
        with managed_git_state():
            assert git_stash_size() == 1
            run("git checkout HEAD~1")

    assert git_stash_size() == 0
    assert run("git rev-parse HEAD") == original
    assert run("git diff") == diff