/** * @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 ); } }
/** * Get submodule repository at path, using the specified file system * abstraction * * @param parent * @param path * @param fs * the file system abstraction to be used * @return repository or null if repository doesn't exist * @throws IOException * @since 4.10 */ public static Repository getSubmoduleRepository(final File parent, final String path, FS fs) throws IOException { File subWorkTree = new File(parent, path); if (!subWorkTree.isDirectory()) return null; File workTree = new File(parent, path); try { return new RepositoryBuilder() // .setMustExist(true) // .setFS(fs) // .setWorkTree(workTree) // .build(); } catch (RepositoryNotFoundException e) { return null; } }
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); } }
/** * 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); }
public Git call() throws GitAPIException { try { RepositoryBuilder builder = new RepositoryBuilder(); if (bare) builder.setBare();
@Override public boolean supports(File baseDir) { RepositoryBuilder builder = new RepositoryBuilder().findGitDir(baseDir); return builder.getGitDir() != null; }
/** * Opens a JGit repository in the current directory or a parent directory. * @param basedir The directory to start with * @throws IOException If the repository cannot be opened */ public static Git openRepo( File basedir ) throws IOException { return new Git( new RepositoryBuilder().readEnvironment().findGitDir( basedir ).setMustExist( true ).build() ); }
public RepoMerger(String outputRepositoryPath, List<SubtreeConfig> subtreeConfigs) throws IOException { this.subtreeConfigs = subtreeConfigs; File file = new File(outputRepositoryPath); repository = new RepositoryBuilder().setWorkTree(file).build(); if (!repository.getDirectory().exists()) { repository.create(); } }
/** * Opens a JGit repository in the current directory or a parent directory. * @param basedir The directory to start with * @throws IOException If the repository cannot be opened */ public static Git openRepo( File basedir ) throws IOException { return new Git( new RepositoryBuilder().readEnvironment().findGitDir( basedir ).setMustExist( true ).build() ); }
static RepositoryBuilder getVerifiedRepositoryBuilder(Path basedir) { RepositoryBuilder builder = new RepositoryBuilder() .findGitDir(basedir.toFile()) .setMustExist(true); if (builder.getGitDir() == null) { throw MessageException.of("Not inside a Git work tree: " + basedir); } return builder; } }
/** {@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 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 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() .setFS(local != null ? local.getFS() : FS.DETECTED) .setGitDir(remoteGitDir).build(); } catch (IOException err) { throw new TransportException(uri, JGitText.get().notAGitDirectory); } }
public Git load() throws IOException { try (Repository repository = new RepositoryBuilder().findGitDir(this.sourceDirectory).build()) { Git.Head head = getHead(repository); String branch = getBranch(repository); List<Git.Remote> remotes = getRemotes(repository); return new Git(repository.getWorkTree(), head, branch, remotes); } }
public Git load() throws IOException { try (Repository repository = new RepositoryBuilder().findGitDir(this.sourceDirectory).build()) { Git.Head head = getHead(repository); String branch = getBranch(repository); List<Git.Remote> remotes = getRemotes(repository); return new Git(repository.getWorkTree(), head, branch, remotes); } }
@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()); }