RevCommit getRevCommitForCommitSHA(String commitSHA) throws GitAPIException { for (RevCommit revision : revisions()) { if (revision.getName().equals(commitSHA)) { return revision; } } throw new IllegalArgumentException(String.format("There is no commit corresponding to SHA: '%s'", commitSHA)); }
@Override public String getCommitId() throws GitCommitIdExecutionException { return evalCommit.getName(); }
this.lastProcessedGitHash = lastLog.getName();
/** * Construct the squashed commit message. * * @param squashedCommits * the squashed commits * @param target * the target branch * @return squashed commit message */ public String format(List<RevCommit> squashedCommits, Ref target) { StringBuilder sb = new StringBuilder(); sb.append("Squashed commit of the following:\n"); //$NON-NLS-1$ for (RevCommit c : squashedCommits) { sb.append("\ncommit "); //$NON-NLS-1$ sb.append(c.getName()); sb.append("\n"); //$NON-NLS-1$ sb.append(toString(c.getAuthorIdent())); sb.append("\n\t"); //$NON-NLS-1$ sb.append(c.getShortMessage()); sb.append("\n"); //$NON-NLS-1$ } return sb.toString(); }
@Override public String getTags() throws GitCommitIdExecutionException { try { Repository repo = getGitRepository(); ObjectId headId = evalCommit.toObjectId(); Collection<String> tags = jGitCommon.getTags(repo, headId); return String.join(",", tags); } catch (GitAPIException e) { log.error("Unable to extract tags from commit: {} ({})", evalCommit.getName(), e.getClass().getName()); return ""; } }
protected RevCommit findEvalCommitObjectId(@Nonnull String evaluateOnCommit, @Nonnull Repository repo) throws RuntimeException { try { ObjectId evalCommitId = repo.resolve(evaluateOnCommit); try (RevWalk walk = new RevWalk(repo)) { RevCommit evalCommit = walk.parseCommit(evalCommitId); walk.dispose(); log.info("evalCommit is [{}]", evalCommit.getName()); return evalCommit; } } catch (IOException ex) { throw new RuntimeException("Unable to obtain " + evaluateOnCommit + " commit!", ex); } }
private List<RevCommit> getNewParents(RevCommit commitToPick) throws IOException { List<RevCommit> newParents = new ArrayList<>(); for (int p = 0; p < commitToPick.getParentCount(); p++) { String parentHash = commitToPick.getParent(p).getName(); if (!new File(rebaseState.getRewrittenDir(), parentHash).exists()) newParents.add(commitToPick.getParent(p)); else { String newParent = RebaseState.readFile( rebaseState.getRewrittenDir(), parentHash); if (newParent.length() == 0) newParents.add(walk.parseCommit(repo .resolve(Constants.HEAD))); else newParents.add(walk.parseCommit(ObjectId .fromString(newParent))); } } return newParents; }
public GitTool() { File gitWorkDir = new File("."); try { Git git = Git.open(gitWorkDir); Iterable<RevCommit> commits = git.log().all().call(); Repository repo = git.getRepository(); branch = repo.getBranch(); RevCommit latestCommit = commits.iterator().next(); name = latestCommit.getName(); message = latestCommit.getFullMessage(); } catch (Throwable e) { name = ""; message = ""; branch = ""; } }
RevCommit base; while ((base = walk.next()) != null) RebaseState.createFile(rewrittenDir, base.getName(), upstreamCommit.getName()); for (int i = 0; i < commit.getParentCount(); i++) { boolean parentRewritten = new File(rewrittenDir, commit .getParent(i).getName()).exists(); if (parentRewritten) { new File(rewrittenDir, commit.getName()).createNewFile(); continue pickLoop;
public static void main(String args[]) throws IOException, GitAPIException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { final String[] list = new File(".").list(); if(list == null) { throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath()); } for(String file : list) { if(new File(file).isDirectory()) { continue; } System.out.println("Blaming " + file); final BlameResult result = new Git(repo).blame().setFilePath(file) .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call(); final RawText rawText = result.getResultContents(); for (int i = 0; i < rawText.size(); i++) { final PersonIdent sourceAuthor = result.getSourceAuthor(i); final RevCommit sourceCommit = result.getSourceCommit(i); System.out.println(sourceAuthor.getName() + (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") + ": " + rawText.getString(i)); } } } } }
public static void main(String args[]) throws IOException, GitAPIException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { final String[] list = new File(".").list(); if(list == null) { throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath()); } for(String file : list) { if(new File(file).isDirectory()) { continue; } System.out.println("Blaming " + file); final BlameResult result = new Git(repo).blame().setFilePath(file) .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call(); final RawText rawText = result.getResultContents(); for (int i = 0; i < rawText.size(); i++) { final PersonIdent sourceAuthor = result.getSourceAuthor(i); final RevCommit sourceCommit = result.getSourceCommit(i); System.out.println(sourceAuthor.getName() + (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") + ": " + rawText.getString(i)); } } } } }
System.out.println("StashDrop returned: " + call); ObjectId applied = git.stashApply().setStashRef(stash.getName()).call(); System.out.println("Applied 2nd stash as: " + applied);
System.out.println("StashDrop returned: " + call); ObjectId applied = git.stashApply().setStashRef(stash.getName()).call(); System.out.println("Applied 2nd stash as: " + applied);
private void autoStash() throws GitAPIException, IOException { if (repo.getConfig().getBoolean(ConfigConstants.CONFIG_REBASE_SECTION, ConfigConstants.CONFIG_KEY_AUTOSTASH, false)) { String message = MessageFormat.format( AUTOSTASH_MSG, Repository .shortenRefName(getHeadName(getHead()))); RevCommit stashCommit = Git.wrap(repo).stashCreate().setRef(null) .setWorkingDirectoryMessage( message) .call(); if (stashCommit != null) { FileUtils.mkdir(rebaseState.getDir()); rebaseState.createFile(AUTOSTASH, stashCommit.getName()); } } }
rup.setNewObjectId(aNewHead); rup.setRefLogMessage("rebase finished: " + headName + " onto " //$NON-NLS-1$ //$NON-NLS-2$ + onto.getName(), false); Result res = rup.forceUpdate(); switch (res) {
"checkout: moving from " //$NON-NLS-1$ + Repository.shortenRefName(headName) + " to " + commit.getName(), false); //$NON-NLS-1$ Result res = refUpdate.forceUpdate(); switch (res) {
public void getCommits(String treeName) { Repository repository = new FileRepository("/home/felipe/git/testRepository/.git"); AndCommitFilter filters = new AndCommitFilter(); CommitListFilter revCommits = new CommitListFilter(); filters.add(revCommits); CommitFinder finder = new CommitFinder(repository); finder.setFilter(filters); finder.findFrom(treeName); for(RevCommit revCommit : revCommits){ System.out.println(revCommit.getName()); } }