@@ -245,6 +245,17 @@ def switch_ref(plugin, ref, discard_changes=False):
245245 origin_remote = repo .get_remote ('origin' )
246246 repo .fetch_remote (origin_remote , None , callbacks ._callbacks )
247247
248+ # If the ref is not found locally, try fetching it specifically
249+ references = repo .get_references ()
250+ tag_ref = f'refs/tags/{ ref } '
251+ if tag_ref not in references :
252+ try :
253+ # Fetch the specific tag
254+ repo .fetch_remote (origin_remote , f'+refs/tags/{ ref } :refs/tags/{ ref } ' , callbacks ._callbacks )
255+ except Exception as e :
256+ # If specific fetch fails, continue with what we have
257+ log .debug ('Failed to fetch specific tag %s: %s' , ref , e )
258+
248259 # Find the ref
249260 try :
250261 references = repo .get_references ()
@@ -277,6 +288,19 @@ def switch_ref(plugin, ref, discard_changes=False):
277288 repo .set_head (commit .id )
278289 log .info ('Switched plugin %s to tag %s' , plugin .plugin_id , ref )
279290 return old_ref , ref , old_commit , commit .id
291+ else :
292+ # Try resolving tag by short name (git can sometimes resolve tags without refs/tags/ prefix)
293+ try :
294+ commit_obj = repo .revparse_single (ref )
295+ # Check if this is actually a tag by seeing if refs/tags/{ref} exists after resolution
296+ if hasattr (commit_obj , 'type' ) and commit_obj .type in ['tag' , 'commit' ]:
297+ commit = repo .peel_to_commit (commit_obj )
298+ repo .checkout_tree (commit )
299+ repo .set_head (commit .id )
300+ log .info ('Switched plugin %s to tag %s' , plugin .plugin_id , ref )
301+ return old_ref , ref , old_commit , commit .id
302+ except KeyError :
303+ pass
280304
281305 # Try as commit hash
282306 try :
0 commit comments