private static bool MoveDirectoryUpUntilRepositoryRoot(FilesystemDirectory directory) { while (true) { if (directory.FileExists(stateFilePath)) { return(true); } if (!directory.MoveOneDirectoryUp()) { return(false); } } }
private LocalRepository(string directoryPath, bool allowNonLinkedDirectory = false) { var directory = new FilesystemDirectory(directoryPath); directoryPath = directory.PhysicalPath; var isLinked = MoveDirectoryUpUntilRepositoryRoot(directory); if (isLinked) { this.FullRepositoryName = directory.ReadTextFile(stateFilePath).SplitInLines()[0]; } else if (allowNonLinkedDirectory) { this.FullRepositoryName = null; directory = new FilesystemDirectory(directoryPath); } else { throw new InvalidOperationException($"{directoryPath} is not linked to any remote repository"); } this.Directory = directory; }
static LocalRepository() { stateFilePath = FilesystemDirectory.CombinePath(databaseDirectory, stateFileName); treeFilePath = FilesystemDirectory.CombinePath(databaseDirectory, treeFileName); }