/** * Gets org.eclipse.jgit.lib.Repository object for existing Git Repository. * * @param repositoryPath the path to an existing Git Repository * @return {@link org.eclipse.jgit.lib.Repository} object * @throws IOException */ public static Repository getRepository(String repositoryPath) throws IOException { RepositoryBuilder repositoryBuilder = new RepositoryBuilder(); repositoryBuilder.findGitDir(new File(repositoryPath)); Repository repository = repositoryBuilder.build(); repository.getConfig().setString(BRANCH, MASTER, MERGE, REFS_HEADS_MASTER); return repository; }
/** * Initialize a new git repository. * * @param dir The directory in which to create a new .git/ folder and repository. */ public static Git init(final DirectoryResource dir) throws IOException { FileResource<?> gitDir = dir.getChildDirectory(".git").reify(FileResource.class); gitDir.mkdirs(); RepositoryBuilder db = new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup(); Git git = new Git(db.build()); git.getRepository().create(); return git; }
public static Git git(final DirectoryResource dir) throws IOException { RepositoryBuilder db = new RepositoryBuilder().findGitDir(dir.getUnderlyingResourceObject()); return new Git(db.build()); }
public Repository createRepository(File fullPath) throws IOException { RepositoryBuilder builder = new RepositoryBuilder(); builder.setGitDir(fullPath); return builder.build(); }