Skip to content

Commit

Permalink
update should checkout if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 13, 2024
1 parent d103bc6 commit 8af1618
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
34 changes: 31 additions & 3 deletions git_fleximod/git_fleximod.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def submodules_status(gitmodules, root_dir):
return testfails, localmods


def submodules_update(gitmodules, root_dir, force):
def submodules_update(gitmodules, root_dir, requiredlist, force):
_, localmods = submodules_status(gitmodules, root_dir)
print("")
if localmods and not force:
Expand All @@ -289,6 +289,34 @@ def submodules_update(gitmodules, root_dir, force):
path = gitmodules.get(name, "path")
url = gitmodules.get(name, "url")
logger.info("name={} path={} url={} fxtag={}".format(name, path, url, fxtag))
if not os.path.exists(os.path.join(path, ".git")):
fxrequired = gitmodules.get(name, "fxrequired")
fxsparse = gitmodules.get(name, "fxsparse")

if fxrequired and fxrequired not in requiredlist:
if "T:F" == fxrequired:
print("Skipping optional component {}".format(name))
continue

if fxsparse:
logger.debug(
"Callng submodule_sparse_checkout({}, {}, {}, {}, {}, {}".format(
root_dir, name, url, path, fxsparse, fxtag
)
)
submodule_sparse_checkout(
root_dir, name, url, path, fxsparse, tag=fxtag, fxhash=fxhash
)
else:
logger.debug(
"Calling submodule_checkout({},{},{})".format(root_dir, name, path)
)

single_submodule_checkout(
root_dir, name, path, url=url, tag=fxtag, force=force, fxhash=fxhash
)


if os.path.exists(os.path.join(path, ".git")):
submoddir = os.path.join(root_dir, path)
with utils.pushd(submoddir):
Expand Down Expand Up @@ -326,7 +354,7 @@ def submodules_update(gitmodules, root_dir, force):
else:
print(f"{name:>20} up to date.")


# checkout is done by update if required so this function may be depricated
def submodules_checkout(gitmodules, root_dir, requiredlist, force=False):
_, localmods = submodules_status(gitmodules, root_dir)
print("")
Expand Down Expand Up @@ -424,7 +452,7 @@ def main():
sys.exit("No submodule components found")
retval = 0
if action == "update":
submodules_update(gitmodules, root_dir, force)
submodules_update(gitmodules, root_dir, fxrequired, force)
elif action == "checkout":
submodules_checkout(gitmodules, root_dir, fxrequired, force)
elif action == "status":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_sparse_checkout(git_fleximod, test_repo_base):
"""
(test_repo_base / "modules" / ".sparse_file_list").write_text(sparse_content)

result = git_fleximod("checkout")
result = git_fleximod("update")

# Assertions
assert result.returncode == 0
Expand All @@ -31,8 +31,3 @@ def test_sparse_checkout(git_fleximod, test_repo_base):

assert "test_sparse_submodule at tag MPIserial_2.5.0" in status.stdout

result = git_fleximod("update")
assert result.returncode == 0

status = git_fleximod("status test_sparse_submodule")
assert "test_sparse_submodule at tag MPIserial_2.5.0" in status.stdout
7 changes: 1 addition & 6 deletions tests/test_checkout.py → tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ def test_basic_checkout(git_fleximod, test_repo):
(test_repo / ".gitmodules").write_text(gitmodules_content)

# Run the command
result = git_fleximod("checkout")
result = git_fleximod("update")

# Assertions
assert result.returncode == 0
assert Path(test_repo / "modules/test").exists() # Did the submodule directory get created?

status = git_fleximod("status")

assert "test_submodule d82ce7c is out of sync with .gitmodules MPIserial_2.4.0" in status.stdout

result = git_fleximod("update")
assert result.returncode == 0

status = git_fleximod("status")
assert "test_submodule at tag MPIserial_2.4.0" in status.stdout

0 comments on commit 8af1618

Please sign in to comment.