List of usage examples for org.eclipse.jgit.api Git Git
public Git(Repository repo)
From source file:net.rohanpm.camel.jgit.JGitReflect.java
License:Apache License
public Callable<?> getRepoCommand(String name, Repository repository) { final Method method = repoCommands.get(name); if (method == null) { return null; }/*from ww w . jav a 2 s. c o m*/ final Git git = new Git(repository); return invoke(name, method, git); }
From source file:net.tietema.versioning.GitJavaVersioning.java
License:Apache License
public String getRevision(File projectDir) throws MojoExecutionException { // XXX we use our own findGitDir because they JGit one doesn't find the git dir in a multi project build File gitDir = findGitDir(projectDir); String revision = "Unknown"; if (gitDir == null) return revision; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = null;/*from w ww .j a v a2 s . c o m*/ try { repository = builder.setGitDir(gitDir).readEnvironment() // scan environment GIT_* variables .findGitDir(projectDir) // scan up the file system tree .build(); log.info("Git dir: " + gitDir.toString()); RepositoryState state = repository.getRepositoryState(); log.info(state.getDescription()); String branch = repository.getBranch(); log.info("Branch is: " + branch); Git git = new Git(repository); String fullBranch = repository.getFullBranch(); log.info("Full branch is: " + fullBranch); ObjectId id = repository.resolve(fullBranch); log.info("Branch " + repository.getBranch() + " points to " + id.name()); Status status = git.status().call(); boolean strictClean = status.isClean(); // no untracked files boolean loseClean = status.getAdded().isEmpty() && status.getChanged().isEmpty() && status.getConflicting().isEmpty() && status.getMissing().isEmpty() && status.getModified().isEmpty() && status.getRemoved().isEmpty(); StringWriter buffer = new StringWriter(); JavaWriter writer = new JavaWriter(buffer); writer.emitPackage(packageName) .beginType(packageName + "." + className, "class", Modifier.PUBLIC | Modifier.FINAL) .emitField("String", "BRANCH", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, String.format(Locale.US, "\"%s\"", branch)) .emitField("String", "REVISION", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, String.format(Locale.US, "\"%s\"", id.name())) .emitField("String", "REVISION_SHORT", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, String.format(Locale.US, "\"%s\"", id.name().substring(0, 8))) .emitJavadoc("Strict Clean means no changes, not even untracked files") .emitField("boolean", "STRICT_CLEAN", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, (strictClean ? "true" : "false")) .emitJavadoc("Lose Clean means no changes except untracked files.") .emitField("boolean", "LOSE_CLEAN", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, (loseClean ? "true" : "false")) .endType(); revision = buffer.toString(); return revision; } catch (IOException e) { log.error(e); throw new MojoExecutionException(e.getMessage()); } catch (GitAPIException e) { log.error(e); throw new MojoExecutionException(e.getMessage()); } finally { if (repository != null) repository.close(); } }
From source file:net.vexelon.jdevlog.vcs.git.GitSource.java
License:Open Source License
@Override public Iterator<?> getLastHistory(long maxEntries) throws SCMException { Iterable<RevCommit> log = null; try {/*w ww. j a v a 2s . c om*/ Git git = new Git(repository); LogCommand cmd = git.log(); cmd.setMaxCount((int) maxEntries); // cmd.addPath(Constants.MASTER); try { cmd.add(repository.resolve(Constants.MASTER)); } catch (Exception e) { throw new SCMException("Error getting log messages!", e); } log = cmd.call(); } catch (NoHeadException e) { throw new SCMException("Error getting log messages!", e); } return log.iterator(); }
From source file:nl.architolk.ldt.license.GitLookUp.java
public String getCommitMessage(File file) throws GitAPIException { String repoRelativePath = pathResolver.relativize(file); String commitMessage = ""; Iterable<RevCommit> commits = new Git(repository).log().addPath(repoRelativePath).setMaxCount(1).call(); for (RevCommit commit : commits) { commitMessage = commit.getShortMessage(); }//w w w. ja va2s . c o m return commitMessage.replaceFirst("^Release ", ""); }
From source file:no.neworder.vcs.GitStatus.java
License:Open Source License
public GitStatus(File directory) throws IOException { File repositoryPath = new File(directory.getAbsolutePath()); RepositoryBuilder repositoryBuilder = new RepositoryBuilder(); Repository repository = repositoryBuilder.setWorkTree(repositoryPath).build(); Git git = new Git(repository); status = git.status().call();// w ww . j av a2 s. c om }
From source file:nz.co.fortytwo.signalk.handler.GitHandler.java
License:Open Source License
protected String upgrade(String path) throws Exception { //staticDir.mkdirs(); Repository repository = null;// ww w.j ava 2s . com try { String logFile = "output.log"; File installLogDir = new File(staticDir, "logs"); installLogDir.mkdirs(); // File destDir = new File(staticDir, SLASH + path); destDir.mkdirs(); File output = new File(installLogDir, logFile); String gitPath = github + path + ".git"; logger.debug("Updating from " + gitPath + " to " + destDir.getAbsolutePath()); FileUtils.writeStringToFile(output, "Updating from " + gitPath + " to " + destDir.getAbsolutePath() + "\n", false); Git git = null; try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); repository = builder.setGitDir(new File(destDir, "/.git")).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); git = new Git(repository); PullResult result = git.pull().call(); FileUtils.writeStringToFile(output, result.getMergeResult().toString(), true); logger.debug("DONE: Updated " + gitPath + " repository: " + result.getMergeResult().toString()); //now run npm install //runNpmInstall(output, destDir); } catch (Exception e) { FileUtils.writeStringToFile(output, e.getMessage(), true); FileUtils.writeStringToFile(output, e.getStackTrace().toString(), true); logger.debug("Error updating " + gitPath + " repository: " + e.getMessage(), e); } finally { if (git != null) git.close(); if (repository != null) repository.close(); } return logFile; } finally { if (repository != null) repository.close(); } }
From source file:org.abratuhi.camel.GitLogComponentTest.java
License:Apache License
public void setUp() throws Exception { repodir = File.createTempFile("tmp", "repo"); repodir.delete();//from w w w .j a va 2 s . c o m repodir.mkdir(); repogit = new File(repodir, ".git"); final FileRepository repo = new FileRepository(repogit); Git git = new Git(repo); repo.create(); final File repofile = File.createTempFile("tmp", "repofile", repodir); git.add().addFilepattern(".").call(); git.commit().setMessage("Test message").call(); super.setUp(); }
From source file:org.abratuhi.camel.GitLogProducer.java
License:Apache License
public void process(Exchange exchange) throws Exception { String repo = endpoint.getEndpointUri().substring("git://".length()); FileRepositoryBuilder frb = new FileRepositoryBuilder(); FileRepository fr = frb.setGitDir(new File(repo)).readEnvironment().build(); Git git = new Git(fr); Iterable<RevCommit> commits = git.log().call(); StringBuffer sb = new StringBuffer(); for (RevCommit rc : commits) { sb.append(rc.getShortMessage() + "\n"); }//w w w. ja va 2s. c o m GitLogMessage msg = new GitLogMessage(); msg.setBody(sb.toString()); exchange.setOut(msg); }
From source file:org.alex73.osm.monitors.export.GitClient.java
License:Open Source License
public synchronized void add(String path) { try {// ww w. j a v a2s .c om new Git(repository).add().addFilepattern(path).call(); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.alex73.osm.monitors.export.GitClient.java
License:Open Source License
public synchronized void remove(String path) { try {/* w ww.j a va 2s . c o m*/ new Git(repository).rm().addFilepattern(path).call(); } catch (Exception ex) { throw new RuntimeException(ex); } }