From 96e42b8e811f28855ddae8721361f7ffccbaa19b Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 14 Apr 2023 18:35:50 +0000 Subject: [PATCH] upgrade-zulip-from-git: Extract code to set zulip upstream remote. --- scripts/lib/update-git-upstream | 11 +++++++++++ scripts/lib/upgrade-zulip-from-git | 21 ++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) create mode 100755 scripts/lib/update-git-upstream diff --git a/scripts/lib/update-git-upstream b/scripts/lib/update-git-upstream new file mode 100755 index 0000000000..1cf17f933b --- /dev/null +++ b/scripts/lib/update-git-upstream @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -eu + +upstream_url="https://github.com/zulip/zulip.git" +if ! git remote | grep -qx upstream; then + git remote add upstream "$upstream_url" +else + git remote set-url upstream "$upstream_url" +fi + +git fetch --prune --quiet --tags --all diff --git a/scripts/lib/upgrade-zulip-from-git b/scripts/lib/upgrade-zulip-from-git index 335e278843..48bd8527a4 100755 --- a/scripts/lib/upgrade-zulip-from-git +++ b/scripts/lib/upgrade-zulip-from-git @@ -25,8 +25,9 @@ from scripts.lib.zulip_tools import ( config_file = get_config_file() deploy_options = get_deploy_options(config_file) -upstream_url = "https://github.com/zulip/zulip.git" -remote_url = get_config(config_file, "deployment", "git_repo_url", upstream_url) +remote_url = get_config( + config_file, "deployment", "git_repo_url", "https://github.com/zulip/zulip.git" +) assert_running_as_root(strip_lib_from_paths=True) @@ -132,21 +133,7 @@ try: preexec_fn=su_to_zulip, ) - # Ensure upstream remote is configured; we need this to make `git describe` accurate. - remotes = subprocess.check_output(["git", "remote"], preexec_fn=su_to_zulip).split(b"\n") - if b"upstream" not in remotes: - subprocess.check_call( - ["git", "remote", "add", "upstream", upstream_url], preexec_fn=su_to_zulip - ) - else: - subprocess.check_call( - ["git", "remote", "set-url", "upstream", upstream_url], preexec_fn=su_to_zulip - ) - - logging.info("Fetching the latest commits") - subprocess.check_call( - ["git", "fetch", "--prune", "--quiet", "--tags", "--all"], preexec_fn=su_to_zulip - ) + subprocess.check_call(["./scripts/lib/update-git-upstream"], preexec_fn=su_to_zulip) # Generate the deployment directory via git worktree from our local repository. try: