Stata package to locate the root of a repository by searching for marker files while walking up parent directories from the current working directory.
By default, assumes a git repository (searches for .git/HEAD). Can be configured
for other version control systems or custom markers.
- Default: git repository detection (searches for
.git/HEAD) - Searches current directory and up to
maxdepthparents (default 3) - Accepts custom single or space-separated markers for other repo types
- Returns absolute path in
r(repo_root); informational message if not found - Tested for Stata 17
net install find_repo_root, from("https://raw.githubusercontent.com/gitlastoni/find_repo_root/main/")Default usage (git repository):
. find_repo_rootCustom markers (for non-git repos or multiple options):
. find_repo_root, maxdepth(5) marker("README.md")
. find_repo_root, marker(".git/HEAD .svn")After running, inspect:
. return listr(repo_root) contains the located root path (or is empty if not found).
maxdepth(#): Levels to search above current dir (default 3; current dir is 0).marker(string): Marker file(s) or directory(ies); space-separated list allowed. Default:.git/HEAD(git repository).
See test/test_find_repo_root.do for automated checks covering basics, custom
markers, multiple markers, different depths, not-found cases, and current-dir
matches.
MIT License (see LICENSE).