/** * @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 ); } }
builder.setFS(fs); builder.readEnvironment(); if (gitDir != null) builder.setGitDir(gitDir);
@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; }
@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; }
@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; }
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; }
/** * 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() ); }
.readEnvironment() .findGitDir(dir);
/** * 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); } }
.readEnvironment() .findGitDir(dir);
/** * 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()); }
private Git getOrInitGit(File folder) throws IOException, GitAPIException { reporter.debugMethod(SHORT_NAME, "getOrInitGit"); Git gitRepo; try { reporter.debugText(SHORT_NAME, "looking for git folder in " + folder.getAbsolutePath()); RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(folder); File gitDir = rb.getGitDir(); if (null != gitDir) { reporter.debugText(SHORT_NAME, "found existing git folder"); gitRepo = Git.open(gitDir); } else { reporter.debugText(SHORT_NAME, "no git folder found, initializing"); gitRepo = Git.init().setDirectory(folder).call(); } } catch (RepositoryNotFoundException e) { reporter.debugText(SHORT_NAME, "no git folder found, initializing"); gitRepo = Git.init().setDirectory(folder).call(); } reporter.endMethod(); return gitRepo; }
private Git getOrInitGit(File folder) throws IOException, GitAPIException { reporter.debugMethod(SHORT_NAME, "getOrInitGit"); Git gitRepo; try { reporter.debugText(SHORT_NAME, "looking for git folder in " + folder.getAbsolutePath()); RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(folder); File gitDir = rb.getGitDir(); if (null != gitDir) { reporter.debugText(SHORT_NAME, "found existing git folder"); gitRepo = Git.open(gitDir); } else { reporter.debugText(SHORT_NAME, "no git folder found, initializing"); gitRepo = Git.init().setDirectory(folder).call(); } } catch (RepositoryNotFoundException e) { reporter.debugText(SHORT_NAME, "no git folder found, initializing"); gitRepo = Git.init().setDirectory(folder).call(); } reporter.endMethod(); return gitRepo; }
private Git getOrInitGit(File folder) throws IOException, GitAPIException { reporter.debugMethod(SHORT_NAME, "getOrInitGit"); Git gitRepo; try { reporter.debugText(SHORT_NAME, "looking for git folder in " + folder.getAbsolutePath()); RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(folder); File gitDir = rb.getGitDir(); if (null != gitDir) { reporter.debugText(SHORT_NAME, "found existing git folder"); gitRepo = Git.open(gitDir); } else { reporter.debugText(SHORT_NAME, "no git folder found, initializing"); gitRepo = Git.init().setDirectory(folder).call(); } } catch (RepositoryNotFoundException e) { reporter.debugText(SHORT_NAME, "no git folder found, initializing"); gitRepo = Git.init().setDirectory(folder).call(); } reporter.endMethod(); return gitRepo; }