From 47bec119bedea0d283ded3d4ee29f19f3939ff4d Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Fri, 3 Apr 2020 12:10:45 -0400 Subject: 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 --- b4/pr.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/b4/pr.py b/b4/pr.py index 25d693b..7efd398 100644 --- a/b4/pr.py +++ b/b4/pr.py @@ -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 -- cgit v1.2.3