initialize method

  1. @override
List<UndoableCommand> initialize()
override

Implementation

@override
List<UndoableCommand> initialize() {
  Repository localRepository = Repository(Directory.current.path);
  State state = localRepository.state;

  Branch? currentBranch = branchName == null ? state.getCurrentBranch() : Branch(branchName!, localRepository);
  if (currentBranch == null) {
    return [ShowErrorCommand("Provide a branch name")];
  }

  RemoteMetaData? remoteMetaData = localRepository.remoteMetaData;
  if (remoteMetaData == null) {
    return [ShowErrorCommand("No remotes")];
  }

  RemoteData? remoteData = remoteMetaData.remotes[remoteName];
  if (remoteData == null) {
    return [ShowErrorCommand("Remote $remoteName not found")];
  }

  Repository remoteRepository = Repository(remoteData.url);
  RemoteBranch remoteBranch = RemoteBranch(
    Branch(
      currentBranch.branchName,
      remoteRepository,
    ),
    Remote(
      remoteRepository,
      remoteData.name,
      remoteData.url,
    ),
  );

  return [
    PullBranchCommitCommand(localRepository, remoteBranch),
  ];
}