From 83a93fb928952d88801308aa6fab4996f439b96d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 10 Oct 2025 16:14:17 -0700 Subject: [PATCH] Revert "upgrade-zulip-from-git: Provide better error message on a bad refname." This reverts commit c903128eb70b762cec00e34f5cbf5eb694baca11. --- scripts/lib/upgrade-zulip-from-git | 44 +++++++++++++----------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/scripts/lib/upgrade-zulip-from-git b/scripts/lib/upgrade-zulip-from-git index 8540315e5e..31d9169398 100755 --- a/scripts/lib/upgrade-zulip-from-git +++ b/scripts/lib/upgrade-zulip-from-git @@ -148,34 +148,28 @@ try: ) # Generate the deployment directory via git worktree from our local repository. - try_refs = [ - f"refs/tags/{refname}", - f"refs/heads/{refname}" if args.local_ref else f"refs/remotes/origin/{refname}", - ] - commit_hash: str | None = None - fullref: str | None = None - for ref in try_refs: - result = subprocess.run( - ["git", "rev-parse", "--verify", ref], + try: + fullref = f"refs/tags/{refname}" + commit_hash = subprocess.check_output( + ["git", "rev-parse", "--verify", fullref], preexec_fn=su_to_zulip, text=True, stderr=subprocess.DEVNULL, - check=False, - ) - if result.returncode == 0: - fullref = ref - commit_hash = result.stdout.strip() - break - elif result.returncode != 128: - result.check_returncode() - if not commit_hash or not fullref: - logging.error( - "Failed to resolve %s as a tag or %s branch name!", - refname, - "local" if args.local_ref else "remote", - ) - sys.exit(1) - + ).strip() + except subprocess.CalledProcessError as e: + if e.returncode == 128: + # Try in the origin namespace, or local heads if --local-ref + if args.local_ref: + fullref = f"refs/heads/{refname}" + else: + fullref = f"refs/remotes/origin/{refname}" + commit_hash = subprocess.check_output( + ["git", "rev-parse", "--verify", fullref], + preexec_fn=su_to_zulip, + text=True, + stderr=subprocess.DEVNULL, + ).strip() + refname = fullref subprocess.check_call( ["git", "worktree", "add", "--detach", deploy_path, refname], stdout=subprocess.DEVNULL,