From 4aa073c3482ad30b6952834ccc5eb99778f88c09 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 31 May 2024 09:56:18 -0600 Subject: [PATCH 1/2] update find_root_dir to work with git worktree --- git_fleximod/cli.py | 24 +++++++++++++++++------- git_fleximod/git_fleximod.py | 10 +++++++--- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/git_fleximod/cli.py b/git_fleximod/cli.py index 1fb959da..3eb90870 100644 --- a/git_fleximod/cli.py +++ b/git_fleximod/cli.py @@ -1,17 +1,27 @@ from pathlib import Path import argparse +from git_fleximod import utils __version__ = "0.7.4" -def find_root_dir(filename=".git"): +def find_root_dir(filename=".gitmodules"): + """ finds the highest directory in tree + which contains a file called filename """ d = Path.cwd() root = Path(d.root) - while d != root: - attempt = d / filename - if attempt.is_dir(): - return attempt - d = d.parent - return None + dirlist = [] + dl = d + while dl != root: + dirlist.append(dl) + dl = dl.parent + dirlist.append(root) + dirlist.reverse() + + for dl in dirlist: + attempt = dl / filename + if attempt.is_file(): + return dl + utils.fatal_error("No .gitmodules found in directory tree") def get_parser(): diff --git a/git_fleximod/git_fleximod.py b/git_fleximod/git_fleximod.py index 103cc82a..f080513a 100755 --- a/git_fleximod/git_fleximod.py +++ b/git_fleximod/git_fleximod.py @@ -312,7 +312,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() - ahash = git.git_operation("status").partition("\n")[0].split()[-1] + part = git.git_operation("status").partition("\n")[0] + # fake hash to initialize + ahash = "xxxx" + if part: + ahash = part.split()[-1] if tag and atag == tag: print(f" {name:>20} at tag {tag}") elif tag and ahash[: len(tag)] == tag: @@ -554,8 +558,8 @@ def main(): global logger logger = logging.getLogger(__name__) - logger.info("action is {}".format(action)) - + 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) From 1fddaac99d83852380738c44ca33f615898123ca Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 31 May 2024 10:09:31 -0600 Subject: [PATCH 2/2] return str not Path --- License | 2 +- README.md | 2 -- git_fleximod/cli.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/License b/License index 2c6fe768..88bc2251 100644 --- a/License +++ b/License @@ -1,4 +1,4 @@ -Copyright 2024 National Center for Atmospheric Sciences (NCAR) +Copyright 2024 NSF National Center for Atmospheric Sciences (NCAR) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index d1ef632f..53917da4 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ Git-fleximod is a Python-based tool that extends Git's submodule and sparse chec ## Installation -#TODO Install using pip: -# pip install git-fleximod If you choose to locate git-fleximod in your path you can access it via command: git fleximod ## Usage diff --git a/git_fleximod/cli.py b/git_fleximod/cli.py index 3eb90870..d24d07c5 100644 --- a/git_fleximod/cli.py +++ b/git_fleximod/cli.py @@ -20,7 +20,7 @@ def find_root_dir(filename=".gitmodules"): for dl in dirlist: attempt = dl / filename if attempt.is_file(): - return dl + return str(dl) utils.fatal_error("No .gitmodules found in directory tree")