Try to auto-detect revision in append mode if not specified
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Benjamin Renard 2022-12-13 10:45:28 +01:00
parent bc072ccf32
commit 1f2ae28cf0

25
gitdch
View file

@ -10,6 +10,7 @@ import sys
import textwrap
import git
from git.exc import GitCommandError
VERSION = '0.0'
DEFAULT_GIT_PATCH = './'
@ -244,6 +245,30 @@ if not options.version:
repo.git.describe('--always', '--tags')
)
log.info('Currrent version detected: %s', options.version)
if options.output and options.append and not options.revision:
log.info(
'Append mode enabled but no revision specify, try to detect it from '
'last modification of the changelog file')
try:
last_change_commit = next(repo.iter_commits(paths=options.output))
# pylint: disable=consider-using-f-string
options.revision = '{0}..HEAD'.format(last_change_commit)
log.info(
'Last change commit of the output file is "%s": use revision "%s"',
last_change_commit, options.revision)
except StopIteration:
log.warning(
'Fail to auto-detect last change commit of changelog file: it '
'seem not tracked. Continue without revision.')
except GitCommandError:
log.warning(
"Fail to auto-detect last change commit of changelog file. May "
"be it's outside of the git repository. Continue without "
"revision.")
# Reset repo object of to avoid BrokenPipeError
repo = git.Repo(options.git_path)
log.info('Generate changelog from git commits')
versions = []