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; }
private static Repository openMainRepo(File mainRepoDir) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); if(mainRepo.isBare()) { throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare"); } return mainRepo; }
private static Repository openMainRepo(File mainRepoDir) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); if(mainRepo.isBare()) { throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare"); } return mainRepo; }
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(); }
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(); }
public static void main(String[] args) throws IOException, GitAPIException { // first create a test-repository, the return is including the .get directory here! File repoDir = createSampleGitRepo(); // now open the resulting repository with a FileRepositoryBuilder FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository repository = builder.setGitDir(repoDir) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { System.out.println("Having repository: " + repository.getDirectory()); // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree) Ref head = repository.exactRef("refs/heads/master"); System.out.println("Ref of refs/heads/master: " + head); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(repoDir.getParentFile()); }
public static void main(String[] args) throws IOException, GitAPIException { // first create a test-repository, the return is including the .get directory here! File repoDir = createSampleGitRepo(); // now open the resulting repository with a FileRepositoryBuilder FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository repository = builder.setGitDir(repoDir) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { System.out.println("Having repository: " + repository.getDirectory()); // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree) Ref head = repository.exactRef("refs/heads/master"); System.out.println("Ref of refs/heads/master: " + head); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(repoDir.getParentFile()); }
public static void main(String[] args) throws IOException, GitAPIException { File mainRepoDir = createRepository(); try (Repository mainRepo = openMainRepo(mainRepoDir)) { addSubmodule(mainRepo); FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository subRepo = builder.setGitDir(new File("testrepo/.git")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { if (subRepo.isBare()) { throw new IllegalStateException("Repository at " + subRepo.getDirectory() + " should not be bare"); } } } System.out.println("All done!"); // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(mainRepoDir); }
public static void main(String[] args) throws IOException, GitAPIException { File mainRepoDir = createRepository(); try (Repository mainRepo = openMainRepo(mainRepoDir)) { addSubmodule(mainRepo); FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository subRepo = builder.setGitDir(new File("testrepo/.git")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { if (subRepo.isBare()) { throw new IllegalStateException("Repository at " + subRepo.getDirectory() + " should not be bare"); } } } System.out.println("All done!"); // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(mainRepoDir); }
@Nonnull private Repository getGitRepository() throws GitCommitIdExecutionException { Repository repository; FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder(); try { repository = repositoryBuilder .setGitDir(dotGitDirectory) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); } catch (IOException e) { throw new GitCommitIdExecutionException("Could not initialize repository...", e); } if (repository == null) { throw new GitCommitIdExecutionException("Could not create git repository. Are you sure '" + dotGitDirectory + "' is the valid Git root for your project?"); } return repository; }
try (Repository repository = builder.setGitDir(localPath2) .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) {
try (Repository repository = builder.setGitDir(localPath2) .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) {
try (Repository repository = builder.setGitDir(localPath) .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) {
try (Repository repository = builder.setGitDir(localPath) .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) {
builder.findGitDir(projectDir); if (builder.getGitDir() != null) { workTree = builder.getWorkTree();
protected static Repository getRepository(String repoLocation) throws IOException { return new FileRepositoryBuilder() .readEnvironment() .findGitDir(new File(repoLocation)) .build(); }
private org.eclipse.jgit.lib.Repository build(File directory) throws IOException { return new FileRepositoryBuilder() .setGitDir(directory) .readEnvironment() .findGitDir() .build(); }
public void buildRepository (File repositoryPath) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder = builder.setGitDir(repositoryPath); builder = builder.readEnvironment(); builder = builder.findGitDir(); repository = builder.build(); }
public static Git gitFromGitFolder(File gitFolder) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(gitFolder) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); return new Git(repository); } }
public void commitFile() throws IOException { final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Repository repository = builder.setWorkTree(new File(gitDir)).findGitDir().build(); try { new Git(repository).commit().setOnly("build.gradle").setMessage("Bump the version of builld.gradle").call(); } catch (final GitAPIException e) { e.printStackTrace(); } }