All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH b4] ez: fall back to regular merge-base if --fork-point mode fails
@ 2024-02-10 21:18 Philippe Blain
  2024-02-13 18:56 ` Konstantin Ryabitsev
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Blain @ 2024-02-10 21:18 UTC (permalink / raw
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Philippe Blain

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>
---
 b4/ez.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/b4/ez.py b/b4/ez.py
index 7baff8f..bad8c4a 100644
--- a/b4/ez.py
+++ b/b4/ez.py
@@ -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)
 

---
base-commit: e790d97805add21c1c5fe22642e403b8c8889ed6
change-id: 20240210-ez-merge-base-no-fork-point-a8b51551ff36


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH b4] ez: fall back to regular merge-base if --fork-point mode fails
  2024-02-10 21:18 [PATCH b4] ez: fall back to regular merge-base if --fork-point mode fails Philippe Blain
@ 2024-02-13 18:56 ` Konstantin Ryabitsev
  0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Ryabitsev @ 2024-02-13 18:56 UTC (permalink / raw
  To: Kernel.org Tools, Philippe Blain


On Sat, 10 Feb 2024 16:18:16 -0500, Philippe Blain wrote:
> 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].
> 
> [...]

Applied, thanks!

[1/1] ez: fall back to regular merge-base if --fork-point mode fails
      commit: b7ccd0f51896e38b995fe0e36f2388f65535593c

Best regards,
-- 
Konstantin Ryabitsev <konstantin@linuxfoundation.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-13 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-10 21:18 [PATCH b4] ez: fall back to regular merge-base if --fork-point mode fails Philippe Blain
2024-02-13 18:56 ` Konstantin Ryabitsev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.