summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-04-03 12:10:45 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-04-03 12:10:45 -0400
commit47bec119bedea0d283ded3d4ee29f19f3939ff4d (patch)
tree105133628e8d0efe9f051e73f7cc215ab700afec
parent207146d12f224d420db8d67e86ceff53d3768cb7 (diff)
downloadb4-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.py14
1 files 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