Try to auto-detect revision in append mode if not specified
This commit is contained in:
parent
bc072ccf32
commit
1f2ae28cf0
1 changed files with 25 additions and 0 deletions
25
gitdch
25
gitdch
|
@ -10,6 +10,7 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
from git.exc import GitCommandError
|
||||||
|
|
||||||
VERSION = '0.0'
|
VERSION = '0.0'
|
||||||
DEFAULT_GIT_PATCH = './'
|
DEFAULT_GIT_PATCH = './'
|
||||||
|
@ -244,6 +245,30 @@ if not options.version:
|
||||||
repo.git.describe('--always', '--tags')
|
repo.git.describe('--always', '--tags')
|
||||||
)
|
)
|
||||||
log.info('Currrent version detected: %s', options.version)
|
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')
|
log.info('Generate changelog from git commits')
|
||||||
|
|
||||||
versions = []
|
versions = []
|
||||||
|
|
Loading…
Reference in a new issue