isGitIgnored static method

Future<bool> isGitIgnored(
  1. JustProject project,
  2. String relative
)

Whether git ignores relative in project: asks git, and — where git isn't installed, or the project isn't in a repository — reads the project's .gitignore as git would (ignoredBy).

Implementation

static Future<bool> isGitIgnored(JustProject project, String relative) async {
  try {
    final result = await Process.run('git', [
      'check-ignore',
      '-q',
      relative,
    ], workingDirectory: project.root);
    if (result.exitCode == 0) return true;
    if (result.exitCode == 1) return false;
  } on ProcessException {
    // No git: read the ignore file.
  }
  final ignore = project.file('.gitignore');
  if (!ignore.existsSync()) return false;
  try {
    return ignoredBy(ignore.readAsStringSync(), relative);
  } on FileSystemException {
    return false;
  }
}