diff mbox series

ez: allow remote-tracking branches as 'base-branch'

Message ID 20230219-allow-remote-branches-as-base-v1-1-a1cf7948b2cc@gmail.com (mailing list archive)
State Superseded
Headers show
Series ez: allow remote-tracking branches as 'base-branch' | expand

Commit Message

Philippe Blain Feb. 20, 2023, 12:45 a.m. UTC
Since 83b185a (ez: support enrolling branches using tags, 2022-08-16),
we use 'git show-ref --heads' to check if the argument given to
'--enroll-base' is a branch, so that the alternate code path can be
taken for tags. This means that since that commit, using a
remote-tracking branch as argument to '--enroll-base' does not work
well, because such branches are not shown by 'git show-ref --heads'. The
code path for tags is taken instead, and this usually leads to a
"Multiple branches contain object" error (since several local branches
are often based on the same remote-tracking branch).

Pass a fully-qualified ref 'refs/heads/<enroll_base>' as pattern to 'git
show-ref', and also pass it a second second pattern
'refs/remotes/<enroll_base>' to allow both local and remote-tracking
branches.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
 b4/ez.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: a3281834d6d5dec44f58071fca2d22e04a97fe18
change-id: 20230219-allow-remote-branches-as-base-1ccdeb741f0c
--
b4

Comments

Philippe Blain Feb. 24, 2023, 2:57 p.m. UTC | #1
Hi Konstantin

Le 2023-02-19 à 19:45, Philippe Blain a écrit :
> Since 83b185a (ez: support enrolling branches using tags, 2022-08-16),
> we use 'git show-ref --heads' to check if the argument given to
> '--enroll-base' is a branch, so that the alternate code path can be
> taken for tags. This means that since that commit, using a
> remote-tracking branch as argument to '--enroll-base' does not work
> well, because such branches are not shown by 'git show-ref --heads'. The
> code path for tags is taken instead, and this usually leads to a
> "Multiple branches contain object" error (since several local branches
> are often based on the same remote-tracking branch).
> 
> Pass a fully-qualified ref 'refs/heads/<enroll_base>' as pattern to 'git
> show-ref', and also pass it a second second pattern
> 'refs/remotes/<enroll_base>' to allow both local and remote-tracking
> branches.

I'll send a v2 of this to also allow '@{u}' as enroll-base, so you might want
to wait before applying it so that the whole series can be applied at the same time.

Cheers,

Philippe.
diff mbox series

Patch

diff --git a/b4/ez.py b/b4/ez.py
index 74afddc..9cafe0c 100644
--- a/b4/ez.py
+++ b/b4/ez.py
@@ -370,7 +370,7 @@  def start_new_series(cmdargs: argparse.Namespace) -> None:
         slug = re.sub(r'\W+', '-', branchname).strip('-').lower()
         enroll_base = cmdargs.enroll_base
         # Is it a branch?
-        gitargs = ['show-ref', '--heads', enroll_base]
+        gitargs = ['show-ref', f'refs/heads/{enroll_base}', f'refs/remotes/{enroll_base}']
         lines = b4.git_get_command_lines(None, gitargs)
         if lines:
             try: