From afbdcbfd8517fbe951772c39bcb1f57da2abd24d Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 3 Jun 2024 17:16:08 -0600 Subject: [PATCH] Squashed '.lib/git-fleximod/' changes from a354b0528..a34070be0 a34070be0 Bump to 0.7.6 9e5d5f72b Merge pull request #40 from ESMCI/fix/change_url 00b7b3817 some fixes when modifying url git-subtree-dir: .lib/git-fleximod git-subtree-split: a34070be02d10071b544be3839f6c9ed79662665 --- git_fleximod/cli.py | 2 +- git_fleximod/git_fleximod.py | 49 ++++++++++++++++++++---------------- git_fleximod/gitmodules.py | 2 +- pyproject.toml | 2 +- tbump.toml | 2 +- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/git_fleximod/cli.py b/git_fleximod/cli.py index 4c3fb1a8f9..7d09abd83b 100644 --- a/git_fleximod/cli.py +++ b/git_fleximod/cli.py @@ -2,7 +2,7 @@ import argparse from git_fleximod import utils -__version__ = "0.7.5" +__version__ = "0.7.6" def find_root_dir(filename=".gitmodules"): """ finds the highest directory in tree diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index f080513a52..a003c0da8c 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -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 @@ -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: @@ -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("git@github.com:", "https://github.com/") tags = rootgit.git_operation("ls-remote", "--tags", url) atag = None @@ -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: @@ -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, " ")) @@ -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) @@ -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: @@ -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. diff --git a/git_fleximod/gitmodules.py b/git_fleximod/gitmodules.py index 68c82d066f..7e4e05394a 100644 --- a/git_fleximod/gitmodules.py +++ b/git_fleximod/gitmodules.py @@ -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( diff --git a/pyproject.toml b/pyproject.toml index ac1684ea0f..3c70c6c9c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "git-fleximod" -version = "0.7.5" +version = "0.7.6" description = "Extended support for git-submodule and git-sparse-checkout" authors = ["Jim Edwards "] maintainers = ["Jim Edwards "] diff --git a/tbump.toml b/tbump.toml index e644fc4d24..3854682df4 100644 --- a/tbump.toml +++ b/tbump.toml @@ -2,7 +2,7 @@ github_url = "https://github.com/jedwards4b/git-fleximod/" [version] -current = "0.7.5" +current = "0.7.6" # Example of a semver regexp. # Make sure this matches current_version before