/** * @param gitConfigFolder e.g. /your/project/root/.git * * @return Returns git config remote.origin.url field of the repository located at gitConfigFolder */ public static String getGitRemoteUrl( String gitConfigFolder ) throws MojoExecutionException { try { Repository repo = new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir() .build(); Config config = repo.getConfig(); return config.getString( "remote", "origin", "url" ); } catch ( Exception e ) { throw new MojoExecutionException( "Error trying to get remote origin url of git repository", e ); } }
/** * @param gitConfigFolder e.g. /your/project/root/.git * * @return Returns last commit's UUID, "nocommit" if there are no commits and returns null if an exception occured */ public static String getLastCommitUuid( String gitConfigFolder ) throws MojoExecutionException { try { Repository repo = new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir() .build(); RevWalk walk = new RevWalk( repo ); ObjectId head = repo.resolve( "HEAD" ); if ( head != null ) { RevCommit lastCommit = walk.parseCommit( head ); return lastCommit.getId().getName(); } else { return "nocommit"; } } catch ( Exception e ) { throw new MojoExecutionException( "Error trying to get the last git commit uuid", e ); } }
private Repository openRepo() throws TransportException { try { return new RepositoryBuilder() .setFS(local != null ? local.getFS() : FS.DETECTED) .setGitDir(remoteGitDir).build(); } catch (IOException err) { throw new TransportException(uri, JGitText.get().notAGitDirectory); } }
builder.setGitDir(gitDir); else gitDir = builder.getGitDir(); if (directory != null) { if (bare) builder.setGitDir(directory); else { builder.setWorkTree(directory); if (gitDir == null) builder.setGitDir(new File(directory, Constants.DOT_GIT)); if (!bare) d = new File(d, Constants.DOT_GIT); builder.setGitDir(d); } else {
/** * Open repository * * @param dir * the repository to open. May be either the GIT_DIR, or the * working tree directory that contains {@code .git}. * @param fs * filesystem abstraction to use when accessing the repository. * @return a {@link org.eclipse.jgit.api.Git} object for the existing git * repository. Closing this instance will close the repo. * @throws java.io.IOException */ public static Git open(File dir, FS fs) throws IOException { RepositoryCache.FileKey key; key = RepositoryCache.FileKey.lenient(dir, fs); Repository db = new RepositoryBuilder().setFS(fs).setGitDir(key.getFile()) .setMustExist(true).build(); return new Git(db, true); }
@Nonnull public static Repository createRepository(@Nonnull File dir, boolean bare) throws IOException { Repository repo = new RepositoryBuilder() .readEnvironment() .setGitDir(bare ? dir : new File(dir, Constants.DOT_GIT)) .build(); repo.create(bare); return repo; }
@Override public Repository openRepository(String repositoryPath) throws Exception { File folder = new File(repositoryPath); Repository repository; if (folder.exists()) { RepositoryBuilder builder = new RepositoryBuilder(); repository = builder .setGitDir(new File(folder, ".git")) .readEnvironment() .findGitDir() .build(); } else { throw new FileNotFoundException(repositoryPath); } return repository; }
@Nonnull public static Repository createRepository(File dir, boolean bare) throws IOException { Repository repo = new RepositoryBuilder() .readEnvironment() .setGitDir(bare ? dir : new File(dir, DOT_GIT)) .build(); repo.create(bare); return repo; }
@Override public Repository openRepository(String repositoryPath) throws Exception { File folder = new File(repositoryPath); Repository repository; if (folder.exists()) { RepositoryBuilder builder = new RepositoryBuilder(); repository = builder .setGitDir(new File(folder, ".git")) .readEnvironment() .findGitDir() .build(); } else { throw new FileNotFoundException(repositoryPath); } return repository; }
@Nonnull public static Repository createRepository(File dir, boolean bare) throws IOException { Repository repo = new RepositoryBuilder() .readEnvironment() .setGitDir(bare ? dir : new File(dir, DOT_GIT)) .build(); repo.create(bare); return repo; }
/** {@inheritDoc} */ @Deprecated @Override public void setRemoteUrl(String name, String url, String GIT_DIR) throws GitException, InterruptedException { try (Repository repo = new RepositoryBuilder().setGitDir(new File(GIT_DIR)).build()) { StoredConfig config = repo.getConfig(); config.setString("remote", name, "url", url); config.save(); } catch (IOException ioe) { throw new GitException(ioe); } }
private static Repository repo(File repoDir) throws IOException { final Lock lock = getLock(repoDir); boolean success = false; lock.lock(); try { repoDir.getParentFile().mkdirs(); final Repository repo = new RepositoryBuilder().setGitDir(repoDir).setBare().build(); if (!repo.getObjectDatabase().exists()) { repo.create(true); } success = true; return repo; } finally { if (!success) { lock.unlock(); } } }
private static boolean exist(File repoDir) { try { final RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(repoDir); final org.eclipse.jgit.lib.Repository repository = repositoryBuilder.build(); if (repository.getConfig() instanceof FileBasedConfig) { return ((FileBasedConfig) repository.getConfig()).getFile().exists(); } return repository.getDirectory().exists(); } catch (IOException e) { throw new StorageException("failed to check if repository exists at " + repoDir, e); } }
private static boolean exist(File repoDir) { try { final RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(repoDir); final org.eclipse.jgit.lib.Repository repository = repositoryBuilder.build(); if (repository.getConfig() instanceof FileBasedConfig) { return ((FileBasedConfig) repository.getConfig()).getFile().exists(); } return repository.getDirectory().exists(); } catch (IOException e) { throw new StorageException("failed to check if repository exists at " + repoDir, e); } }
private static boolean exist(File repoDir) { try { final RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(repoDir); final org.eclipse.jgit.lib.Repository repository = repositoryBuilder.build(); if (repository.getConfig() instanceof FileBasedConfig) { return ((FileBasedConfig) repository.getConfig()).getFile().exists(); } return repository.getDirectory().exists(); } catch (IOException e) { throw new StorageException("failed to check if repository exists at " + repoDir, e); } }
private Repository openRepo() throws TransportException { try { return new RepositoryBuilder().setGitDir(remoteGitDir).build(); } catch (IOException err) { throw new TransportException(uri, JGitText.get().notAGitDirectory); } }
private Repository openRepo() throws TransportException { try { return new RepositoryBuilder() .setFS(local != null ? local.getFS() : FS.DETECTED) .setGitDir(remoteGitDir).build(); } catch (IOException err) { throw new TransportException(uri, JGitText.get().notAGitDirectory); } }
/** * @param dir * the repository to open. May be either the GIT_DIR, or the * working tree directory that contains {@code .git}. * @param fs * filesystem abstraction to use when accessing the repository. * @return a {@link Git} object for the existing git repository. Closing this * instance will close the repo. * @throws IOException */ public static Git open(File dir, FS fs) throws IOException { RepositoryCache.FileKey key; key = RepositoryCache.FileKey.lenient(dir, fs); Repository db = new RepositoryBuilder().setFS(fs).setGitDir(key.getFile()) .setMustExist(true).build(); return new Git(db, true); }
@Override public Git init(final DirectoryResource dir) throws IOException { FileResource<?> gitDir = dir.getChildDirectory(GIT_DIRECTORY).reify(FileResource.class); gitDir.mkdirs(); RepositoryBuilder db = new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup(); Git git = new Git(db.build()); git.getRepository().create(); return git; }
@BeforeClass public static void beforeAll() throws Exception { File gitDir = new File("../../.git"); RepositoryBuilder builder = new RepositoryBuilder(); repository = builder.setGitDir(gitDir).readEnvironment().findGitDir().build(); git = new Git(repository); context = new ExecutionContext(); values = new Values(context.getValueFactories(), context.getBinaryStore()); }