Pick a tag if multiple tags exist on a SHA. · Elentary/pre-commit@e8b46c1 · GitHub
Skip to content

Commit e8b46c1

Browse files
mblaymanasottile
authored andcommitted
Pick a tag if multiple tags exist on a SHA.
Fixes pre-commit#2311
1 parent a522507 commit e8b46c1

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

pre_commit/commands/autoupdate.py

Lines changed: 3 additions & 0 deletions

pre_commit/git.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,18 @@ def check_for_cygwin_mismatch() -> None:
229229
f' - python {exe_type[is_cygwin_python]}\n'
230230
f' - git {exe_type[is_cygwin_git]}\n',
231231
)
232+
233+
234+
def get_best_candidate_tag(rev: str, git_repo: str) -> str:
235+
"""Get the best tag candidate.
236+
237+
Multiple tags can exist on a SHA. Sometimes a moving tag is attached
238+
to a version tag. Try to pick the tag that looks like a version.
239+
"""
240+
tags = cmd_output(
241+
'git', *NO_FS_MONITOR, 'tag', '--points-at', rev, cwd=git_repo,
242+
)[1].splitlines()
243+
for tag in tags:
244+
if '.' in tag:
245+
return tag
246+
return rev

tests/commands/autoupdate_test.py

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)