From c304487aff29425777e08fc5e009320b50282149 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 5 Jun 2024 11:36:26 -0600 Subject: [PATCH 1/4] update complex test --- git_fleximod/cli.py | 2 +- git_fleximod/git_fleximod.py | 8 +++++--- tests/test_d_complex.py | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/git_fleximod/cli.py b/git_fleximod/cli.py index 7d09abd83b..d4498b84f9 100644 --- a/git_fleximod/cli.py +++ b/git_fleximod/cli.py @@ -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(): diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index a003c0da8c..48a9b69f65 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -565,10 +565,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) ) diff --git a/tests/test_d_complex.py b/tests/test_d_complex.py index fdce516274..62889f2cba 100644 --- a/tests/test_d_complex.py +++ b/tests/test_d_complex.py @@ -7,7 +7,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 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("Complex not checked out, aligned at tag testtag02" in status.stdout) assert("AlwaysOptional not checked out, aligned at tag MPIserial_2.3.0" in status.stdout) # This should checkout and update test_submodule and complex_sub @@ -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") @@ -39,7 +39,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 not checked out, aligned at tag MPIserial_2.3.0" in status.stdout) @@ -51,7 +51,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 From d95f5d61ba381fbef6274eae5547e08d09e1a10d Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 5 Jun 2024 14:08:19 -0600 Subject: [PATCH 2/4] fix status issue --- git_fleximod/git_fleximod.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index 48a9b69f65..a847c9fc6b 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -298,15 +298,22 @@ def submodules_status(gitmodules, root_dir, toplevel=False): # submodule commands use path, not name url = url.replace("git@github.com:", "https://github.com/") tags = rootgit.git_operation("ls-remote", "--tags", url) + ahash = rootgit.git_operation("submodule","status",newpath).split()[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 not atag and ahash in htag: atag = (htag.split()[1])[10:] + if 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( From 0593149d3c106509daa1fbb235fe5b747e26c9a5 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 5 Jun 2024 14:17:46 -0600 Subject: [PATCH 3/4] one more improvement --- git_fleximod/git_fleximod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index a847c9fc6b..b0a5a33070 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -309,7 +309,7 @@ def submodules_status(gitmodules, root_dir, toplevel=False): htag = htag[:-3] if not atag and ahash in htag: atag = (htag.split()[1])[10:] - if not hhash and htag.endswith(tag): + if tag and not hhash and htag.endswith(tag): hhash = htag.split()[0] if hhash and atag: break From 3ff935b835d1793e0840f00230e323efc52fba76 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 5 Jun 2024 14:47:54 -0600 Subject: [PATCH 4/4] update tests --- git_fleximod/git_fleximod.py | 7 +++++-- tests/conftest.py | 4 ++-- tests/test_d_complex.py | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index b0a5a33070..ca5f90622d 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -298,7 +298,10 @@ def submodules_status(gitmodules, root_dir, toplevel=False): # submodule commands use path, not name url = url.replace("git@github.com:", "https://github.com/") tags = rootgit.git_operation("ls-remote", "--tags", url) - ahash = rootgit.git_operation("submodule","status",newpath).split()[0][1:] + result = rootgit.git_operation("submodule","status",newpath).split() + ahash = None + if result: + ahash = result[0][1:] hhash = None atag = None needsupdate += 1 @@ -307,7 +310,7 @@ def submodules_status(gitmodules, root_dir, toplevel=False): for htag in tags.split("\n"): if htag.endswith('^{}'): htag = htag[:-3] - if not atag and ahash in htag: + 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] diff --git a/tests/conftest.py b/tests/conftest.py index 942a0efb97..1cc008eb1d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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"] @@ -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"] diff --git a/tests/test_d_complex.py b/tests/test_d_complex.py index 62889f2cba..edde7d816d 100644 --- a/tests/test_d_complex.py +++ b/tests/test_d_complex.py @@ -8,7 +8,7 @@ def test_complex_checkout(git_fleximod, complex_repo, logger): 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 testtag02" in status.stdout) - assert("AlwaysOptional not checked out, aligned at tag MPIserial_2.3.0" 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") @@ -40,8 +40,7 @@ def test_complex_checkout(git_fleximod, complex_repo, logger): 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 testtag02" in status.stdout) - assert("AlwaysOptional not checked out, aligned at tag MPIserial_2.3.0" 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")