hasUncommittedChanges static method

bool hasUncommittedChanges(
  1. String? root
)

Checks if the current repository has uncommitted changes Throws GitException if Git is not available or if there's an error.

Implementation

static bool hasUncommittedChanges(String? root) {
  try {
    // Check if we're in a Git repository
    final result = Process.runSync('git', ['status', '--porcelain'], workingDirectory: root);

    if (result.exitCode != 0) {
      throw const GitException('Not a Git repository or Git command failed');
    }

    // If there's any output, there are uncommitted changes
    return result.stdout.toString().trim().isNotEmpty;
  } on ProcessException catch (e) {
    throw GitException('Git command not found: ${e.message}');
  } catch (e) {
    throw GitException('Unexpected error: $e');
  }
}