getRepositoryRoot static method

String getRepositoryRoot(
  1. String? root
)

Gets the repository root directory

Implementation

static String getRepositoryRoot(String? root) {
  try {
    final result = Process.runSync('git', ['rev-parse', '--show-toplevel'], workingDirectory: root);
    if (result.exitCode != 0) {
      throw const GitException('Failed to get repository root');
    }
    return result.stdout.toString().trim();
  } on ProcessException catch (e) {
    throw GitException('Git command not found: ${e.message}');
  } catch (e) {
    throw GitException('Unexpected error: $e');
  }
}