updateBranch method

Future<void> updateBranch({
  1. required String publishDirectory,
  2. String? commitMessage,
})

Update branch with content of publishDirectory.

The publishDirectory must be under the workingDirectory provided in the constructor.

commitMessage is optional and defaults to 'Deploy on DateTime.now'.

Implementation

Future<void> updateBranch({
  required String publishDirectory,
  String? commitMessage,
}) async {
  if (!await GitDir.isGitDir(workingDirectory)) {
    throw NotGitDirectoryException(
      "'$workingDirectory' is not a git directory.",
    );
  }
  gitDir = await GitDir.fromExisting(workingDirectory);

  try {
    await gitDir.updateBranchWithDirectoryContents(
      branch,
      join(workingDirectory, publishDirectory),
      commitMessage ?? '🚀 Deploy on ${DateTime.now().toIso8601String()}',
    );
  } catch (e) {
    throw GithubPagesException(e);
  }
}