hasWorktreeChanges method

Future<bool> hasWorktreeChanges(
  1. String worktreePath,
  2. String headCommit
)

Check whether a worktree has uncommitted changes or new commits since creation.

Implementation

Future<bool> hasWorktreeChanges(
  String worktreePath,
  String headCommit,
) async {
  final statusResult = await _execGit([
    'status',
    '--porcelain',
  ], cwd: worktreePath);
  if (statusResult.code != 0) return true;
  if (statusResult.stdout.trim().isNotEmpty) return true;

  final revListResult = await _execGit([
    'rev-list',
    '--count',
    '$headCommit..HEAD',
  ], cwd: worktreePath);
  if (revListResult.code != 0) return true;
  if ((int.tryParse(revListResult.stdout.trim()) ?? 0) > 0) return true;

  return false;
}