diff options
author | Philippe Blain <levraiphilippeblain@gmail.com> | 2024-02-10 16:18:16 -0500 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2024-02-13 13:56:06 -0500 |
commit | b7ccd0f51896e38b995fe0e36f2388f65535593c (patch) | |
tree | e633e64d16fb159f0020612bb3a3d34732b8762a | |
parent | 1d8c58b15facf490336e0146aaabb1c5194bf733 (diff) | |
download | b4-b7ccd0f51896e38b995fe0e36f2388f65535593c.tar.gz |
ez: fall back to regular merge-base if --fork-point mode fails
If the 'git merge-base --fork-point' invocation in
ez::get_base_forkpoint fails and returns nothing, we abort, saying
basebranch and mybranch have no common ancestors.
Depending on how the current branch was created, and the state of the
branch's reflog, it is possible for this invocation to fail even if the
current branch and the chosen base branch do share a common ancestor,
for reasons expplained in git-merge-base(1) [1].
Support that situation better by adding a second invocation, using the
regular merge-base syntax 'git merge-base mybranch basebranch', and only
fail if that second invocation also returns nothing.
[1] https://git-scm.com/docs/git-merge-base#_discussion_on_fork_point_mode
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Link: https://msgid.link/20240210-ez-merge-base-no-fork-point-v1-1-b3f82cdd3bee@gmail.com
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/ez.py | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -233,8 +233,11 @@ def get_base_forkpoint(basebranch: str, mybranch: Optional[str] = None) -> str: gitargs = ['merge-base', '--fork-point', basebranch] lines = b4.git_get_command_lines(None, gitargs) if not lines: - logger.critical('CRITICAL: Could not find common ancestor with %s', basebranch) - raise RuntimeError('Branches %s and %s have no common ancestors' % (basebranch, mybranch)) + gitargs = ['merge-base', mybranch, basebranch] + lines = b4.git_get_command_lines(None, gitargs) + if not lines: + logger.critical('CRITICAL: Could not find common ancestor with %s', basebranch) + raise RuntimeError('Branches %s and %s have no common ancestors' % (basebranch, mybranch)) forkpoint = lines[0] logger.debug('Fork-point between %s and %s is %s', mybranch, basebranch, forkpoint) |