Add code like this just before return candidates:
# search for branches and tags (with or without "refs" and "heads" or "tags" prefixes)
for path in [f'refs/heads/{name}', f'refs/tags/{name}', f'refs/{name}', name]:
if os.path.exists(repo_file(repo, path)):
candidates.append(ref_resolve(repo, path))