Skip to content

feat: Support subdirectories in generate and validator#59

Merged
anhnh2002 merged 1 commit into
FSoft-AI4Code:mainfrom
p0thi:feature/subdirectory-incremental-updates
May 23, 2026
Merged

feat: Support subdirectories in generate and validator#59
anhnh2002 merged 1 commit into
FSoft-AI4Code:mainfrom
p0thi:feature/subdirectory-incremental-updates

Conversation

@p0thi
Copy link
Copy Markdown
Contributor

@p0thi p0thi commented May 21, 2026

TL;DR

This PR adds full support for running CodeWiki and performing incremental updates inside subdirectories of Git monorepos.

Description

Previously, CodeWiki assumed the .git directory was located directly at the project root (repo_path), which caused issues and errors when attempting to run analysis and generation inside monorepo subdirectories.
This pull request updates the CLI and utility methods to search parent directories for a Git repository, correctly align git-diff paths under sub-folders, and filter changes accordingly.

Key Changes:

  • Git Root Traversal (repo_validator.py):
    • Introduced a unified private helper _get_git_repo that uses git.Repo(repo_path, search_parent_directories=True).
    • Updated is_git_repository, get_git_commit_hash, and get_git_branch to leverage this helper. This allows CodeWiki to recognize when it is running inside a Git repository subdirectory.
  • Subdirectory Path Alignment & Filtering (generate.py):
    • Updated _detect_changed_files to calculate the relative subdirectory prefix (e.g., apps/my-app) relative to the git repository root.
    • Filtered the file paths returned by git diff to include only those within the active subdirectory.
    • Stripped the subdirectory prefix from these paths so they align perfectly with component paths in module_tree.json for proper incremental generation.
  • Error Handling & Detached HEAD Safety:
    • Added robust try-except wrapping around git helpers to prevent unexpected crashes (e.g., when running in detached HEAD states inside CI/CD environments).
    • Handles fallback gracefully, defaulting to full generation if the repository is bare, outside the git root, or if any exceptions are raised.
      With these changes, developers can now seamlessly use CodeWiki on targeted microservices, modules, or application sub-folders within monorepos.

@anhnh2002
Copy link
Copy Markdown
Collaborator

anhnh2002 commented May 23, 2026

Thanks @p0thi, clean, well-scoped fix. Merging.

@anhnh2002 anhnh2002 merged commit 69b2610 into FSoft-AI4Code:main May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants