Skip to content

Commit

Permalink
Fixe issue with nested repositories (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWatkins committed Feb 24, 2023
1 parent c220743 commit be5cac4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion gitman/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from . import common
from .decorators import preserve_cwd
from .models import Config, Source, find_nested_configs, load_config
from .models.config import filter_nested_configs


def init(*, force: bool = False):
Expand Down Expand Up @@ -89,7 +90,11 @@ def install(

config = load_config(root)
configs = [config] if config else []
configs.extend(find_nested_configs(root, depth, []))
nested_configs = find_nested_configs(root, depth, [])
if config is not None:
nested_configs = filter_nested_configs(config, nested_configs)
configs.extend(nested_configs)

if configs:
count = 0
common.newline()
Expand Down
17 changes: 16 additions & 1 deletion gitman/models/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from pathlib import Path
from typing import Iterator, List, Optional

import log
Expand Down Expand Up @@ -430,7 +431,7 @@ def find_nested_configs(
if name.startswith("."):
continue
path = os.path.join(root, name)
if os.path.isdir(path) and path not in skip_paths:
if os.path.isdir(path) and path not in skip_paths and not os.path.islink(path):
config = load_config(path, search=False)
if config:
configs.append(config)
Expand Down Expand Up @@ -461,3 +462,17 @@ def _valid_filename(filename):
if name.startswith("."):
name = name[1:]
return name in {"gitman", "gdm"} and ext in {".yml", ".yaml"}


def filter_nested_configs(
top_level_config: Config, nested_configs: List[Config]
) -> List[Config]:
"""Filter subdirectories inside of parent config."""
configs = []
config_location_path = Path(top_level_config.location_path)
for nested_config in nested_configs:
nested_config_root = Path(nested_config.location_path)
if config_location_path in nested_config_root.parents:
configs.append(nested_config)

return configs

0 comments on commit be5cac4

Please sign in to comment.