updateBranch method

Future<Commit?> updateBranch(
  1. String branchName,
  2. Future<void> populater(
    1. Directory td
    ),
  3. String commitMessage
)

Updates the named branch with the content add by calling populater.

populater is called with a temporary Directory instance that should be populated with the desired content.

If the content provided matches the content in the specificed branchName, then no Commit is created and null is returned.

If no content is added to the directory, an error is thrown.

Implementation

Future<Commit?> updateBranch(
  String branchName,
  Future<void> Function(Directory td) populater,
  String commitMessage,
) async {
  // TODO: ponder restricting branch names
  // see http://stackoverflow.com/questions/12093748/how-do-i-check-for-valid-git-branch-names/12093994#12093994

  requireArgumentNotNullOrEmpty(branchName, 'branchName');
  requireArgumentNotNullOrEmpty(commitMessage, 'commitMessage');

  final tempContentRoot = await _createTempDir();

  try {
    await populater(tempContentRoot);
    final commit = await updateBranchWithDirectoryContents(
      branchName,
      tempContentRoot.path,
      commitMessage,
    );
    return commit;
  } finally {
    await tempContentRoot.delete(recursive: true);
  }
}