示例#1
0
  @Override
  protected void run() throws Exception {
    if (localName != null && gitdir != null)
      throw die("conflicting usage of --git-dir and arguments");

    final URIish uri = new URIish(sourceUri);
    if (localName == null) {
      String p = uri.getPath();
      while (p.endsWith("/")) p = p.substring(0, p.length() - 1);
      final int s = p.lastIndexOf('/');
      if (s < 0) throw die("cannot guess local name from " + sourceUri);
      localName = p.substring(s + 1);
      if (localName.endsWith(".git")) localName = localName.substring(0, localName.length() - 4);
    }
    if (gitdir == null) gitdir = new File(localName, ".git");

    db = new Repository(gitdir);
    db.create();
    db.getConfig().setBoolean("core", null, "bare", false);
    db.getConfig().save();

    out.println("Initialized empty Git repository in " + gitdir.getAbsolutePath());
    out.flush();

    saveRemote(uri);
    final FetchResult r = runFetch();
    final Ref branch = guessHEAD(r);
    doCheckout(branch);
  }