Java Code Examples for org.eclipse.jgit.storage.file.FileRepositoryBuilder#getGitDir()

The following examples show how to use org.eclipse.jgit.storage.file.FileRepositoryBuilder#getGitDir() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DifferentFiles.java    From gitflow-incremental-builder with MIT License 6 votes vote down vote up
private Git setupGit(Configuration configuration) throws IOException {
    final FileRepositoryBuilder builder = new FileRepositoryBuilder();
    File pomDir = mavenSession.getCurrentProject().getBasedir().toPath().toFile();
    builder.findGitDir(pomDir);
    if (builder.getGitDir() == null) {
        String gitDirNotFoundMessage = "Git repository root directory not found ascending from current working directory:'" + pomDir + "'.";
        logger.warn(gitDirNotFoundMessage + " Next step is determined by failOnMissingGitDir property.");
        if (configuration.failOnMissingGitDir) {
            throw new IllegalArgumentException(gitDirNotFoundMessage);
        } else {
            throw new SkipExecutionException(gitDirNotFoundMessage);
        }
    }
    if (isWorktree(builder)) {
        throw new SkipExecutionException(UNSUPPORTED_WORKTREE + builder.getGitDir());
    }
    return Git.wrap(builder.build());
}
 
Example 2
Source File: GitRepo.java    From git-changelog-lib with Apache License 2.0 6 votes vote down vote up
public GitRepo(final File repo) throws GitChangelogRepositoryException {
  try {
    File repoFile = new File(repo.getAbsolutePath());
    final File gitRepoFile = new File(repo.getAbsolutePath() + "/.git");
    if (gitRepoFile.exists()) {
      repoFile = gitRepoFile;
    }
    final FileRepositoryBuilder builder =
        new FileRepositoryBuilder() //
            .findGitDir(repoFile) //
            .readEnvironment();
    if (builder.getGitDir() == null) {
      throw new GitChangelogRepositoryException(
          "Did not find a GIT repo in " + repo.getAbsolutePath());
    }
    this.repository = builder.build();
    this.revWalk = new RevWalk(this.repository);
    this.git = new Git(this.repository);
  } catch (final IOException e) {
    throw new GitChangelogRepositoryException(
        "Could not use GIT repo in " + repo.getAbsolutePath(), e);
  }
}
 
Example 3
Source File: GitFlowMetaData.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
/**
 * Open a Git repository using the specified directory.
 * @param gitProjectRootDir a root directory of a Git project
 * @return created Repository
 * @throws IOException thrown when the specified directory does not exist,
 * does not have read/write privilege or not containing .git directory
 */
private Repository openRepository(final File gitProjectRootDir) throws IOException {

    // Instead of using FileUtils.ensureDirectoryExistAndCanReadAndWrite, check availability manually here.
    // Because the util will try to create a dir if not exist.
    // The git dir should be initialized and configured by users.
    if (!gitProjectRootDir.isDirectory()) {
        throw new IOException(format("'%s' is not a directory or does not exist.", gitProjectRootDir));
    }

    if (!(gitProjectRootDir.canRead() && gitProjectRootDir.canWrite())) {
        throw new IOException(format("Directory '%s' does not have read/write privilege.", gitProjectRootDir));
    }

    // Search .git dir but avoid searching parent directories.
    final FileRepositoryBuilder builder = new FileRepositoryBuilder()
            .readEnvironment()
            .setMustExist(true)
            .addCeilingDirectory(gitProjectRootDir)
            .findGitDir(gitProjectRootDir);

    if (builder.getGitDir() == null) {
        throw new IOException(format("Directory '%s' does not contain a .git directory." +
                " Please init and configure the directory with 'git init' command before using it from NiFi Registry.",
                gitProjectRootDir));
    }

    return builder.build();
}
 
Example 4
Source File: Git.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
public Git() throws IOException {
  final FileRepositoryBuilder builder = new FileRepositoryBuilder();
  // scan environment GIT_* variables
  builder.readEnvironment();
  // scan up the file system tree
  builder.findGitDir();
  // if getGitDir is null, then we are not in a git repository
  repo = builder.getGitDir() == null ? null : builder.build();
}