public static void checkFetchSuccessful()

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


  public static void checkFetchSuccessful(@NotNull Repository db, @NotNull FetchResult result, @NotNull Set<String> refNamesLocal) throws VcsException {
    TreeSet<String> conflictsWithoutDb = new TreeSet<>();
    for (TrackingRefUpdate update : result.getTrackingRefUpdates()) {
      String localRefName = update.getLocalName();
      RefUpdate.Result status = update.getResult();
      if (status == RefUpdate.Result.REJECTED || status == RefUpdate.Result.LOCK_FAILURE || status == RefUpdate.Result.IO_FAILURE) {
        if (status == RefUpdate.Result.LOCK_FAILURE) {
          TreeSet<String> caseSensitiveConflicts = new TreeSet<>();
          TreeSet<String> conflicts = new TreeSet<>();
          try {
            if (SystemInfo.isWindows || SystemInfo.isMac) {
              // here we need to check ref names before the fetch, otherwise they can be corrupted after an unsuccessful fetch (bug in jgit)
              for (String ref : refNamesLocal) {
                if (!localRefName.equals(ref) && localRefName.equalsIgnoreCase(ref))
                  caseSensitiveConflicts.add(ref);
              }
            }
            conflicts.addAll(db.getRefDatabase().getConflictingNames(localRefName));
          } catch (Exception e) {
            //ignore
          }
          String msg;
          if (!conflicts.isEmpty()) {
            msg = "Failed to fetch ref " + localRefName + ": it clashes with " + StringUtil.join(", ", conflicts) +
                  ". Please remove conflicting refs from repository.";
          } else if (!caseSensitiveConflicts.isEmpty()) {
            msg = "Failed to fetch ref " + localRefName + ": on case-insensitive file system it clashes with " +
                  StringUtil.join(", ", caseSensitiveConflicts) +
                  ". Please remove conflicting refs from repository.";
          } else {
            //msg = "Fail to update '" + localRefName + "' (" + status.name() + ")";
            conflictsWithoutDb.add(localRefName);
            continue;
          }
          throw new VcsException(msg);
        } else {
          throw new VcsException("Failed to update '" + localRefName + "' (" + status.name() + ")");
        }
      }
    }
    if (!conflictsWithoutDb.isEmpty()) {
      throw new VcsException("Failed to update '" + StringUtil.join(", ", conflictsWithoutDb) + "' (" + RefUpdate.Result.LOCK_FAILURE.name() + ")");
    }
  }