Browse Source

add "shore bump --allow-lower" option, get_commit_distance_version() now adds "+dirty" even if the distance is 0 if the repo has a diff

master
Niklas Rosenstein 6 months ago
parent
commit
f44059d02b
Signed by: NiklasRosenstein <rosensteinniklas@gmail.com> GPG Key ID: 06D269B33D25F6C6
2 changed files with 9 additions and 7 deletions
  1. +3
    -2
      src/shore/__main__.py
  2. +6
    -5
      src/shore/util/version.py

+ 3
- 2
src/shore/__main__.py View File

@@ -385,6 +385,7 @@ def _get_version_refs(subject) -> List[VersionRef]:
@click.option('--dry', is_flag=True)
@click.option('--skip-checks', is_flag=True)
@click.option('--force', '-f', is_flag=True)
@click.option('--allow-lower', is_flag=True)
@click.option('--push', is_flag=True)
@click.option('--update', is_flag=True)
@click.option('--publish')
@@ -461,14 +462,14 @@ def bump(**args):
new_version = bump_version(current_version, 'major')
elif args['version'] == 'git' or args['snapshot']:
new_version = _commit_distance_version(subject)
args['force'] = True
args['allow_lower'] = True
else:
new_version = parse_version(args['version'])

if not new_version.pep440_compliant:
logger.warning('version "{}" is not PEP440 compliant.'.format(new_version))

if new_version < current_version and not args['force']:
if new_version < current_version and not (args['force'] or args['allow_lower']):
logger.error('version {} is lower than current version {}'.format(
new_version, current_version))
exit(1)


+ 6
- 5
src/shore/util/version.py View File

@@ -134,6 +134,8 @@ def get_commit_distance_version(repo_dir: str, version: Version, latest_tag: str
Todo: We could try to find the previous tag for this subject and use that.
"""

dirty = _git.has_diff(repo_dir)

if _git.rev_parse(latest_tag):
distance = len(_git.rev_list(latest_tag + '..HEAD', repo_dir))
else:
@@ -142,11 +144,10 @@ def get_commit_distance_version(repo_dir: str, version: Version, latest_tag: str
distance = len(_git.rev_list('HEAD', repo_dir))

if distance == 0:
if dirty:
return parse_version(str(version) + '+dirty')
return None

suffix = ''
if _git.has_diff(repo_dir):
suffix = '.dirty'

rev = _git.rev_parse('HEAD', repo_dir)
return parse_version(str(version) + '+{}.g{}{}'.format(distance, rev[:7], suffix))
local = '+{}.g{}{}'.format(distance, rev[:7], '.dirty' if dirty else '')
return parse_version(str(version) + local)

Loading…
Cancel
Save