get method

  1. @override
Future<String> get({
  1. required GgLog ggLog,
  2. required Directory directory,
  3. int offset = 0,
  4. bool throwIfNotEverythingIsCommitted = true,
})

Returns the commit message of the head revision in the given directory.

Implementation

@override
Future<String> get({
  required GgLog ggLog,
  required Directory directory,
  int offset = 0,
  bool throwIfNotEverythingIsCommitted = true,
}) async {
  HeadHash.checkOffset(offset);

  await check(directory: directory);

  final isCommited = await _isCommitted.get(
    directory: directory,
    ggLog: ggLog,
  );

  if (!isCommited && throwIfNotEverythingIsCommitted) {
    throw Exception('Not everything is committed.');
  }

  // To get the commit message, the command is adjusted to use `git log`
  final offsetString = offset == 0 ? '' : '~$offset';
  final result = await processWrapper.run('git', [
    'log',
    '-1',
    '--pretty=format:%B',
    'HEAD$offsetString',
  ], workingDirectory: directory.path);

  if (result.exitCode == 0) {
    return result.stdout.toString().trim();
  } else {
    throw Exception('Could not read the head message: ${result.stderr}');
  }
}