public static Repository getRepository()

in git-server/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/GitServerUtil.java [82:112]


  public static Repository getRepository(@NotNull final File dir, @NotNull final URIish remote) throws VcsException {
    if (dir.exists() && !dir.isDirectory()) {
      throw new VcsException("The specified path is not a directory: " + dir);
    }
    try {
      ensureRepositoryIsValid(dir);
      Repository r = getRepositoryWithDisabledAutoGc(dir);
      String remoteUrl = remote.toString();
      if (remoteUrl.contains("\n") || remoteUrl.contains("\r"))
        throw new VcsException("Newline in url '" + remoteUrl + "'");
      if (!new File(dir, "config").exists()) {
        r.create(true);
        addConfigOptions(r.getConfig(), remoteUrl).save();
      } else {
        final StoredConfig config = r.getConfig();
        final String existingRemote = config.getString("teamcity", null, "remote");
        final String refSpec = config.getString("remote", "origin", "fetch");
        final String mirror = config.getString("remote", "origin", "mirror");
        if (existingRemote != null && !remoteUrl.equals(existingRemote)) {
          throw getWrongUrlError(dir, existingRemote, remote);
        } else if (existingRemote == null || refSpec == null || mirror != null) {
          addConfigOptions(config, remoteUrl).save();
        }
      }
      return r;
    } catch (Exception ex) {
      if (ex instanceof NullPointerException)
        LOG.warn("The repository at directory '" + dir + "' cannot be opened or created", ex);
      throw new VcsException("The repository at directory '" + dir + "' cannot be opened or created, reason: " + ex.toString(), ex);
    }
  }