mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
fix: check maintenance branches
This commit is contained in:
parent
ceb429b253
commit
9632918850
1 changed files with 17 additions and 6 deletions
|
|
@ -3,7 +3,9 @@ from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
from distutils.version import LooseVersion
|
||||||
from typing import Mapping
|
from typing import Mapping
|
||||||
|
import re
|
||||||
|
|
||||||
from pre_commit.errors import FatalError
|
from pre_commit.errors import FatalError
|
||||||
from pre_commit.util import CalledProcessError
|
from pre_commit.util import CalledProcessError
|
||||||
|
|
@ -236,10 +238,19 @@ def get_best_candidate_tag(rev: str, git_repo: str) -> str:
|
||||||
Multiple tags can exist on a SHA. Sometimes a moving tag is attached
|
Multiple tags can exist on a SHA. Sometimes a moving tag is attached
|
||||||
to a version tag. Try to pick the tag that looks like a version.
|
to a version tag. Try to pick the tag that looks like a version.
|
||||||
"""
|
"""
|
||||||
tags = cmd_output(
|
all_tag_cmd = ('git', *NO_FS_MONITOR, 'tag', '-l')
|
||||||
'git', *NO_FS_MONITOR, 'tag', '--points-at', rev, cwd=git_repo,
|
all_tags = cmd_output(*all_tag_cmd, cwd=git_repo)[1].strip().splitlines()
|
||||||
)[1].splitlines()
|
all_tags = sorted(all_tags, key=LooseVersion)
|
||||||
for tag in tags:
|
numbers_and_dots = re.compile("^v|\d+(\.\d+)*$")
|
||||||
if '.' in tag:
|
filtered_all_tags = [ver for ver in all_tags if numbers_and_dots.match(ver)]
|
||||||
return tag
|
try: # or check for empty list
|
||||||
|
rev = filtered_all_tags[-1]
|
||||||
|
except IndexError:
|
||||||
|
tags = cmd_output(
|
||||||
|
'git', *NO_FS_MONITOR, 'tag', '--points-at', rev, cwd=git_repo,
|
||||||
|
)[1].splitlines()
|
||||||
|
for tag in tags:
|
||||||
|
if '.' in tag:
|
||||||
|
return tag
|
||||||
|
|
||||||
return rev
|
return rev
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue