From c1713c5bc37b7e31bd84555066c06a72bb0f025b Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 14 Feb 2025 11:24:06 -0500 Subject: [PATCH] script/build-with-container: add --current-branch cli option Add a new --current-branch argument that lets the user supply a name for the current branch. This allows the automatic tag generation to avoid calling git - something useful if the tree is not using a git checkout (like a tarball). It also allows you to pull a temporary branch in git but ignore it and act like the temporary branch is the base branch. Signed-off-by: John Mulligan --- src/script/build-with-container.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/script/build-with-container.py b/src/script/build-with-container.py index f00eb39ce82d0..7b199eb42e6ef 100755 --- a/src/script/build-with-container.py +++ b/src/script/build-with-container.py @@ -286,10 +286,12 @@ class Context: def target_tag(self): if self.cli.tag: return self.cli.tag - try: - branch = _git_current_branch(self).replace("/", "-") - except subprocess.CalledProcessError: - branch = "UNKNOWN" + branch = self.cli.current_branch + if not branch: + try: + branch = _git_current_branch(self).replace("/", "-") + except subprocess.CalledProcessError: + branch = "UNKNOWN" return f"{branch}.{self.cli.distro}" @property @@ -668,6 +670,10 @@ def parse_cli(build_step_names): "-t", help="Specify a container tag", ) + parser.add_argument( + "--current-branch", + help="Manually specify the current branch name", + ) parser.add_argument( "--image-repo", help="Specify a container image repository", -- 2.39.5