diff --git a/git_fleximod/cli.py b/git_fleximod/cli.py index 1fb959d..3eb9087 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 103cc82..f080513 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)