From patchwork Mon Mar 6 18:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13162134 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 998EB5688 for ; Mon, 6 Mar 2023 18:02:38 +0000 (UTC) Received: by mail-qt1-f171.google.com with SMTP id l13so11545478qtv.3 for ; Mon, 06 Mar 2023 10:02:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678125757; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7HQNg8EQrFWtBtioJevpMEGmMhPCRFMSwx/o3zTZP48=; b=gOpwy5xIVVI0Q3UH8b87nAdIW9OXE2DrEuwaoYa5mrQRbqr4nGds9DWWyXua+oIQ4U qZfZ2/eQjV/AQcFtbUJ26gnr2pH5pI041S5pAnfv2UZUMZEYZplWdNGyCHuISNO1o0eb 4cnL/hWDcgjif8QwBA8paUiG/V7lfyrUnADc5QOXnYuHe47BHtbv/pW396KRMRE859d8 w/vFyBzT4v3hfens75siy+g80U5IHwW3ksvhiY+Ai5JDIa1JsgFrJm+pmUkIUbE3jHHf ia4zU1PWEicZGG5eP4fIglEe/KBkRr7JUnG5LsICAeLdxLXiGFy0Nw7ayCHks6Jd+Obi S16A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678125757; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7HQNg8EQrFWtBtioJevpMEGmMhPCRFMSwx/o3zTZP48=; b=MjWwXzm0i2uB148ZQbtZpn/60upYFEKF45JORvK1y1TJALzGlcL0A4GhzQfqgvU97W sFmG1jlsv5NszRSVzjoGklh5znDHEowx9R+4Y1dec3aZ+Hy3FCnF3TPtk5fHjGJ4kwcd tSA4Hoa0OZU8l/vLtEJ/DGIZfuuVgYtSBll0zUjWcUAsOKm5VU/gj/5hs8ZQFE9O1mQy eNaKB+zNWdNf5XQQ9aJCeeFOT2p0t0D5J0VP2NM8ywhdsG/yAiZG1a1pGdgZ44RJfKZK g5XzJ8TV1nxJXrS8h5zIqPvT8Gr0jy0JEWL5p0KSXKu6fRTXKUn6Z8LYhKCstusBsypM jyoA== X-Gm-Message-State: AO0yUKUtdFuX4ZDONA6q7hFuQgtImYXPlD85Aof80DWScruiltsCA1UG T8lXMLs1cRgsoyqGMS0/+Jk= X-Google-Smtp-Source: AK7set9ifmjRj80i+BsIOvufXJOjjmdvc7AwxazJzWACi10GTejP/tPVNY9ZDWOdnKo26WR6gXL2ng== X-Received: by 2002:ac8:7d84:0:b0:3b9:fb0e:adba with SMTP id c4-20020ac87d84000000b003b9fb0eadbamr19722097qtd.25.1678125757466; Mon, 06 Mar 2023 10:02:37 -0800 (PST) Received: from WQUEN758573.ncr.int.ec.gc.ca (ecodor132.cmc.ec.gc.ca. [205.211.133.132]) by smtp.gmail.com with ESMTPSA id d24-20020ac800d8000000b003bfaf01af24sm8050763qtg.46.2023.03.06.10.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 10:02:37 -0800 (PST) From: Philippe Blain Date: Mon, 06 Mar 2023 13:02:09 -0500 Subject: [PATCH v2 1/4] ez: allow remote-tracking branches as ENROLL_BASE Precedence: bulk X-Mailing-List: tools@linux.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230219-allow-remote-branches-as-base-v2-1-8db83bda1403@gmail.com> References: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> In-Reply-To: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> To: "Kernel.org Tools" Cc: Konstantin Ryabitsev , Philippe Blain X-Mailer: b4 0.13-dev-10ee4 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/' as pattern to 'git show-ref', and also pass it a second second pattern 'refs/remotes/' to allow both local and remote-tracking branches. Signed-off-by: Philippe Blain --- b4/ez.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/b4/ez.py b/b4/ez.py index daa1b4f..c3b0237 100644 --- a/b4/ez.py +++ b/b4/ez.py @@ -371,7 +371,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: From patchwork Mon Mar 6 18:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13162135 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D648566C for ; Mon, 6 Mar 2023 18:02:39 +0000 (UTC) Received: by mail-qt1-f179.google.com with SMTP id c18so11526614qte.5 for ; Mon, 06 Mar 2023 10:02:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678125758; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rXu+MAsRRE9/p4gzb8HwkzuzB02SQex4yHqgduUiRyU=; b=Zvy4SOEKxixnA7nVW4QaEApU3FX4Npe+Zoc3kxLl77yMSqZIi132USDu1IHa/8NO5S SQP9O67O9u5nYh6gzUhjkxwXgM+BbJlPOOXCKGY/QOd0qrjMNtt58v7HlJJuviQeEMBp /F+X1mZMmse4Em4J35SNNEq2xkludN6wfGVnKInOVgpqq+TmOsvV8JfI3rI7uR7XZGU8 JDw/N7DrPn5iGzisFgdbGwnvDuPqls2vBUH5Qiwqx41rZfnsAV0Bts2275+/8t36mTj+ t2VObHHdGhSGdWoK0/GI7Plyk3qcrv/i3jRl+Hu5KkYWUqXn6d9G8PfMwnlABXmtXA08 LNSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678125758; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rXu+MAsRRE9/p4gzb8HwkzuzB02SQex4yHqgduUiRyU=; b=2uYA91jxAnpqGKH5oF+MuJ82PRO/tbawHY8WqzZrfIPSzLUPk8wddKHnOMqNKMVlMA 8p/23ZSHjqKEaJ9b+5cmfRfMrS4es0QD2aO3U15KzBSuX0e9l0T4grqnwvPOVm1QjEVy cakBoyQvcvz6Oikhpum0DRy1Zkj6wDrexUElTlvZqxQJ141K4JUZpTK33AKx7xz89+C8 nvVH/52vT39em2tTxNSCDyy4Hxv/IkEqlLWoHd22UJGNMLHJSrzW4aTT4q6XcYHnMpaX /srY9BAKIKV4JfMeXupbFvCf5GW7YKS3Zzt9TI7+k0FjsOlA6Zip4Nsi8rhpNbpoyjXj jUiA== X-Gm-Message-State: AO0yUKXP0TW1LCc7ZgsMyn2dsJCvcMG6itkmpDQrNlDHX733Rk5o48hf 7drQ7MxsDDFSY3i4sOSiuA+LkAk9s8c= X-Google-Smtp-Source: AK7set+DAyiapFzxQwkHnRIGDeAvx7/kF+4VOmlKZ84RNA9RgsrVFzwG/vZP67foBclkkBXsuSrhYQ== X-Received: by 2002:a05:622a:34a:b0:3bf:d258:c151 with SMTP id r10-20020a05622a034a00b003bfd258c151mr21654670qtw.12.1678125758419; Mon, 06 Mar 2023 10:02:38 -0800 (PST) Received: from WQUEN758573.ncr.int.ec.gc.ca (ecodor132.cmc.ec.gc.ca. [205.211.133.132]) by smtp.gmail.com with ESMTPSA id d24-20020ac800d8000000b003bfaf01af24sm8050763qtg.46.2023.03.06.10.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 10:02:38 -0800 (PST) From: Philippe Blain Date: Mon, 06 Mar 2023 13:02:10 -0500 Subject: [PATCH v2 2/4] ez: also check remote-tracking branches when ENROLL_BASE is not a branch Precedence: bulk X-Mailing-List: tools@linux.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230219-allow-remote-branches-as-base-v2-2-8db83bda1403@gmail.com> References: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> In-Reply-To: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> To: "Kernel.org Tools" Cc: Konstantin Ryabitsev X-Mailer: b4 0.13-dev-10ee4 When invoking 'b4 prep --enroll ENROLL_BASE' with a revision ENROLL_BASE that does not correspond to a branch, ez.py::start_new_series tries to find branches where the commit corresponding to the given revision is found. If there is only one such branch, it is used as the 'base-branch'. The function 'git_branch_contains' used to find where the commit lives invokes 'git branch --contains', so only local branches are checked. This means that if the given revision corresponds to a remote-tracking branch, git_branch_contains won't recognize it and we will hit: CRITICAL: No other branch contains %s: cannot use as fork base Ensure that remote-tracking branches are also checked by adding an optional 'checkall' argument to 'git_branch_contains', that in turns adds a '--all' argument to the 'git branch' invocation, such that both local and remote-tracking branches are checked. Add that argument to the call in 'start_new_series'. An alternative would be to unconditionnally invoke 'git branch' with '--all' in 'git_branch_contains', but this function is also called in pr.py::main and ty.py::auto_locate_pr to check if the tip commit of the given pull requests already exists in a local branch, and it seems safer to not change behaviour for these two functions. --- b4/__init__.py | 4 +++- b4/ez.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index 3138f3c..78418c1 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -2986,8 +2986,10 @@ def git_revparse_tag(gitdir: Optional[str], tagname: str) -> Optional[str]: return out.strip() -def git_branch_contains(gitdir: Optional[str], commit_id: str) -> List[str]: +def git_branch_contains(gitdir: Optional[str], commit_id: str, checkall: bool = False) -> List[str]: gitargs = ['branch', '--format=%(refname:short)', '--contains', commit_id] + if checkall: + gitargs.append('--all') lines = git_get_command_lines(gitdir, gitargs) return lines diff --git a/b4/ez.py b/b4/ez.py index c3b0237..ce080f1 100644 --- a/b4/ez.py +++ b/b4/ez.py @@ -390,7 +390,7 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: raise RuntimeError('Object %s not found' % enroll_base) forkpoint = out.strip() # check branches where this object lives - heads = b4.git_branch_contains(None, forkpoint) + heads = b4.git_branch_contains(None, forkpoint, checkall=True) if mybranch not in heads: logger.critical('CRITICAL: object %s does not exist on current branch', enroll_base) sys.exit(1) From patchwork Mon Mar 6 18:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13162136 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89DF65688 for ; Mon, 6 Mar 2023 18:02:40 +0000 (UTC) Received: by mail-qt1-f175.google.com with SMTP id y10so11555324qtj.2 for ; Mon, 06 Mar 2023 10:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678125759; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BNeuD7CgzJcQRuKPhk+GTp/R3+BoF07Vo2yOIrBMYFE=; b=c4MxINkbmhEySSbFRKFs3OSDyS222OehhN5Tuw2zyNONuuJcsB99wh4NKgWcFGcfik tmh5Xy66vaINHdtvk5lmbzB8fVM1DBFuiYn0f5wt51AR/4+CQ61JsuLeIzV/mv6KqxCv GdZ8CWVmTL1PnrMEg2XjQCeEQYOhZxjo1/DTYYLrkAJyDWGtQIsQYpvr8ZW1+0riqSbe gQskevZP4lAzXMntvsQ8Q5KS9gFsVE1kIN4kt83a8prWuA3eLaVLpLMFRNhPNLH1etn+ syejStuOV0JCuUydj5utFs0h4xoMgbQW3Psn20lfmT//LpHlkq5v4lIWsygXjUjlTzqi xBsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678125759; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BNeuD7CgzJcQRuKPhk+GTp/R3+BoF07Vo2yOIrBMYFE=; b=4KT5xb4tTwl9kCbybBUuY26V4R8CYjVdRx+LbyvbCKvGIa3IxJ5SdP649vPcArwDqM eWgKNCBEsKE4rMVkTdKvghMMQduaC1WIirOAPakg9FmHdZl3SJpZzxaJjlc0Bn6t79/T 2531pU4RaSGYfEBtuJwiM/VbscAvNq4IYyVNfpSZx5MgEYCHubB7xjMH/95ss7l8i9HJ FfOao5HL6vnHw5CBzgI1L5Smkgf9un4uoyJYCzT+LDQse5A/lpuJL9h1uF7qf9yjEAjD mwqDEHxXLK+7Rnrr8e5yhRpSTcBsRdC9K9hgnZrRu/Uy8BS+YIjzaDf8xAM/t8vyRtlz ZIsQ== X-Gm-Message-State: AO0yUKXxMEU5gKfW7oC2kNSy2lqtt4XwSovOcOVVYt9tDiqsFPeVSECm nZkYh1c4SbwM9Gwwu3w1RXc= X-Google-Smtp-Source: AK7set9tRZ/whvpUk1BLIK57gwW9yRC+gtbYoBjQ3gDGHjN8n2du19evcxYbqQTaXTY5p4t2F6y17g== X-Received: by 2002:ac8:57c4:0:b0:3bd:1a07:2086 with SMTP id w4-20020ac857c4000000b003bd1a072086mr21531943qta.36.1678125759480; Mon, 06 Mar 2023 10:02:39 -0800 (PST) Received: from WQUEN758573.ncr.int.ec.gc.ca (ecodor132.cmc.ec.gc.ca. [205.211.133.132]) by smtp.gmail.com with ESMTPSA id d24-20020ac800d8000000b003bfaf01af24sm8050763qtg.46.2023.03.06.10.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 10:02:39 -0800 (PST) From: Philippe Blain Date: Mon, 06 Mar 2023 13:02:11 -0500 Subject: [PATCH v2 3/4] ez: allow '@{upstream}' as ENROLL_BASE Precedence: bulk X-Mailing-List: tools@linux.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230219-allow-remote-branches-as-base-v2-3-8db83bda1403@gmail.com> References: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> In-Reply-To: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> To: "Kernel.org Tools" Cc: Konstantin Ryabitsev X-Mailer: b4 0.13-dev-10ee4 Invoking 'b4 prep --enroll @{u}' (or @{upstream}) does not work reliably with the current code. In 'start_new_series', we take the code path that checks on which branch the object given as ENROLL_BASE lives using 'git branch --all --contains', so if multiple local branches build on top of the current branch's upstream branch, they are all listed by this invocation of 'git branch' and so we error with 'CRITICAL: Multiple branches contain object @{u}, please pass a branch name as base'. Fix that by invoking 'git rev-parse --abbrev-ref --verify ENROLL_BASE' before the 'git show-branch' invocation. That command will convert @{u}, @{upstream} and @{push} [1-2] to an abbreviated ref like 'upstream/master'. If the given revision exist but can't be directly converted to an abbreviated ref, the command will succeed and not output anything, so only change ENROLL_BASE when we actually get an output. We avoid checking the error code as we already invoke 'git rev-parse --verify' later on to check if the object exists. We could use 'git_get_command_lines' instead, but we will check the error code in a subsequent commit, so it makes more sense to use 'git_run_command'. While at it, fix a "CRITICAL" error message that was missing a value for the '%s' string formatting operator. [1] https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltbranchnamegtupstreamemegemmasterupstreamememuem [2] https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltbranchnamegtpushemegemmasterpushemempushem --- b4/ez.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/b4/ez.py b/b4/ez.py index ce080f1..53a4b2f 100644 --- a/b4/ez.py +++ b/b4/ez.py @@ -370,6 +370,11 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: seriesname = branchname slug = re.sub(r'\W+', '-', branchname).strip('-').lower() enroll_base = cmdargs.enroll_base + # Convert @{upstream}, @{push} to an abbreviated ref + gitargs = ['rev-parse', '--abbrev-ref', '--verify', enroll_base] + ecode, out = b4.git_run_command(None, gitargs) + if out: + enroll_base = out.strip() # Is it a branch? gitargs = ['show-ref', f'refs/heads/{enroll_base}', f'refs/remotes/{enroll_base}'] lines = b4.git_get_command_lines(None, gitargs) @@ -377,7 +382,7 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: try: forkpoint = get_base_forkpoint(enroll_base, mybranch) except RuntimeError as ex: - logger.critical('CRITICAL: could not use %s as enrollment base:') + logger.critical('CRITICAL: could not use %s as enrollment base:', enroll_base) logger.critical(' %s', ex) sys.exit(1) basebranch = enroll_base From patchwork Mon Mar 6 18:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13162137 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6000D566C for ; Mon, 6 Mar 2023 18:02:41 +0000 (UTC) Received: by mail-qt1-f178.google.com with SMTP id c18so11526743qte.5 for ; Mon, 06 Mar 2023 10:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678125760; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rN7uYZ4QcEqbO96RtJqrI1JQVu1umhoDI3zhbFefnAY=; b=FxkC2mhiqwtj7rdlSnNbOIFzjN65Z4fXvUbp1ny3MePdssD0BECZtlqGVmMhUOpnxJ DkEBw5kf6wN3ywyR+nbSIa7no5S5Mu2pGUUdaQb96W4lHqxxEwmKqg7jNCkd0P6MGSmK wHlsyRkBKPsjgv5QarAdt+6vIcA45ieIzQfXbO6k3sWfKiTsF6+7XYdbDny1+65hgmLj BQauFRBh+IXTLNC8IHKe6aw7AI3Hitc/aeDa8x+2N61/kG2MMqwfUJMCtvpJXPMP1u1v BxCN5Fmyg+CaksncnvkXktsPQc2OiULggrbaRgts2vJiQfuu8pK1/cO2cisNQO1PTQea p0Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678125760; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rN7uYZ4QcEqbO96RtJqrI1JQVu1umhoDI3zhbFefnAY=; b=IWCXINzmbKwXhz69FkNnWzM5wtBTnnLeB4CGAaNy7Jzyz4rmbZ11KZNH3PwGu2xfSM Lro5GE7ERbwhdyizRnolPbTe7IK5+anWwwnx+3LIQdDakWbPJXYM8wSfuLUoloJrFiH1 tQMq/ZX04Z2sv1pwqlNFaIzpg2Hcina5BrC8EJzItS8GlomfmSYHWxzVAsMdk4f0HQFZ kb+1QJn0qZ9XY1RR8lwZX792zehnWp2W/M9AWulF08e+VtZyB660MSOj1Z+4qMfVaXMh 318Kt3c6hy05hBYGoiaoZidU2pO6H9ygGZwu0UaN6Hd+TdtbacG+9R1HeFTrQCaNk07p QSeA== X-Gm-Message-State: AO0yUKVPUVZNxNihVwaqGVeUkbPRCumTkJZswo3vkA3l3e5yz/EBnXuV N/gITa+0mCGu7qoT0TcBrxYyKKpFR2s= X-Google-Smtp-Source: AK7set/ilv3eE/mo8m/SdZsxadkFZjSSc00yTTatp8ZdNCET7rJKmCJ5AD7cTgvc6XZG/0lgg++vGQ== X-Received: by 2002:a05:622a:55:b0:3b8:6555:342c with SMTP id y21-20020a05622a005500b003b86555342cmr21432883qtw.11.1678125760355; Mon, 06 Mar 2023 10:02:40 -0800 (PST) Received: from WQUEN758573.ncr.int.ec.gc.ca (ecodor132.cmc.ec.gc.ca. [205.211.133.132]) by smtp.gmail.com with ESMTPSA id d24-20020ac800d8000000b003bfaf01af24sm8050763qtg.46.2023.03.06.10.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 10:02:40 -0800 (PST) From: Philippe Blain Date: Mon, 06 Mar 2023 13:02:12 -0500 Subject: [PATCH v2 4/4] ez: let ENROLL_BASE default to '@{upstream}' Precedence: bulk X-Mailing-List: tools@linux.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230219-allow-remote-branches-as-base-v2-4-8db83bda1403@gmail.com> References: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> In-Reply-To: <20230219-allow-remote-branches-as-base-v2-0-8db83bda1403@gmail.com> To: "Kernel.org Tools" Cc: Konstantin Ryabitsev X-Mailer: b4 0.13-dev-10ee4 It is a common worflow to set 'branch..merge' and 'branch..remote' to the remote-tracking branch that corresponds to the default branch of the canonical repository of the project (say 'upstream/master'), such that 'git rebase -i' automatically "does the right thing" and rebases only the commits in your feature branch that are not reachable from 'upstream/master'. The revision syntax '@{upstream}' (short: '@{u}') can be used to denote the configured upstream branch of the current branch. Support that workflow better by allowing the 'ENROLL_BASE' argument to 'b4 prep --enroll' to be ommitted and default to @{upstream}. To avoid a RuntimeError when enroll_base is @{upstream} (either from the default or because it was given litterally on the command line) and the current branch has no configured upstream, add some error-checking to the 'git rev-parse --verify --abbrev-ref' invocation along with a clear message. Let other error situations be handled by the second 'git rev-parse --verify' invocation later on. --- b4/command.py | 4 ++-- b4/ez.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/b4/command.py b/b4/command.py index e7656a5..1ae73d2 100644 --- a/b4/command.py +++ b/b4/command.py @@ -290,8 +290,8 @@ def setup_parser() -> argparse.ArgumentParser: ag_prepn.add_argument('-F', '--from-thread', metavar='MSGID', dest='msgid', help='When creating a new branch, use this thread') ag_prepe = sp_prep.add_argument_group('Enroll existing branch', 'Enroll existing branch for prep work') - ag_prepe.add_argument('-e', '--enroll', dest='enroll_base', - help='Enroll current branch, using the passed tag, branch, or commit as fork base') + ag_prepe.add_argument('-e', '--enroll', dest='enroll_base', nargs='?', const='@{upstream}', + help='Enroll current branch, using its configured upstream branch as fork base, or the passed tag, branch, or commit') sp_prep.set_defaults(func=cmd_prep) # b4 trailers diff --git a/b4/ez.py b/b4/ez.py index 53a4b2f..0a2936a 100644 --- a/b4/ez.py +++ b/b4/ez.py @@ -373,7 +373,11 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: # Convert @{upstream}, @{push} to an abbreviated ref gitargs = ['rev-parse', '--abbrev-ref', '--verify', enroll_base] ecode, out = b4.git_run_command(None, gitargs) - if out: + if ecode > 0: + if enroll_base == '@{upstream}' or enroll_base == '@{u}': + logger.critical('CRITICAL: current branch has no configured upstream') + sys.exit(1) + elif out: enroll_base = out.strip() # Is it a branch? gitargs = ['show-ref', f'refs/heads/{enroll_base}', f'refs/remotes/{enroll_base}']