@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); }
.setGitDir(directory.resolve(".git").toFile()) .build();
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; }
/** * 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()); }
/** * Convenience factory method to construct a * {@link org.eclipse.jgit.internal.storage.file.FileRepository}. * * @param gitDir * {@code GIT_DIR}, the repository meta directory. * @return a repository matching this configuration. * @throws java.io.IOException * the repository could not be accessed to configure the rest of * the builder's parameters. * @since 3.0 */ public static Repository create(File gitDir) throws IOException { return new FileRepositoryBuilder().setGitDir(gitDir).readEnvironment() .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)
try (Repository repository = builder.setGitDir(localPath2)
try (Repository repository = builder.setGitDir(localPath)
try (Repository repository = builder.setGitDir(localPath)
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()); }
public void init(String jiraProjectId, Logger logger) throws IOException { // Open an existing repository existingRepo = new FileRepositoryBuilder() .setGitDir(new File(".git")) .build(); logger.quiet("Current branch " + existingRepo.getBranch()); this.logger = logger; this.smartCommitPattern = Pattern.compile(".*(" + jiraProjectId + "-\\d*).*"); }
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); } }