From 1639792e9e63fd01254fd4eb47b59ec4b0c9d81d Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 8 Jun 2022 19:33:45 -0700 Subject: [PATCH] upgrade-zulip-from-git: Check fetch refspecs, not mirror flag. While the `remote.origin.mirror` boolean being set is a very good proxy for having been cloned with `--mirror`, is technically only used when pushing into the remote[1]. What we care about is if fetches from this remote will overwrite `refs/heads/`, or all of `refs/` -- the latter of which is most likely, from having run `git clone --bare`. Detect either of these fetch refspecs, and not the mirror flag. We let the upgrade process error out if `remote.origin.fetch` is unset, as that represents an unexpected state. We ignore failures to unset the `remote.origin.mirror` flag, in case it is not set already. [1]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-remoteltnamegtmirror --- scripts/lib/upgrade-zulip-from-git | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/lib/upgrade-zulip-from-git b/scripts/lib/upgrade-zulip-from-git index 96d0eed515..4f3addd9bd 100755 --- a/scripts/lib/upgrade-zulip-from-git +++ b/scripts/lib/upgrade-zulip-from-git @@ -74,14 +74,18 @@ try: ["git", "remote", "set-url", "origin", remote_url], preexec_fn=su_to_zulip ) - # Check to see if it's the old "mirror" configuration - is_mirror = subprocess.check_output( - ["git", "config", "--bool", "--default=false", "remote.origin.mirror"], + fetch_spec = subprocess.check_output( + ["git", "config", "remote.origin.fetch"], preexec_fn=su_to_zulip, text=True, - ) - if is_mirror.strip() == "true": - subprocess.check_call( + ).strip() + if fetch_spec in ("+refs/*:refs/*", "+refs/heads/*:refs/heads/*"): + # The refspec impinges on refs/heads/ -- this is an old mirror + # configuration. + logging.info("Cleaning up mirrored repository") + # remotes.origin.mirror may not be set -- we do not use + # check_call to ignore errors if it's already missing + subprocess.call( ["git", "config", "--unset", "remote.origin.mirror"], preexec_fn=su_to_zulip, )