init static method

Future<void> init(
  1. String path, {
  2. FileSystem? fs,
})

Implementation

static Future<void> init(String path, {FileSystem? fs}) async {
  fs ??= const LocalFileSystem();

  // FIXME: Check if path has stuff and accordingly return

  var gitDir = p.join(path, '.git');
  var dirsToCreate = [
    'branches',
    'objects/pack',
    'refs/heads',
    'refs/tags',
  ];
  for (var dir in dirsToCreate) {
    await fs.directory(p.join(gitDir, dir)).create(recursive: true);
  }

  await fs.file(p.join(gitDir, 'description')).writeAsString(
      "Unnamed repository; edit this file 'description' to name the repository.\n");
  await fs
      .file(p.join(gitDir, 'HEAD'))
      .writeAsString('ref: refs/heads/master\n');

  var config = Config('');
  var core = config.section('core');
  core.options['repositoryformatversion'] = '0';
  core.options['filemode'] = 'false';
  core.options['bare'] = 'false';

  await fs.file(p.join(gitDir, 'config')).writeAsString(config.serialize());
}