upgrade-zulip-from-git: Provide better error message on a bad refname.

This commit is contained in:
Alex Vandiver
2025-10-08 01:59:23 +00:00
committed by Tim Abbott
parent 800cfc4421
commit c903128eb7

View File

@@ -148,28 +148,34 @@ try:
) )
# Generate the deployment directory via git worktree from our local repository. # Generate the deployment directory via git worktree from our local repository.
try: try_refs = [
fullref = f"refs/tags/{refname}" f"refs/tags/{refname}",
commit_hash = subprocess.check_output( f"refs/heads/{refname}" if args.local_ref else f"refs/remotes/origin/{refname}",
["git", "rev-parse", "--verify", fullref], ]
commit_hash: str | None = None
fullref: str | None = None
for ref in try_refs:
result = subprocess.run(
["git", "rev-parse", "--verify", ref],
preexec_fn=su_to_zulip, preexec_fn=su_to_zulip,
text=True, text=True,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
).strip() check=False,
except subprocess.CalledProcessError as e: )
if e.returncode == 128: if result.returncode == 0:
# Try in the origin namespace, or local heads if --local-ref fullref = ref
if args.local_ref: commit_hash = result.stdout.strip()
fullref = f"refs/heads/{refname}" break
else: elif result.returncode != 128:
fullref = f"refs/remotes/origin/{refname}" result.check_returncode()
commit_hash = subprocess.check_output( if not commit_hash or not fullref:
["git", "rev-parse", "--verify", fullref], logging.error(
preexec_fn=su_to_zulip, "Failed to resolve %s as a tag or %s branch name!",
text=True, refname,
stderr=subprocess.DEVNULL, "local" if args.local_ref else "remote",
).strip() )
refname = fullref sys.exit(1)
subprocess.check_call( subprocess.check_call(
["git", "worktree", "add", "--detach", deploy_path, refname], ["git", "worktree", "add", "--detach", deploy_path, refname],
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,