Пример #1
0
  @SuppressWarnings("resource" /* java 7 */)
  @Test
  public void absoluteGitDirRef() throws Exception {
    Repository repo1 = createWorkRepository();
    File dir = createTempDirectory("dir");
    File dotGit = new File(dir, Constants.DOT_GIT);
    new FileWriter(dotGit).append("gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    builder.setWorkTree(dir);
    builder.setMustExist(true);
    Repository repo2 = builder.build();

    assertEquals(repo1.getDirectory(), repo2.getDirectory());
    assertEquals(dir, repo2.getWorkTree());
  }
Пример #2
0
  // import a git repo in jgit data structures or create a new one
  private Repository createRepo(String repoDir, String gitDir) throws IOException {

    File gd = new File(gitDir);
    File rd = new File(repoDir);
    if (GitWorks.anew) {
      if (rd.exists()) FileUtils.delete(rd, FileUtils.RECURSIVE);
      if (!GitWorks.bare) rd.mkdirs();
      if (gd.exists()) FileUtils.delete(gd, FileUtils.RECURSIVE);
      gd.mkdirs();
    }
    FileRepositoryBuilder frb = new FileRepositoryBuilder();
    if (!GitWorks.bare) frb.setWorkTree(rd);
    Repository repository =
        frb.setGitDir(gd)
            .readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .setMustExist(!GitWorks.anew)
            .build();
    if (GitWorks.anew) repository.create(GitWorks.bare);

    return repository;
  }