Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/root dir #43

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git_fleximod/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def find_root_dir(filename=".gitmodules"):
attempt = dl / filename
if attempt.is_file():
return str(dl)
utils.fatal_error("No .gitmodules found in directory tree")
return None


def get_parser():
Expand Down
22 changes: 17 additions & 5 deletions git_fleximod/git_fleximod.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,25 @@ def submodules_status(gitmodules, root_dir, toplevel=False):
# submodule commands use path, not name
url = url.replace("[email protected]:", "https://github.com/")
tags = rootgit.git_operation("ls-remote", "--tags", url)
result = rootgit.git_operation("submodule","status",newpath).split()
ahash = None
if result:
ahash = result[0][1:]
hhash = None
atag = None
needsupdate += 1
if not toplevel and level:
continue
for htag in tags.split("\n"):
if tag and tag in htag:
if htag.endswith('^{}'):
htag = htag[:-3]
if ahash and not atag and ahash in htag:
atag = (htag.split()[1])[10:]
if tag and not hhash and htag.endswith(tag):
hhash = htag.split()[0]
if hhash and atag:
break
if tag and tag == atag:
if tag and (ahash == hhash or atag == tag):
print(f"e {name:>20} not checked out, aligned at tag {tag}")
elif tag:
ahash = rootgit.git_operation(
Expand Down Expand Up @@ -565,10 +575,12 @@ def main():

logger.info("action is {} root_dir={} file_name={}".format(action, root_dir, file_name))

if not os.path.isfile(os.path.join(root_dir, file_name)):
file_path = utils.find_upwards(root_dir, file_name)
if not root_dir or not os.path.isfile(os.path.join(root_dir, file_name)):
if root_dir:
file_path = utils.find_upwards(root_dir, file_name)

if file_path is None:
if root_dir is None or file_path is None:
root_dir = "."
utils.fatal_error(
"No {} found in {} or any of it's parents".format(file_name, root_dir)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def logger():
"submodule_name": "test_optional",
"status1" : "test_optional MPIserial_2.5.0-3-gd82ce7c is out of sync with .gitmodules MPIserial_2.4.0",
"status2" : "test_optional at tag MPIserial_2.4.0",
"status3" : "test_optional not checked out, aligned at tag MPIserial_2.4.0",
"status3" : "test_optional not checked out, out of sync at tag None, expected tag is MPIserial_2.4.0",
"status4" : "test_optional at tag MPIserial_2.4.0",
"gitmodules_content": """
[submodule "test_optional"]
Expand All @@ -46,7 +46,7 @@ def logger():
"submodule_name": "test_alwaysoptional",
"status1" : "test_alwaysoptional MPIserial_2.3.0 is out of sync with .gitmodules e5cf35c",
"status2" : "test_alwaysoptional at hash e5cf35c",
"status3" : "test_alwaysoptional not checked out, out of sync at tag MPIserial_2.3.0",
"status3" : "out of sync at tag None, expected tag is e5cf35c",
"status4" : "test_alwaysoptional at hash e5cf35c",
"gitmodules_content": """
[submodule "test_alwaysoptional"]
Expand Down
13 changes: 6 additions & 7 deletions tests/test_d_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_complex_checkout(git_fleximod, complex_repo, logger):
assert("ToplevelOptional not checked out, aligned at tag v5.3.2" in status.stdout)
assert("ToplevelRequired not checked out, aligned at tag MPIserial_2.5.0" in status.stdout)
assert("AlwaysRequired not checked out, aligned at tag MPIserial_2.4.0" in status.stdout)
assert("Complex not checked out, aligned at tag testtag01" in status.stdout)
assert("AlwaysOptional not checked out, aligned at tag MPIserial_2.3.0" in status.stdout)
assert("Complex not checked out, aligned at tag testtag02" in status.stdout)
assert("AlwaysOptional not checked out, out of sync at tag None, expected tag is MPIserial_2.3.0" in status.stdout)

# This should checkout and update test_submodule and complex_sub
result = git_fleximod(complex_repo, "update")
Expand All @@ -18,7 +18,7 @@ def test_complex_checkout(git_fleximod, complex_repo, logger):
assert("ToplevelOptional not checked out, aligned at tag v5.3.2" in status.stdout)
assert("ToplevelRequired at tag MPIserial_2.5.0" in status.stdout)
assert("AlwaysRequired at tag MPIserial_2.4.0" in status.stdout)
assert("Complex at tag testtag01" in status.stdout)
assert("Complex at tag testtag02" in status.stdout)

# now check the complex_sub
root = (complex_repo / "modules" / "complex")
Expand All @@ -39,9 +39,8 @@ def test_complex_checkout(git_fleximod, complex_repo, logger):
assert("ToplevelOptional at tag v5.3.2" in status.stdout)
assert("ToplevelRequired at tag MPIserial_2.5.0" in status.stdout)
assert("AlwaysRequired at tag MPIserial_2.4.0" in status.stdout)
assert("Complex at tag testtag01" in status.stdout)
assert("AlwaysOptional not checked out, aligned at tag MPIserial_2.3.0" in status.stdout)

assert("Complex at tag testtag02" in status.stdout)
assert("AlwaysOptional not checked out, out of sync at tag None, expected tag is MPIserial_2.3.0" in status.stdout)

# Finally update optional
result = git_fleximod(complex_repo, "update --optional")
Expand All @@ -51,7 +50,7 @@ def test_complex_checkout(git_fleximod, complex_repo, logger):
assert("ToplevelOptional at tag v5.3.2" in status.stdout)
assert("ToplevelRequired at tag MPIserial_2.5.0" in status.stdout)
assert("AlwaysRequired at tag MPIserial_2.4.0" in status.stdout)
assert("Complex at tag testtag01" in status.stdout)
assert("Complex at tag testtag02" in status.stdout)
assert("AlwaysOptional at tag MPIserial_2.3.0" in status.stdout)

# now check the complex_sub
Expand Down