/** * @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 ); } }
public Git call() throws GitAPIException { try { RepositoryBuilder builder = new RepositoryBuilder(); if (bare) builder.setBare(); if (fs != null) { builder.setFS(fs); builder.readEnvironment(); if (gitDir != null) 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)); } else if (builder.getGitDir() == null) { String dStr = SystemReader.getInstance() .getProperty("user.dir"); //$NON-NLS-1$ if (!bare) d = new File(d, Constants.DOT_GIT); builder.setGitDir(d); } else {
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); } }
/** * 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 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(); } } }
try RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(dir); File gitDir = rb.getGitDir(); if (gitDir != null)
public static Repository getGitRepository(File baseDir) throws IOException { return new RepositoryBuilder().findGitDir(baseDir).build(); }
private Repository openRepo() throws TransportException { try { return new RepositoryBuilder().setGitDir(remoteGitDir).build(); } catch (IOException err) { throw new TransportException(uri, JGitText.get().notAGitDirectory); } }
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() ); }
Repository r = null; RepositoryBuilder b = new RepositoryBuilder().setGitDir(stagingDirectory).setWorkTree(sourceDirectory); r = b.build(); r = b.build();
throws Exception Model model = new Model(Git.wrap(new RepositoryBuilder().findGitDir().setFS(FS.DETECTED).build())); Metadata metadata = model.readMetadata();
@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; }
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; } }
@Override public boolean supports(File baseDir) { RepositoryBuilder builder = new RepositoryBuilder().findGitDir(baseDir); return builder.getGitDir() != null; }
Repository buildRepo(Path basedir) throws IOException { return getVerifiedRepositoryBuilder(basedir).build(); }
String wpath = "/tmp/test-git"; ArrayList<String> commits = new ArrayList<String>(); // get list of commit { File gitDir = new File(wpath); RepositoryBuilder builder = new RepositoryBuilder(); Repository repository = builder.setWorkTree(gitDir) .readEnvironment().findGitDir().build(); Git git = new Git(repository); for (RevCommit commit : git.log().call()) { String cid = commit.getId().toString().split(" ")[1]; commits.add(cid); } Collections.shuffle(commits); } // Random access { File gitDir = new File(wpath + "/subdir"); RepositoryBuilder builder = new RepositoryBuilder(); Repository repository = builder.setWorkTree(gitDir) .readEnvironment().findGitDir().build(); for (String cid : commits) { RevCommit commit = CommitUtils.getCommit(repository, cid); assertEquals(commit.getId().toString().split(" ")[1], cid); } }
@Override public Path relativePathFromScmRoot(Path path) { RepositoryBuilder builder = getVerifiedRepositoryBuilder(path); return builder.getGitDir().toPath().getParent().relativize(path); }
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(); } } }
try RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(dir); File gitDir = rb.getGitDir(); if (gitDir != null)