From b287d9f6439763cbe4bcf5bb259ffe8b87b35b8e Mon Sep 17 00:00:00 2001 From: James Edwards Date: Wed, 15 Nov 2023 06:08:50 -0700 Subject: [PATCH] convert svn access to github to git sparse checkout --- manic/repository_git.py | 26 ++++++++++++++++---------- manic/repository_svn.py | 3 +++ manic/sourcetree.py | 10 +++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/manic/repository_git.py b/manic/repository_git.py index ac55084..ec20935 100644 --- a/manic/repository_git.py +++ b/manic/repository_git.py @@ -362,12 +362,20 @@ def _checkout_external_ref(self, verbosity, submodules, dirname): def _sparse_checkout(self, repo_dir, verbosity): """Use git read-tree to thin the working tree.""" - cmd = ['cp', os.path.join(repo_dir, self._sparse), - os.path.join(repo_dir, - '.git/info/sparse-checkout')] - if verbosity >= VERBOSITY_VERBOSE: - printlog(' {0}'.format(' '.join(cmd))) - execute_subprocess(cmd) + + sparse_filepath = os.path.join(repo_dir, self._sparse) + if os.path.isfile(sparse_filepath): + cmd = ['cp', os.path.join(repo_dir, self._sparse), + os.path.join(repo_dir, + '.git/info/sparse-checkout')] + if verbosity >= VERBOSITY_VERBOSE: + printlog(' {0}'.format(' '.join(cmd))) + execute_subprocess(cmd) + else: + with open(os.path.join(repo_dir,'.git/info/sparse-checkout'),"w") as fsc: + fsc.write("/"+self._sparse+"/") + + self._git_sparse_checkout(verbosity, repo_dir) def _check_for_valid_ref(self, ref, remote_name, dirname): @@ -380,6 +388,7 @@ def _check_for_valid_ref(self, ref, remote_name, dirname): is_tag = self._ref_is_tag(ref, dirname) is_branch = self._ref_is_branch(ref, remote_name, dirname) is_hash = self._ref_is_hash(ref, dirname) + is_valid = is_tag or is_branch or is_hash if not is_valid: msg = ('In repo "{0}": reference "{1}" does not appear to be a ' @@ -709,10 +718,7 @@ def _git_lsremote_branch(ref, remote_name, dirname): cmd = ('git -C {dirname} ls-remote --exit-code --heads ' '{remote_name} {ref}').format( dirname=dirname, remote_name=remote_name, ref=ref).split() - status, output = execute_subprocess(cmd, status_to_caller=True, output_to_caller=True) - if not status and not f"refs/heads/{ref}" in output: - # In this case the ref is contained in the branch name but is not the complete branch name - return -1 + status = execute_subprocess(cmd, status_to_caller=True) return status @staticmethod diff --git a/manic/repository_svn.py b/manic/repository_svn.py index 922855d..32a7118 100644 --- a/manic/repository_svn.py +++ b/manic/repository_svn.py @@ -42,6 +42,9 @@ def __init__(self, component_name, repo, ignore_ancestry=False): Parse repo (a XML element). """ Repository.__init__(self, component_name, repo) + if 'github.com' in self._url: + msg = "SVN access to github.com is no longer supported" + fatal_error(msg) self._ignore_ancestry = ignore_ancestry if self._url.endswith('/'): # there is already a '/' separator in the URL; no need to add another diff --git a/manic/sourcetree.py b/manic/sourcetree.py index cf2a5b7..9db8783 100644 --- a/manic/sourcetree.py +++ b/manic/sourcetree.py @@ -293,7 +293,15 @@ def __init__(self, root_dir, ext_description, svn_ignore_ancestry=False): required = desc[ExternalsDescription.REQUIRED] repo_info = desc[ExternalsDescription.REPO] subexternals_path = desc[ExternalsDescription.EXTERNALS] - + if repo_info['protocol'] == 'svn' and 'github.com' in repo_info['repo_url']: + # change to git sparse checkout + repo_info['protocol'] = 'git' + if repo_info['repo_url'].endswith('tags/'): + repo_info['repo_url'] = (repo_info['repo_url'])[:-5] + slash_index = repo_info['tag'].index('/') + repo_info['sparse'] = (repo_info['tag'])[slash_index+1:] + repo_info['tag'] = (repo_info['tag'])[:slash_index] + repo = create_repository(comp, repo_info, svn_ignore_ancestry=svn_ignore_ancestry)