checkRemoteLocation function

void checkRemoteLocation(
  1. String location, {
  2. required List<String> schemes,
})

Refuses location unless it is a remote location the engine accepts.

schemes are the URI schemes the calling engine accepts, spelled in lower case exactly as git recognizes them. The other accepted forms carry no scheme: a path of the local disk (/srv/repo.git, ../repo, C:\repo, C:repo), including a Windows UNC share, and the scp-like user@host:path spelling.

Everything else raises GitUnsupportedUrlException without running git: an empty value, a value spelled like an option (a leading -), a remote helper invocation (<transport>::, including ext:: and fd::), and a scheme-shaped URL whose scheme is not one of schemes.

A Windows drive prefix wins over the scheme reading, so C://repo is a local path rather than a URL served over a scheme named C.

Implementation

void checkRemoteLocation(String location, {required List<String> schemes}) {
  if (location.isEmpty) {
    throw GitUnsupportedUrlException(location, reason: 'it is empty');
  }
  if (location.startsWith('-')) {
    throw GitUnsupportedUrlException(
      location,
      reason: 'it is spelled like an option',
    );
  }
  final RegExpMatch? helper = _remoteHelperPattern.firstMatch(location);
  if (helper != null) {
    throw GitUnsupportedUrlException(
      location,
      reason: 'the remote helper "${helper.group(1)}::" is not supported',
    );
  }
  if (_isDrivePath(location)) {
    return;
  }
  final RegExpMatch? scheme = _schemePattern.firstMatch(location);
  if (scheme == null) {
    return;
  }
  final String name = scheme.group(1)!;
  if (!schemes.contains(name)) {
    throw GitUnsupportedUrlException(
      location,
      reason: '"$name" is not one of the supported schemes: '
          '${schemes.join(", ")}',
    );
  }
}