Skip to content

Commit

Permalink
update find_root_dir to work with git worktree
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed May 31, 2024
1 parent 9412129 commit 4aa073c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
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 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 4aa073c

Please sign in to comment.