GitLocalRepository.open constructor

GitLocalRepository.open(
  1. String folder
)

Opens the repository folder names: a folder holding .git (a folder, or a file reading gitdir: <path>), a bare repository, or a .git folder itself. Throws GitNotARepositoryException for anything else.

Implementation

factory GitLocalRepository.open(String folder) {
  final dotGit = p.join(folder, '.git');
  String gitDir;
  bool bare;
  if (Directory(dotGit).existsSync()) {
    gitDir = dotGit;
    bare = false;
  } else if (File(dotGit).existsSync()) {
    gitDir = _gitDirFromFile(File(dotGit), folder);
    bare = false;
  } else if (_isGitDir(folder)) {
    gitDir = folder;
    bare = _configSaysBare(folder);
  } else {
    throw GitNotARepositoryException(folder);
  }
  final commonDir = _commonDirOf(gitDir);
  if (!File(p.join(gitDir, 'HEAD')).existsSync() || !_isGitDir(commonDir)) {
    throw GitNotARepositoryException(folder);
  }
  return GitLocalRepository._(
    folder: folder,
    gitDir: gitDir,
    commonDir: commonDir,
    isBare: bare,
    repository: gitOpenDirectory(commonDir),
  );
}