/** * @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 ); } }
@Override public boolean supports(File baseDir) { RepositoryBuilder builder = new RepositoryBuilder().findGitDir(baseDir); return builder.getGitDir() != null; }
public static Repository getGitRepository(File baseDir) throws IOException { return new RepositoryBuilder().findGitDir(baseDir).build(); }
@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; }
@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; }
public Repository openRepository(File gitdir) throws IOException, NoGitRepositoryException { log.debug("About to open git repository."); Repository repository; try { if ( gitdir == null ) { repository = new RepositoryBuilder().findGitDir().build(); } else { repository = new RepositoryBuilder().findGitDir(gitdir).build(); } } catch (IllegalArgumentException iae) { throw new NoGitRepositoryException(); } log.debug("Opened " + repository + ". About to load the commits."); walk = createWalk(repository); log.debug("Loaded commits. about to load the tags."); commitIDToTagsMap = createCommitIDToTagsMap(repository, walk); log.debug("Loaded tag map: " + commitIDToTagsMap); return repository; }
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; } }
public static Repository openRepository() throws NoGitRepositoryException, IOException { Repository repository = null; try { repository = new RepositoryBuilder().findGitDir().build(); } catch (IllegalArgumentException iae) { throw new NoGitRepositoryException(); } return repository; }
private Repository getRepositoryFromPath( String _path ) { Repository repository = null; try { if ( _path == null ) { _path = this.workDir.toString() + "/.git"; } else { _path += "/.git"; } RepositoryBuilder builder = new RepositoryBuilder(); repository = builder.setGitDir( new File( _path ) ) .readEnvironment() .findGitDir() .build(); } catch ( Exception e ) { e.printStackTrace(); } return repository; }
@Override public Git git(final DirectoryResource dir) throws IOException { RepositoryBuilder db = new RepositoryBuilder().findGitDir(dir.getUnderlyingResourceObject()); return new Git(db.build()); }
/** * 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() ); }
/** * 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 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); } }
/** * Gets an existing git flow project and returns a JGitFlow instance * * @param projectDir * @return * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static JGitFlow get(File projectDir) throws JGitFlowIOException { try { RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(projectDir); File gitDir = rb.getGitDir(); Git gitRepo = Git.open(gitDir); GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo); return new JGitFlow(gitRepo, gfConfig); } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Gets an existing git flow project and returns a JGitFlow instance * * @param projectDir * @return * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static JGitFlow get(File projectDir) throws JGitFlowIOException { try { RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(projectDir); File gitDir = rb.getGitDir(); Git gitRepo = Git.open(gitDir); GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo); return new JGitFlow(gitRepo, gfConfig); } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Gets an existing git flow project and returns a JGitFlow instance * @param projectDir * @return * @throws JGitFlowIOException */ public static JGitFlow get(File projectDir) throws JGitFlowIOException { try { RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(projectDir); File gitDir = rb.getGitDir(); Git gitRepo = Git.open(gitDir); GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo); return new JGitFlow(gitRepo, gfConfig, new JGitFlowReporter()); } catch (IOException e) { throw new JGitFlowIOException(e); } }
@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()); }