diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2022-07-27 13:08:28 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2022-07-27 13:08:28 -0400 |
commit | 9d64075f5902052a83a722306239ac8d033b84b3 (patch) | |
tree | a6a033ba3d16a8aeae175a757b481bef0426a111 | |
parent | d1cc204a33fc4ae0c2c5b7e6fe6aef720454d239 (diff) | |
download | b4-9d64075f5902052a83a722306239ac8d033b84b3.tar.gz |
ez: some cleanups and error handling for revision tagging
Handle some of the potential errors that could come up when tagging
historical versions.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/ez.py | 95 |
1 files changed, 51 insertions, 44 deletions
@@ -952,53 +952,60 @@ def cmd_send(cmdargs: argparse.Namespace) -> None: logger.info('Sent %s messages', counter) mybranch = b4.git_get_current_branch() - if get_cover_strategy() == 'commit': - # Detach the head at our parent commit and apply the cover-less series - cover_commit = find_cover_commit() - gitargs = ['checkout', f'{cover_commit}~1'] - ecode, out = b4.git_run_command(None, gitargs) - if ecode > 0: - # TODO: do something - raise RuntimeError('Could not switch to a detached head') - # cherry-pick from cover letter to the last commit - last_commit = patches[-1][0] - gitargs = ['cherry-pick', f'{cover_commit}..{last_commit}'] - ecode, out = b4.git_run_command(None, gitargs) - if ecode > 0: - # TODO: do something - raise RuntimeError('Could not cherry-pick the cover-less range') - # Find out the head commit - gitargs = ['rev-parse', 'HEAD'] - ecode, out = b4.git_run_command(None, gitargs) - if ecode > 0: - # TODO: do something - raise RuntimeError('Could not find the HEAD commit of the detached head') - tagcommit = out.strip() - # Switch back to our branch - gitargs = ['checkout', mybranch] + revision = tracking['series']['revision'] + + try: + if get_cover_strategy() == 'commit': + # Detach the head at our parent commit and apply the cover-less series + cover_commit = find_cover_commit() + gitargs = ['checkout', f'{cover_commit}~1'] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + raise RuntimeError('Could not switch to a detached head') + # cherry-pick from cover letter to the last commit + last_commit = patches[-1][0] + gitargs = ['cherry-pick', f'{cover_commit}..{last_commit}'] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + raise RuntimeError('Could not cherry-pick the cover-less range') + # Find out the head commit + gitargs = ['rev-parse', 'HEAD'] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + raise RuntimeError('Could not find the HEAD commit of the detached head') + tagcommit = out.strip() + # Switch back to our branch + gitargs = ['checkout', mybranch] + ecode, out = b4.git_run_command(None, gitargs) + if ecode > 0: + raise RuntimeError('Could not switch back to %s', mybranch) + else: + # TODO: commit-tip will have HEAD~1 + tagcommit = 'HEAD' + + # TODO: make sent/ prefix configurable? + tagprefix = 'sent/' + if mybranch.startswith('b4/'): + tagname = f'{tagprefix}{mybranch[3:]}-v{revision}' + else: + tagname = f'{tagprefix}{mybranch}-v{revision}' + + logger.debug('checking if we already have %s', tagname) + gitargs = ['rev-parse', f'refs/tags/{tagname}'] ecode, out = b4.git_run_command(None, gitargs) if ecode > 0: - # TODO: do something - raise RuntimeError('Could not switch back to %s', mybranch) - else: - # TODO: commit-tip will have HEAD~1 - tagcommit = 'HEAD' - - # TODO: make sent/ prefix configurable? - revision = tracking['series']['revision'] - tagprefix = 'sent/' - if mybranch.startswith('b4/'): - tagname = f'{tagprefix}{mybranch[3:]}-v{revision}' - else: - tagname = f'{tagprefix}{mybranch}-v{revision}' + logger.info('Tagging %s', tagname) + gitargs = ['tag', '-a', '-F', '-', tagname, tagcommit] + ecode, out = b4.git_run_command(None, gitargs, stdin=cover.encode()) + if ecode > 0: + # Not a fatal error, just complain about it + logger.info('Could not tag %s as %s:', tagcommit, tagname) + logger.info(out) + else: + logger.info('NOTE: Tagname %s already exists', tagname) - # TODO: check if we already have this tag for some reason - logger.info('Tagging %s', tagname) - gitargs = ['tag', '-a', '-F', '-', tagname, tagcommit] - ecode, out = b4.git_run_command(None, gitargs, stdin=cover.encode()) - if ecode > 0: - # TODO: do something - raise RuntimeError('Could not tag %s as %s', tagcommit, tagname) + except RuntimeError as ex: + logger.critical('Error tagging the revision: %s', ex) if not cover_msgid: return |