Skip to content

Commit

Permalink
Set store to writeable after creating a branch (earth-mover#455)
Browse files Browse the repository at this point in the history
* Set store to writeable after creating a branch

Closes earth-mover#439

* Add tests
  • Loading branch information
dcherian authored and emacollins committed Dec 11, 2024
1 parent 4c05fc5 commit 9ff8f5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions icechunk-python/python/icechunk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,20 @@ def checkout(
"only one of snapshot_id, branch, or tag may be specified"
)
self._store.checkout_snapshot(snapshot_id)
self._read_only = True
self.set_read_only()
return
if branch is not None:
if tag is not None:
raise ValueError(
"only one of snapshot_id, branch, or tag may be specified"
)
self._store.checkout_branch(branch)
self._read_only = True
# We preserve the read-only status here so you can checkout a branch
# on a read-only store, and be guaranteed that you won't modify the store.
return
if tag is not None:
self._store.checkout_tag(tag)
self._read_only = True
self.set_read_only()
return

raise ValueError("a snapshot_id, branch, or tag must be specified")
Expand Down Expand Up @@ -385,7 +386,9 @@ def new_branch(self, branch_name: str) -> str:
This requires having no uncommitted changes.
"""
return self._store.new_branch(branch_name)
ret = self._store.new_branch(branch_name)
self.set_writeable()
return ret

async def async_reset_branch(self, to_snapshot: str) -> None:
"""Reset the currently checked out branch to point to a different snapshot.
Expand Down
3 changes: 3 additions & 0 deletions icechunk-python/tests/test_timetravel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_timetravel():
assert air_temp[200, 6] == 42

snapshot_id = store.commit("commit 1")
assert not store._read_only

air_temp[:, :] = 54
assert air_temp[200, 6] == 54
Expand Down Expand Up @@ -49,12 +50,14 @@ def test_timetravel():
assert air_temp[200, 6] == 54

store.new_branch("feature")
assert not store._read_only
assert store.branch == "feature"
air_temp[:, :] = 90
feature_snapshot_id = store.commit("commit 3")
store.tag("v1.0", feature_snapshot_id)

store.checkout(tag="v1.0")
assert store._read_only
assert store.branch is None
assert air_temp[200, 6] == 90

Expand Down

0 comments on commit 9ff8f5c

Please sign in to comment.