Skip to content

fix: repository detection from subdirectories#129

Open
BlackPool25 wants to merge 2 commits into
HexmosTech:mainfrom
BlackPool25:main
Open

fix: repository detection from subdirectories#129
BlackPool25 wants to merge 2 commits into
HexmosTech:mainfrom
BlackPool25:main

Conversation

@BlackPool25

Copy link
Copy Markdown

Summary

Fixes brittle repository detection when running lrc hooks install --local and lrc hooks uninstall --local from nested subdirectories of a Git repository.

  • Renamed and updated check: Renamed IsGitRepositoryCurrentDirIsGitRepository in gitops/config.go. Replaced os.Stat(".git") (only works at repo root) with git rev-parse --is-inside-work-tree (traverses parent dirs correctly).
  • Updated callsite: Updated isGitRepository() in internal/appcore/hooks_management.go to call the renamed function.
  • E2E coverage: Added subdirectory integration tests to tests/worktree-hooks.sh.

Root Cause

IsGitRepositoryCurrentDir() used os.Stat(".git") which resolves relative to the current working directory. When invoked from a subdirectory, the .git entry is not found even though CWD is inside a valid Git worktree.

Changes Made

  1. gitops/config.go — Replace function body, rename, remove unused "os" import
  2. internal/appcore/hooks_management.go — Update delegate call
  3. tests/worktree-hooks.sh — Add "Local Hook Management In Subdirectories" test section

Testing

  • make test-go — All Go packages pass
  • make test-hooks-worktree — All 32 tests pass (including 10 new subdirectory tests)

Checklist

  • This PR fulfills an agreed issue.
  • I kept the change narrow and scoped.
  • I ran the most specific relevant validation and described it above.
  • If I changed behavior, I called that out clearly in this PR.
  • If I touched UI, I attached a GIF or video walkthrough. This is required. (No UI changes)
  • If I changed storage/ responsibilities, I updated storage/storage_status.md and ran make check-status-doc. (No storage changes)
  • If I changed network/ responsibilities, I updated network/network_status.md and ran make check-status-doc. (No network changes)
  • If this change touches security, disclosure flow, credentials, storage, network behavior, or remote data handling, I reviewed SECURITY.md and updated related documentation if needed. (No security-sensitive changes)

Linked Issue

Fixes #128

Notes For Reviewers

The new E2E tests in tests/worktree-hooks.sh under "Local Hook Management In Subdirectories" verify install, status, and uninstall from a nested subdirectory.

Replace os.Stat('.git') with git rev-parse --is-inside-work-tree so
lrc hooks install/uninstall --local works from any subdirectory.
Rename IsGitRepositoryCurrentDir to IsGitRepository to match function
purpose. Add E2E subdirectory tests.
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.

[Bug]: Repository detection fails in nested subdirectories

1 participant