commitFile function

Future<void> commitFile(
  1. Directory testDir,
  2. String fileName, {
  3. String message = 'Commit Message',
  4. bool stage = true,
  5. bool ammend = false,
})

Commit the file with a name in the test directory

Implementation

Future<void> commitFile(
  Directory testDir,
  String fileName, {
  String message = 'Commit Message',
  bool stage = true,
  bool ammend = false,
}) async {
  final nothingHasChanged = (await modifiedFiles(testDir)).isEmpty;
  if (nothingHasChanged) {
    return;
  }

  if (stage) {
    await stageFile(testDir, fileName);
  }

  final result2 = await Process.run('git', [
    'commit',
    '-m',
    message,
    if (ammend) '--amend',
  ], workingDirectory: testDir.path);

  _throw('Could not commit $fileName', result2);
}