fromPackageRef static method

GitRef? fromPackageRef(
  1. String packageRefString
)

Creates a GitRef from a package reference string Returns null if the string is not a valid git reference

Implementation

static GitRef? fromPackageRef(String packageRefString) {
  if (!packageRefString.startsWith('git://')) {
    return null;
  }

  // Remove the git:// prefix
  final withoutScheme = packageRefString.substring(6);

  // Handle git://https://... format
  if (withoutScheme.startsWith('https://')) {
    return _parseHttpsFormat(withoutScheme);
  }

  // Handle SSH format like git@github.com:user/repo or git@github.com:user/repo:branch
  if (withoutScheme.contains('@')) {
    return _parseSshFormat(withoutScheme);
  }

  // Fallback: treat the whole thing as a URI without ref
  return GitRef._(uri: withoutScheme);
}