NGit.Repository GetRepository (FilePath localPath) { var submodules = new NGit.Api.Git (RootRepository).SubmoduleStatus ().Call (); var submodule = submodules.Where (s => { var fullPath = ((FilePath) s.Key).ToAbsolute (RootPath); return localPath.IsChildPathOf (fullPath) || localPath.CanonicalPath == fullPath.CanonicalPath; }).Select (s => s.Key).FirstOrDefault (); return submodule == null ? RootRepository : NGit.Submodule.SubmoduleWalk.GetSubmoduleRepository (RootRepository, submodule); }