Skip to content

Commit

Permalink
Merge pull request ESCOMP#37 from ESMCI/fix/git_workflow
Browse files Browse the repository at this point in the history
update find_root_dir to work with git worktree
  • Loading branch information
jedwards4b authored May 31, 2024
2 parents 9412129 + 1fddaac commit 71273de
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion License
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions git_fleximod/cli.py
Original file line number Diff line number Diff line change
@@ -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 str(dl)
utils.fatal_error("No .gitmodules found in directory tree")


def get_parser():
Expand Down
10 changes: 7 additions & 3 deletions git_fleximod/git_fleximod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 71273de

Please sign in to comment.