Skip to content

Commit

Permalink
better fix for issue with ssh access
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Jul 8, 2024
1 parent c624b61 commit e9cd2be
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
4 changes: 3 additions & 1 deletion git_fleximod/git_fleximod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 8 additions & 2 deletions git_fleximod/gitinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]:", "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)
Expand Down
29 changes: 13 additions & 16 deletions git_fleximod/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]:", "https://github.com/")
self.path = path
self.url = url
self.fxurl = fxurl
self.fxtag = fxtag
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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}")
Expand All @@ -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("[email protected]:", "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()
Expand All @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit e9cd2be

Please sign in to comment.