@GET @Produces(MediaType.APPLICATION_JSON) public static Response get() { Map<String,String> logMessages = new HashMap<>(); try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.setGitDir(new File(VerigreenNeededLogic.properties.getProperty("git.repositoryLocation"))).setMustExist(true).build(); Git git = new Git(repo); Iterable<RevCommit> log = git.log().call(); for (Iterator<RevCommit> iterator = log.iterator(); iterator.hasNext();) { RevCommit rev = iterator.next(); logMessages.put(rev.getName(),rev.getFullMessage()); } } catch(Exception e){ e.printStackTrace(); } return Response.status(Status.OK).entity(logMessages).build(); }
/** * 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(); }
public String getCommitMessage(String commitId){ String commitMessage = null; try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); String repoPath = VerigreenNeededLogic.properties.getProperty("git.repositoryLocation"); Repository repo = builder.setGitDir(new File(repoPath)).setMustExist(true).build(); Git git = new Git(repo); Iterable<RevCommit> log = git.log().call(); Iterator<RevCommit> iterator = log.iterator(); while(commitMessage == null && iterator.hasNext()){ RevCommit rev = iterator.next(); String commit = rev.getName().substring(0,7); if(commit.equals(commitId)){ commitMessage = rev.getFullMessage(); } } } catch(Exception e){ e.printStackTrace(); } return commitMessage; } public void notifyCommiter(
@SneakyThrows private static Git initializeGitRepository(final File path, final boolean mustExist) { LOGGER.debug("Initializing git repository directory at [{}] with strict path checking [{}]", path, BooleanUtils.toStringOnOff(mustExist)); val builder = new FileRepositoryBuilder() .setGitDir(path) .setMustExist(mustExist) .findGitDir() .readEnvironment(); try { return new Git(builder.build()); } catch (final RepositoryNotFoundException e) { LOGGER.error("Git repository not found/initialized at [{}]", path.getCanonicalPath()); } return null; } }
.setMustExist(true) .setGitDir(srcPath.toFile()).build(); final Repository dstRepo = new FileRepositoryBuilder() .setMustExist(false) .setGitDir(dstPath.toFile()).build();
.call(); } else { Repository gitRepo = builder.setWorkTree(repositoryPath.toFile()).setMustExist(false).build(); this.git = new Git(gitRepo); try {
repository = new FileRepositoryBuilder().setGitDir(gitDir).setMustExist(true).setBare().build(); git = new Git(repository);
/** * @param gitBasedRepositoryConfiguration the configuration of the repository * @throws IOException thrown if repository does not exist * @throws GitAPIException thrown if there was an error while checking the status of the repository * @throws NoWorkTreeException thrown if the directory is not a git work tree */ public GitBasedRepository(GitBasedRepositoryConfiguration gitBasedRepositoryConfiguration) throws IOException, NoWorkTreeException, GitAPIException { super(Objects.requireNonNull(gitBasedRepositoryConfiguration)); this.gitBasedRepositoryConfiguration = gitBasedRepositoryConfiguration; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository gitRepo = builder.setWorkTree(this.repositoryRoot.toFile()).setMustExist(false).build(); if (!Files.exists(this.repositoryRoot.resolve(".git"))) { gitRepo.create(); } // explicitly enable longpaths to ensure proper handling of long pathss gitRepo.getConfig().setBoolean("core", null, "longpaths", true); gitRepo.getConfig().save(); this.eventBus = new EventBus(); this.git = new Git(gitRepo); if (gitBasedRepositoryConfiguration.isAutoCommit() && !this.git.status().call().isClean()) { this.addCommit("Files changed externally."); } }
repo = builder.setWorkTree(repoDir). setGitDir(new File(repoDir, ".git")). setMustExist(false). build(); Bundle bundle = findBundleForPlugin(bundleContext, id);