getRemoteUrl static method

Future<String?> getRemoteUrl(
  1. String? root
)

Gets the remote URL of the git repository

Implementation

static Future<String?> getRemoteUrl(String? root) async {
  try {
    final result = await Process.run(
      'git',
      ['config', '--get', 'remote.origin.url'],
      workingDirectory: root,
    );
    if (result.exitCode == 0) {
      var url = result.stdout.toString().trim();
      if (url.startsWith('git@')) {
        url = url.replaceFirst(':', '/').replaceFirst('git@', 'https://');
      }
      if (url.endsWith('.git')) {
        url = url.substring(0, url.length - 4);
      }
      return url;
    }
  } catch (e) {
    logger.detail('Could not get git remote url: $e');
  }
  return null;
}