diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-04-03 12:10:45 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-04-03 12:10:45 -0400 |
commit | 47bec119bedea0d283ded3d4ee29f19f3939ff4d (patch) | |
tree | 105133628e8d0efe9f051e73f7cc215ab700afec | |
parent | 207146d12f224d420db8d67e86ceff53d3768cb7 (diff) | |
download | b4-47bec119bedea0d283ded3d4ee29f19f3939ff4d.tar.gz |
Auto-discover base commit when none provided
When a pull request is generated using git-request-pull, the base commit
is specified in the body of the message. However, in other cases this
information can be missing, so we can use git merge-base to find out
what it is after we've performed a "git fetch".
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/pr.py | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -211,6 +211,17 @@ def explode(gitdir, lmsg, savefile): ecode = fetch_remote(gitdir, lmsg) if ecode > 0: sys.exit(ecode) + if not lmsg.pr_base_commit: + # Use git merge-base between HEAD and FETCH_HEAD to find + # where we should start + logger.info('Running git merge-base to find common ancestry') + gitargs = ['merge-base', 'HEAD', 'FETCH_HEAD'] + ecode, out = b4.git_run_command(gitdir, gitargs, logstderr=True) + if ecode > 0: + logger.critical('Could not find common ancestry.') + logger.critical(out) + sys.exit(ecode) + lmsg.pr_base_commit = out.strip() logger.info('Generating patches starting from the base-commit') reroll = None if lmsg.revision > 1: @@ -309,9 +320,6 @@ def main(cmdargs): lmsg.pr_tip_commit = lmsg.pr_remote_tip_commit if cmdargs.explode: - if not lmsg.pr_base_commit: - logger.critical('ERROR: No base-commit info provided in the message.') - sys.exit(1) savefile = cmdargs.outmbox if savefile is None: savefile = '%s.mbx' % lmsg.msgid |