checkGitignore function

String? checkGitignore(
  1. Directory projectRoot
)

Warns, at startup, if projectRoot's .gitignore doesn't mention .ref โ€” these are throwaway dev-tool scratch files, not something meant to land in commits (PLAN.md ยง5.3). Returns null if all's well.

Implementation

String? checkGitignore(Directory projectRoot) {
  final File gitignore = File('${projectRoot.path}/.gitignore');
  if (!gitignore.existsSync()) {
    return 'No .gitignore found in ${projectRoot.path} โ€” add ".ref/" to it so selections don\'t get committed.';
  }
  final bool mentioned = gitignore
      .readAsStringSync()
      .split('\n')
      .map((String line) => line.trim())
      .any((String line) => line == '.ref' || line == '.ref/' || line == '/.ref' || line == '/.ref/');
  if (!mentioned) {
    return '.gitignore doesn\'t mention .ref/ โ€” add it so selections don\'t get committed.';
  }
  return null;
}