Skip to content

Commit

Permalink
Squashed '.lib/git-fleximod/' changes from a354b05..a34070b
Browse files Browse the repository at this point in the history
a34070b Bump to 0.7.6
9e5d5f7 Merge pull request #40 from ESMCI/fix/change_url
00b7b38 some fixes when modifying url

git-subtree-dir: .lib/git-fleximod
git-subtree-split: a34070b
  • Loading branch information
ekluzek committed Jun 3, 2024
1 parent eb94e4d commit afbdcbf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion git_fleximod/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
maintainers = ["Jim Edwards <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion tbump.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit afbdcbf

Please sign in to comment.