discoverRepo

Discover a git repository and return its path if found.

The lookup starts from startPath and continues searching across parent directories. The lookup stops when one of the following becomes true:

  • a git repository is found.
  • a directory referenced in ceilingDirs has been reached.
  • the filesystem changed (if acrossFS is equal to AcrossFS.no.)
  • string
    discoverRepo
    (
    in char[] startPath
    ,
    string[] ceilingDirs = null
    ,)

    Examples

    /**
        look for the .git repo in "../test/repo/a/".
        The .git directory will be found one dir up, and will
        contain the line 'gitdir: ../../.git/modules/test/repo'.
        The function will expand this line and return the true
        repository location.
    */
    string path = buildPath(_testRepo.dirName, "a");
    string repoPath = discoverRepo(path);
    assert(repoPath.relativePath.toPosixPath == "../.git/modules/test/repo");
    
    // verify the repo can be opened
    auto repo = GitRepo(repoPath);
    // ceiling dir is found before any git repository
    string path = buildPath(_testRepo.dirName, "a");
    string[] ceils = [_testRepo.dirName.absolutePath.buildNormalizedPath];
    assertThrown!GitException(discoverRepo(path, ceils));
    // all ceiling paths must be absolute
    string[] ceils = ["../.."];
    assertThrown!AssertError(discoverRepo(_testRepo.dirName, ceils));

    Meta