upgrade-zulip-from-git: Provide a flag to use a local branch.

While this could be done previously by calling
`upgrade-zulip-from-git --remote-url /srv/zulip.git`, the explicit
argument makes this more straightforward, and avoids churning the
`refs/remotes/origin/` namespace.
This commit is contained in:
Alex Vandiver 2024-03-08 19:45:18 +00:00 committed by Tim Abbott
parent 6e18c84048
commit 5123477d55
1 changed files with 21 additions and 9 deletions

View File

@ -40,9 +40,15 @@ logging.basicConfig(format="%(asctime)s upgrade-zulip-from-git: %(message)s", le
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("refname", help="Git reference, e.g. a branch, tag, or commit ID.") parser.add_argument("refname", help="Git reference, e.g. a branch, tag, or commit ID.")
parser.add_argument( git_ref = parser.add_mutually_exclusive_group()
git_ref.add_argument(
"--remote-url", help="Override the Git remote URL configured in /etc/zulip/zulip.conf." "--remote-url", help="Override the Git remote URL configured in /etc/zulip/zulip.conf."
) )
git_ref.add_argument(
"--local-ref",
action="store_true",
help="Provided branch name has been pushed directly to /srv/zulip.git already",
)
args, extra_options = parser.parse_known_args() args, extra_options = parser.parse_known_args()
refname = args.refname refname = args.refname
@ -75,9 +81,10 @@ try:
subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR]) subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR])
os.chdir(LOCAL_GIT_CACHE_DIR) os.chdir(LOCAL_GIT_CACHE_DIR)
subprocess.check_call( if not args.local_ref:
["git", "remote", "set-url", "origin", remote_url], preexec_fn=su_to_zulip subprocess.check_call(
) ["git", "remote", "set-url", "origin", remote_url], preexec_fn=su_to_zulip
)
fetch_spec = subprocess.check_output( fetch_spec = subprocess.check_output(
["git", "config", "remote.origin.fetch"], ["git", "config", "remote.origin.fetch"],
@ -134,9 +141,11 @@ try:
preexec_fn=su_to_zulip, preexec_fn=su_to_zulip,
) )
subprocess.check_call( if not args.local_ref:
[os.path.join(get_deploy_root(), "scripts/lib/update-git-upstream")], preexec_fn=su_to_zulip subprocess.check_call(
) [os.path.join(get_deploy_root(), "scripts/lib/update-git-upstream")],
preexec_fn=su_to_zulip,
)
# Generate the deployment directory via git worktree from our local repository. # Generate the deployment directory via git worktree from our local repository.
try: try:
@ -149,8 +158,11 @@ try:
).strip() ).strip()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
if e.returncode == 128: if e.returncode == 128:
# Try in the origin namespace # Try in the origin namespace, or local heads if --local-ref
fullref = f"refs/remotes/origin/{refname}" if args.local_ref:
fullref = f"refs/heads/{refname}"
else:
fullref = f"refs/remotes/origin/{refname}"
commit_hash = subprocess.check_output( commit_hash = subprocess.check_output(
["git", "rev-parse", "--verify", fullref], ["git", "rev-parse", "--verify", fullref],
preexec_fn=su_to_zulip, preexec_fn=su_to_zulip,