resolveRef static method

Future<String> resolveRef(
  1. String ref,
  2. String? root
)

Resolves a git ref to its commit hash Throws GitException if the ref doesn't exist

Implementation

static Future<String> resolveRef(String ref, String? root) async {
  try {
    final result = await Process.run('git', ['rev-parse', ref], workingDirectory: root);
    if (result.exitCode != 0) {
      throw GitException('Failed to resolve ref $ref: ${result.stderr}');
    }
    return result.stdout.toString().trim();
  } on ProcessException catch (e) {
    throw GitException('Git command not found: ${e.message}');
  } catch (e) {
    if (e is GitException) rethrow;
    throw GitException('Unexpected error: $e');
  }
}