Skip to content
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

Fixed: Made object id optional #1166

Merged
merged 7 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion azure-devops/azext_devops/dev/repos/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_ref(name, object_id, repository=None, organization=None, project=None
project=project)[0]


def delete_ref(name, object_id, repository=None, organization=None, project=None, detect=None):
def delete_ref(name, object_id=None, repository=None, organization=None, project=None, detect=None):
"""Delete a reference.
:param str name: Name of the reference to delete (example: heads/my_branch).
:param str object_id: Id of the reference to delete.
Expand All @@ -70,6 +70,16 @@ def delete_ref(name, object_id, repository=None, organization=None, project=None
project=project,
repo=repository)
client = get_git_client(organization)

if object_id is None:
ref = client.get_refs(repository_id=repository,
project=project,
filter=name)
if not ref:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not ref:
if not ref or len(ref) > 1:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be sure we are not getting multiple id's from service because in that case we can't be sure which one to delete

logger.error('ref not found')
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.error('ref not found')
return
raise CLIError("Failed to find object_id for ref " + name + ". Please provide object_id.")

object_id = ref[0].object_id

ref_update = GitRefUpdate(name=resolve_git_refs(name),
new_object_id='0000000000000000000000000000000000000000',
old_object_id=object_id)
Expand Down
Loading