From e9cd2bee6200f7bde68dec6e10d5491e3171cc4d Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 8 Jul 2024 09:49:35 -0600 Subject: [PATCH] better fix for issue with ssh access --- git_fleximod/git_fleximod.py | 4 +++- git_fleximod/gitinterface.py | 10 ++++++++-- git_fleximod/submodule.py | 29 +++++++++++++---------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index e28499de87..4595cd2ab2 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -93,7 +93,8 @@ def submodule_sparse_checkout(root_dir, name, url, path, sparsefile, tag="master """ logger.info("Called sparse_checkout for {}".format(name)) rgit = GitInterface(root_dir, logger) - superroot = rgit.git_operation("rev-parse", "--show-superproject-working-tree") + superroot = git_toplevelroot(root_dir, logger) + if superroot: gitroot = superroot.strip() else: @@ -178,6 +179,7 @@ def submodule_sparse_checkout(root_dir, name, url, path, sparsefile, tag="master def init_submodule_from_gitmodules(gitmodules, name, root_dir, logger): path = gitmodules.get(name, "path") url = gitmodules.get(name, "url") + assert path and url, f"Malformed .gitmodules file {path} {url}" tag = gitmodules.get(name, "fxtag") fxurl = gitmodules.get(name, "fxDONOTUSEurl") fxsparse = gitmodules.get(name, "fxsparse") diff --git a/git_fleximod/gitinterface.py b/git_fleximod/gitinterface.py index c7462b3a15..5831201446 100644 --- a/git_fleximod/gitinterface.py +++ b/git_fleximod/gitinterface.py @@ -49,8 +49,14 @@ def _init_git_repo(self): # pylint: disable=unused-argument def git_operation(self, operation, *args, **kwargs): - command = self._git_command(operation, *args) - self.logger.info(command) + newargs = [] + for a in args: + # Do not use ssh interface + if isinstance(a, str): + a = a.replace("git@github.com:", "https://github.com/") + newargs.append(a) + + command = self._git_command(operation, *newargs) if isinstance(command, list): try: return utils.execute_subprocess(command, output_to_caller=True) diff --git a/git_fleximod/submodule.py b/git_fleximod/submodule.py index daa0fef090..713ea344de 100644 --- a/git_fleximod/submodule.py +++ b/git_fleximod/submodule.py @@ -26,8 +26,7 @@ def __init__(self, root_dir, name, path, url, fxtag=None, fxurl=None, fxsparse=N """ self.name = name self.root_dir = root_dir - self.path = path - url = url.replace("git@github.com:", "https://github.com/") + self.path = path self.url = url self.fxurl = fxurl self.fxtag = fxtag @@ -46,6 +45,7 @@ def status(self): - localmods (bool): An indicator if the submodule has local modifications. - testfails (bool): An indicator if the submodule has failed a test, this is used for testing purposes. """ + smpath = os.path.join(self.root_dir, self.path) testfails = False localmods = False @@ -162,8 +162,7 @@ def _add_remote(self, git): if remotes: upstream = git.git_operation("ls-remote", "--get-url").rstrip() newremote = "newremote.00" - - line = next((s for s in remotes if self.url in s), None) + line = next((s for s in remotes if self.url or tmpurl in s), None) if line: newremote = line.split()[0] return newremote @@ -281,6 +280,7 @@ def sparse_checkout(self): print(f"Successfully checked out {self.name:>20} at {self.fxtag}") rgit.config_set_value(f'submodule "{self.name}"', "active", "true") rgit.config_set_value(f'submodule "{self.name}"', "url", self.url) + rgit.config_set_value(f'submodule "{self.name}"', "path", self.path) def update(self): """ @@ -308,11 +308,11 @@ def update(self): repodir = os.path.join(self.root_dir, self.path) self.logger.info("Checkout {} into {}/{}".format(self.name, self.root_dir, self.path)) # if url is provided update to the new url - tmpurl = None + tag = None repo_exists = False - # if os.path.exists(os.path.join(repodir, ".git")): - # self.logger.info("Submodule {} already checked out".format(self.name)) - # repo_exists = True + if os.path.exists(os.path.join(repodir, ".git")): + self.logger.info("Submodule {} already checked out".format(self.name)) + repo_exists = True # Look for a .gitmodules file in the newly checkedout repo if self.fxsparse: print(f"Sparse checkout {self.name} fxsparse {self.fxsparse}") @@ -324,9 +324,7 @@ def update(self): # opened with a GitModules object we don't need to worry about restoring the file here # it will be done by the GitModules class if self.url.startswith("git@"): - tmpurl = self.url - url = self.url.replace("git@github.com:", "https://github.com/") - git.git_operation("clone", url, self.path) + git.git_operation("clone", self.url, self.path) smgit = GitInterface(repodir, self.logger) if not tag: tag = smgit.git_operation("describe", "--tags", "--always").rstrip() @@ -347,14 +345,14 @@ def update(self): with open(os.path.join(repodir, ".git"), "w") as f: f.write("gitdir: " + os.path.relpath(newpath, start=repodir)) - + if not os.path.exists(repodir): parent = os.path.dirname(repodir) if not os.path.isdir(parent): os.makedirs(parent) git.git_operation("submodule", "add", "--name", self.name, "--", self.url, self.path) - if not repo_exists or not tmpurl: + if not repo_exists: git.git_operation("submodule", "update", "--init", "--", self.path) if self.fxtag: @@ -363,11 +361,10 @@ def update(self): if not os.path.exists(os.path.join(repodir, ".git")): utils.fatal_error( - f"Failed to checkout {self.name} {repo_exists} {tmpurl} {repodir} {self.path}" + f"Failed to checkout {self.name} {repo_exists} {repodir} {self.path}" ) - if tmpurl: - print(git.git_operation("restore", ".gitmodules")) + if os.path.exists(os.path.join(self.path, ".git")): submoddir = os.path.join(self.root_dir, self.path) with utils.pushd(submoddir):