public static Repository openJGitCookbookRepository() throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); return builder .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); }
@Autowired public ConfigRepository(SystemEnvironment systemEnvironment) throws IOException { this.systemEnvironment = systemEnvironment; workingDir = this.systemEnvironment.getConfigRepoDir(); File configRepoDir = new File(workingDir, ".git"); gitRepo = new FileRepositoryBuilder().setGitDir(configRepoDir).build(); gitRepo.getConfig().setInt("gc", null, "auto", 0); git = new Git(gitRepo); }
/** * {@inheritDoc} * <p> * Create a repository matching the configuration in this builder. * <p> * If an option was not set, the build method will try to default the option * based on other options. If insufficient information is available, an * exception is thrown to the caller. * * @since 3.0 */ @Override public Repository build() throws IOException { FileRepository repo = new FileRepository(setup()); if (isMustExist() && !repo.getObjectDatabase().exists()) throw new RepositoryNotFoundException(getGitDir()); return repo; }
private static List<RevCommit> getCommitsToCheck() throws Exception { final List<RevCommit> commits; try (Repository repo = new FileRepositoryBuilder().findGitDir().build()) { final RevCommitsPair revCommitsPair = resolveRevCommitsPair(repo); if (COMMITS_RESOLUTION_MODE == CommitsResolutionMode.BY_COUNTER) { commits = getCommitsByCounter(revCommitsPair.getFirst()); commits.addAll(getCommitsByCounter(revCommitsPair.getSecond())); } else { commits = getCommitsByLastCommitAuthor(revCommitsPair.getFirst()); commits.addAll(getCommitsByLastCommitAuthor(revCommitsPair.getSecond())); } } return commits; }
@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(); }
private Repository createJGitRepository( RepoStore repoStore, String projName ) throws IOException { File repoDir = new File(repoStore.getRootDirectory(), projName); return new FileRepositoryBuilder().setWorkTree(repoDir).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(); }
/** * Method description * * * @param directory * * @return * * @throws IOException */ public static org.eclipse.jgit.lib.Repository open(File directory) throws IOException { FS fs = FS.DETECTED; FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.setFS(fs); if (isGitDirectory(fs, directory)) { // bare repository builder.setGitDir(directory).setBare(); } else { builder.setWorkTree(directory); } return builder.build(); }
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder(); repositoryBuilder.addCeilingDirectory(getProject().getProjectDir()); repositoryBuilder.findGitDir(getProject().getProjectDir()); boolean create = (repositoryBuilder.getGitDir() == null); repositoryBuilder.setWorkTree(getProject().getProjectDir()); Repository repository = repositoryBuilder.build();
final void buildRepository(File workTree, File gitDir) throws GitRepositoryException { if (gitDir == null && workTree == null) { throw new GitRepositoryException("Neither worktree nor GIT_DIR is set."); } else { if (workTree != null && !workTree.exists()) { throw new GitRepositoryException("The worktree " + workTree + " does not exist"); } if (gitDir != null && !gitDir.exists()) { throw new GitRepositoryException("The GIT_DIR " + gitDir + " does not exist"); } } FileRepositoryBuilder repositoryBuilder = getRepositoryBuilder(); if (gitDir == null) { if (repositoryBuilder.findGitDir(workTree).getGitDir() == null) { throw new GitRepositoryException(workTree + " is not inside a Git repository. Please specify the GIT_DIR separately."); } repositoryBuilder.setWorkTree(repositoryBuilder.getGitDir().getParentFile()); } else { repositoryBuilder.setGitDir(gitDir); repositoryBuilder.setWorkTree(workTree); } try { repository = repositoryBuilder.build(); } catch (IOException e) { throw new GitRepositoryException("Could not initialize repository", e); } }
/** * Construct a representation of a Git repository. * <p> * The work tree, object directory, alternate object directories and index * file locations are deduced from the given git directory and the default * rules by running * {@link org.eclipse.jgit.storage.file.FileRepositoryBuilder}. This * constructor is the same as saying: * * <pre> * new FileRepositoryBuilder().setGitDir(gitDir).build() * </pre> * * @param gitDir * GIT_DIR (the location of the repository metadata). * @throws java.io.IOException * the repository appears to already exist but cannot be * accessed. * @see FileRepositoryBuilder */ public FileRepository(File gitDir) throws IOException { this(new FileRepositoryBuilder().setGitDir(gitDir).setup()); }
FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.setGitDir(new File("localrepositary"+"\\.git")).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.add(rev.getFullMessage()); }
FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.findGitDir(projectDir); if (builder.getGitDir() != null) { workTree = builder.getWorkTree(); repoConfig = new FileBasedConfig(userConfig, new File(builder.getGitDir(), Constants.CONFIG), FS.DETECTED); repoAttributesFile = new File(builder.getGitDir(), Constants.INFO_ATTRIBUTES); } else { workTree = null;
/** * Creates a new JGit {@code FileRepositoryBuilder} instance * * @return A new repository builder */ FileRepositoryBuilder getRepositoryBuilder() { return new FileRepositoryBuilder().readEnvironment(); }
File workTree = new File("/path/to/git-repository"); Repository repository = new FileRepositoryBuilder().setWorkTree(workTree).build();
private boolean isWorktree(FileRepositoryBuilder builder) { Path gitDirParent = builder.getGitDir().toPath().getParent(); return gitDirParent.getFileName().toString().equals("worktrees") && gitDirParent.getParent().getFileName().toString().equals(".git"); }
public GitRepository() throws IOException { final FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder(); repositoryBuilder.findGitDir(); this.repository = repositoryBuilder.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(
@Override public Repository openRepository() throws IOException { File rd = getRepositoryDir(); // TODO 7: should we cache r here? Who will be closing r? FileRepository r = new FileRepositoryBuilder().setWorkTree(rd).build(); if (!r.getObjectDatabase().exists()){ r.create(); try { new FilePath(rd).untarFrom(JenkowWorkflowRepository.class.getResourceAsStream("/jenkow-repository-seed.tar"),FilePath.TarCompression.NONE); } catch (InterruptedException e1) { LOGGER.log(Level.WARNING, "Seeding of jenkow-repository failed",e1); } addAndCommit(r,".","Initial import of the existing contents"); } return r; }
/** * Construct a representation of a Git repository. * <p> * The work tree, object directory, alternate object directories and index * file locations are deduced from the given git directory and the default * rules by running {@link FileRepositoryBuilder}. This constructor is the * same as saying: * * <pre> * new FileRepositoryBuilder().setGitDir(gitDir).build() * </pre> * * @param gitDir * GIT_DIR (the location of the repository metadata). * @throws IOException * the repository appears to already exist but cannot be * accessed. * @see FileRepositoryBuilder */ public FileRepository(final File gitDir) throws IOException { this(new FileRepositoryBuilder().setGitDir(gitDir).setup()); }