public static LocalReason classify()

in git-common/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/GitRemoteUrlInspector.java [37:92]


  public static LocalReason classify(@Nullable String rawUrl) {
    if (rawUrl == null) return null;
    String url = rawUrl.trim();
    if (url.isEmpty()) return null;

    String lower = url.toLowerCase();

    // 1) file: scheme (file://, file:/, file:///C:/...)
    if (lower.startsWith("file:")) {
      return LocalReason.FILE_SCHEME;
    }

    // 2) Windows UNC path \\server\share\...
    if (url.startsWith("\\\\")) {
      return LocalReason.WINDOWS_UNC;
    }

    // 3) Windows drive path: C:\path or C:/path or even C:relative
    // Make sure we don't confuse scp-like syntax (user@host:path)
    if (looksLikeWindowsDrive(url)) {
      return LocalReason.WINDOWS_DRIVE;
    }

    // 4) Unix absolute path: /path/to/repo
    if (url.startsWith("/")) {
      return LocalReason.UNIX_ABSOLUTE;
    }

    // 5) Unix relative path: ./repo, ../repo, ~/repo
    if (url.startsWith("./") || url.startsWith("../") || url.startsWith("~/") || url.startsWith(".\\") || url.startsWith("..\\") || url.startsWith("~\\")) {
      return LocalReason.UNIX_RELATIVE;
    }

    // 6) If it contains a scheme (://), treat as network URL
    int schemeIdx = url.indexOf("://");
    if (schemeIdx >= 0) {
      return null;
    }

    // 7) scp-like syntax user@host:path should not be considered local
    // Quick check: presence of '@' before a ':' suggests scp-like form
    int atIdx = url.indexOf('@');
    int colonIdx = url.indexOf(':');
    if (atIdx >= 0 && colonIdx > atIdx) {
      return null; // likely scp syntax
    }

    // 8) Bare relative like "repo.git" or "path/to/repo" (without scheme/host) is generally local path
    // Avoid marking single word without path separators as local as it could be a host alias in some setups,
    // but Git would treat plain words as local paths too. We conservatively require a path separator to decide.
    if (url.contains("/") || url.contains("\\")) {
      return LocalReason.UNIX_RELATIVE;
    }

    return null;
  }