[Diff][Fixed] KIBOT_TAG skipping commits, not tags

Fixes #430
This commit is contained in:
Salvador E. Tropea 2023-05-12 09:54:26 -03:00
parent 8404cd7613
commit 91ffb04661
2 changed files with 23 additions and 3 deletions

View File

@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Position:
- Components marked as "Exclude from position files" not excluded when only
SMD components are selected. (See #429)
- Diff:
- KIBOT_TAG with n > 0 skipped n commits, not n tags (#430)
## [1.6.2] - 2023-04-24
### Added

View File

@ -251,6 +251,25 @@ class DiffOptions(BaseOptions):
for sub in self.git_submodules():
self.stash_pop(sub)
def process_tags(self, num):
# Get a list of all tags ... and commits (how can I filter it?)
logger.debug('Looking for git tags')
res = self.run_git(['rev-list', '--tags', '--format=format:%D'])
if not res:
return res
res = res.split('\n')
commit = ''
skipped = 0
for v in res:
if v.startswith('tag: '):
tag = v.split(',')[0][4:]
logger.debugl(2, '- {}/{} tag: {} -> {}'.format(skipped, num, tag, commit))
if skipped == num:
return commit
skipped += 1
elif v.startswith('commit '):
commit = v[7:]
def solve_kibot_magic(self, name, tag):
# The magic KIBOT_*
ori = name
@ -265,12 +284,11 @@ class DiffOptions(BaseOptions):
num = int(name[1:])
except ValueError:
raise KiPlotConfigurationError(malformed)
num = str(num)
# Return its hash
if tag == 'KIBOT_LAST':
res = self.run_git(['log', '--pretty=format:%H', '--skip='+num, '-n', '1', '--', self.file])
res = self.run_git(['log', '--pretty=format:%H', '--skip='+str(num), '-n', '1', '--', self.file])
else: # KIBOT_TAG
res = self.run_git(['rev-list', '--tags', '--skip='+num, '--max-count=1'])
res = self.process_tags(num)
if not res:
raise KiPlotConfigurationError("The `{}` doesn't resolve to a valid hash".format(ori))
logger.debug('- '+res)