isGitIgnored static method
Whether git ignores relative in project: asks git, and reads
.gitignore when git isn't available.
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;
for (final raw in ignore.readAsLinesSync()) {
final line = raw.trim();
if (line == relative || line == '/$relative' || line == '**/$relative') {
return true;
}
}
return false;
}