serialize method

String serialize()

Implementation

String serialize() {
  // Remotes
  var remoteSection = section('remote');
  var serializedRemotes = <String>{};
  for (var remote in remotes) {
    var rs = remoteSection.getOrCreateSection(remote.name);
    rs.options['url'] = remote.url;
    rs.options['fetch'] = remote.fetch;

    serializedRemotes.add(remote.name);
  }
  remoteSection.keepSections(serializedRemotes);

  // Branches
  var branchSection = section('branch');
  var serializedBranches = <String>{};
  for (var branch in branches.values) {
    var bs = branchSection.getOrCreateSection(branch.name);
    if (branch.remote != null) {
      bs.options['remote'] = branch.remote!;
    }
    if (branch.merge != null) {
      bs.options['merge'] = branch.merge.toString();
      assert(branch.merge!.isBranch());
    }

    if (serializedRemotes.contains(branch.remote)) {
      serializedBranches.add(branch.name);
    }
  }
  branchSection.keepSections(serializedBranches);

  // Core
  if (bare != null) {
    var coreSection = section('core');
    coreSection.options['bare'] = bare.toString();
  }

  // User
  if (user != null) {
    var sec = section('user');
    sec.options['name'] = user!.name;
    sec.options['email'] = user!.email;
  }

  return configFile.serialize();
}