Skip to content

Commit

Permalink
some fixes when modifying url
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Jun 1, 2024
1 parent 4aa073c commit 00b7b38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
49 changes: 27 additions & 22 deletions git_fleximod/git_fleximod.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ def single_submodule_checkout(

return

def add_remote(git, url):
remotes = git.git_operation("remote", "-v")
newremote = "newremote.00"
if url in remotes:
for line in remotes:
if url in line and "fetch" in line:
newremote = line.split()[0]
break
else:
i = 0
while "newremote" in remotes:
i = i + 1
newremote = f"newremote.{i:02d}"
git.git_operation("remote", "add", newremote, url)
return newremote

def submodules_status(gitmodules, root_dir, toplevel=False):
testfails = 0
Expand All @@ -271,6 +286,7 @@ def submodules_status(gitmodules, root_dir, toplevel=False):
for name in gitmodules.sections():
path = gitmodules.get(name, "path")
tag = gitmodules.get(name, "fxtag")
url = gitmodules.get(name, "url")
required = gitmodules.get(name, "fxrequired")
level = required and "Toplevel" in required
if not path:
Expand All @@ -280,7 +296,6 @@ def submodules_status(gitmodules, root_dir, toplevel=False):
if not os.path.exists(os.path.join(newpath, ".git")):
rootgit = GitInterface(root_dir, logger)
# submodule commands use path, not name
url = gitmodules.get(name, "url")
url = url.replace("[email protected]:", "https://github.com/")
tags = rootgit.git_operation("ls-remote", "--tags", url)
atag = None
Expand Down Expand Up @@ -312,11 +327,11 @@ def submodules_status(gitmodules, root_dir, toplevel=False):
with utils.pushd(newpath):
git = GitInterface(newpath, logger)
atag = git.git_operation("describe", "--tags", "--always").rstrip()
part = git.git_operation("status").partition("\n")[0]
# fake hash to initialize
ahash = "xxxx"
if part:
ahash = part.split()[-1]
ahash = git.git_operation("rev-list", "HEAD").partition("\n")[0]
rurl = git.git_operation("ls-remote","--get-url").rstrip()
if rurl != url:
remote = add_remote(git, url)
git.git_operation("fetch", remote)
if tag and atag == tag:
print(f" {name:>20} at tag {tag}")
elif tag and ahash[: len(tag)] == tag:
Expand All @@ -335,7 +350,7 @@ def submodules_status(gitmodules, root_dir, toplevel=False):
)
testfails += 1

status = git.git_operation("status", "--ignore-submodules")
status = git.git_operation("status", "--ignore-submodules", "-uno")
if "nothing to commit" not in status:
localmods = localmods + 1
print("M" + textwrap.indent(status, " "))
Expand All @@ -357,11 +372,11 @@ def submodules_update(gitmodules, root_dir, requiredlist, force):
path = gitmodules.get(name, "path")
url = gitmodules.get(name, "url")
logger.info(
"name={} path={} url={} fxtag={} requiredlist={}".format(
"name={} path={} url={} fxtag={} requiredlist={} ".format(
name, os.path.join(root_dir, path), url, fxtag, requiredlist
)
)
# if not os.path.exists(os.path.join(root_dir,path, ".git")):

fxrequired = gitmodules.get(name, "fxrequired")
assert fxrequired in fxrequired_allowed_values()
rgit = GitInterface(root_dir, logger)
Expand Down Expand Up @@ -409,19 +424,7 @@ def submodules_update(gitmodules, root_dir, requiredlist, force):
upstream = git.git_operation("ls-remote", "--get-url").rstrip()
newremote = "origin"
if upstream != url:
# TODO - this needs to be a unique name
remotes = git.git_operation("remote", "-v")
if url in remotes:
for line in remotes:
if url in line and "fetch" in line:
newremote = line.split()[0]
break
else:
i = 0
while newremote in remotes:
i = i + 1
newremote = f"newremote.{i:02d}"
git.git_operation("remote", "add", newremote, url)
add_remote(git, url)

tags = git.git_operation("tag", "-l")
if fxtag and fxtag not in tags:
Expand All @@ -439,6 +442,8 @@ def submodules_update(gitmodules, root_dir, requiredlist, force):
print(f"{name:>20} up to date.")




def local_mods_output():
text = """\
The submodules labeled with 'M' above are not in a clean state.
Expand Down
2 changes: 1 addition & 1 deletion git_fleximod/gitmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get(self, name, option, raw=False, vars=None, fallback=None):
Uses the parent class's get method to access the value.
Handles potential errors if the section or option doesn't exist.
"""
self.logger.debug("get called {} {}".format(name, option))
self.logger.debug("git get called {} {}".format(name, option))
section = f'submodule "{name}"'
try:
return ConfigParser.get(
Expand Down

0 comments on commit 00b7b38

Please sign in to comment.