Skip to content

Commit

Permalink
tool: add diff program
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemolland committed Jun 6, 2023
1 parent 9eace40 commit 429e272
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tool/git_diff.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ignore_for_file: avoid_print

import 'dart:io';

import 'package:args/args.dart';

void main(List<String> args) async {
// Parse args
final parser = ArgParser();

parser.addOption(
'dir',
abbr: 'd',
help: 'Directory to search for files with git diffs',
);

parser.addOption(
'file',
abbr: 'f',
help: 'File to check for git diff',
);

final results = parser.parse(args);

final dir = results['dir'] as String?;
final file = results['file'] as String?;

if (dir == null && file == null) {
print('Please provide a directory or file to check for git diff');
exit(1);
}

if (dir != null && file != null) {
print('Please provide only a directory or file to check for git diff');
exit(1);
}

if (dir != null) {
var result = await Process.run(
'git',
['diff', '--name-only', '--relative', dir],
);

if (result.stdout.toString().isEmpty) {
print('No diff found in $dir');
} else {
print('Diff found in $dir');
print(result.stdout);
exit(1);
}
}

if (file != null) {
var result = await Process.run(
'git',
['diff', '--name-only', file],
);

if (result.stdout.toString().isEmpty) {
print('No diff found in $file');
} else {
print('Diff found in $file');
print(result.stdout);
exit(1);
}
}
}

0 comments on commit 429e272

Please sign in to comment.