|
| 1 | +"""Public GitPython queries used by released downstream projects.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from test.lib.fixtures import fixture_repo |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize("object_format", ["sha1", "sha256"]) |
| 11 | +@pytest.mark.parametrize("ref_format", ["files", "reftable"]) |
| 12 | +def test_index_entries_readers_retain_pending_and_published_snapshots(object_format, ref_format): |
| 13 | + with fixture_repo("downstream-index.sh", object_format, ref_format, write=True) as repo: |
| 14 | + index = repo.index |
| 15 | + published_bytes = Path(index.path).read_bytes() |
| 16 | + entries = index.entries |
| 17 | + assert len(entries) == 4 |
| 18 | + assert set(entries.keys()) == {("tracked", 0), *(("conflict", stage) for stage in (1, 2, 3))} |
| 19 | + assert [str(key[0]) for key in entries].count("conflict") == 3 |
| 20 | + assert entries[("tracked", 0)].binsha == repo.head.commit.tree["tracked"].binsha |
| 21 | + assert all(entry.path == path and entry.stage == stage for (path, stage), entry in entries.items()) |
| 22 | + with pytest.raises(KeyError): |
| 23 | + entries[("missing", 0)] |
| 24 | + with pytest.raises(TypeError): |
| 25 | + entries[("tracked", 0)] = entries[("conflict", 1)] |
| 26 | + index.add(["tracked"], write=False) |
| 27 | + pending = index.entries |
| 28 | + assert pending[("tracked", 0)].binsha != entries[("tracked", 0)].binsha |
| 29 | + assert repo.index.entries[("tracked", 0)] == entries[("tracked", 0)] |
| 30 | + assert Path(index.path).read_bytes() == published_bytes |
| 31 | + index.write() |
| 32 | + assert repo.index.entries == pending |
| 33 | + assert entries[("tracked", 0)].binsha == repo.head.commit.tree["tracked"].binsha |
0 commit comments