-
Notifications
You must be signed in to change notification settings - Fork 537
Add rename_branch to ManageSnapshots #3426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -937,6 +937,37 @@ def remove_branch(self, branch_name: str) -> ManageSnapshots: | |
| """ | ||
| return self._remove_ref_snapshot(ref_name=branch_name) | ||
|
|
||
| def rename_branch(self, name: str, new_name: str) -> ManageSnapshots: | ||
| """ | ||
| Rename a branch. | ||
|
|
||
| Args: | ||
| name (str): name of branch to rename | ||
| new_name (str): the desired new name of the branch | ||
| Returns: | ||
| This for method chaining | ||
| """ | ||
| self._commit_if_ref_updates_exist() | ||
|
|
||
| if name == MAIN_BRANCH: | ||
| raise ValueError("Cannot rename main branch") | ||
|
|
||
| refs = self._transaction.table_metadata.refs | ||
| if name not in refs: | ||
| raise ValueError(f"Branch does not exist: {name}") | ||
|
|
||
| ref = refs[name] | ||
| if ref.snapshot_ref_type != SnapshotRefType.BRANCH: | ||
| raise ValueError(f"Ref {name} is not a branch") | ||
|
|
||
| if new_name in refs: | ||
| raise ValueError(f"Ref {new_name} already exists") | ||
|
|
||
| self.create_branch(ref.snapshot_id, new_name, ref.max_ref_age_ms, ref.max_snapshot_age_ms, ref.min_snapshots_to_keep) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we ensure refs is still the latest metadata when creating the new branch?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to add some unit tests validating that there's no concurrency issues from commits on the branch while this operation runs?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does upstream do here for validation? |
||
| self.remove_branch(name) | ||
|
|
||
| return self | ||
|
|
||
| def set_current_snapshot(self, snapshot_id: int | None = None, ref_name: str | None = None) -> ManageSnapshots: | ||
| """Set the current snapshot to a specific snapshot ID or ref. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using stock
ValueErrormakes sense here, looking at upstream preconditions is used!