public RevCommit getRevCommitForMd5(String md5) throws GitAPIException { Assert.notNull(md5, "md5 is required"); final String expectedPart = GoConfigRevision.Fragment.md5.represent(GoConfigRevision.esc(md5)); for (RevCommit revision : revisions()) { String message = revision.getFullMessage(); if (message.endsWith(expectedPart)) { return revision; } } throw new IllegalArgumentException(String.format("There is no config version corresponding to md5: '%s'", md5)); }
private GoConfigRevision getGoConfigRevision(final RevCommit revision) { return new GoConfigRevision(contentFromTree(revision.getTree()), revision.getFullMessage()); }
public GoConfigRevisions getCommits(final int pageSize, final int offset) { return doLocked(() -> { GoConfigRevisions goConfigRevisions = new GoConfigRevisions(); try { LogCommand command = git.log().setMaxCount(pageSize).setSkip(offset); Iterable<RevCommit> revisions = command.call(); for (RevCommit revision : revisions) { GoConfigRevision goConfigRevision = new GoConfigRevision((byte[]) null, revision.getFullMessage()); goConfigRevision.setCommitSHA(revision.name()); goConfigRevisions.add(goConfigRevision); } } catch (Exception e) { // ignore } return goConfigRevisions; }); }
@Test public void testCommitMessageHasProperStructure() { for (RevCommit commit : filterValidCommits(lastCommits)) { final String commitMessage = commit.getFullMessage(); final int error = validateCommitMessage(commitMessage); if (error != 0) { final String commitId = commit.getId().getName(); fail(getInvalidCommitMessageFormattingError(commitId, commitMessage) + error); } } }
@Override public String getCommitMessageFull() throws GitCommitIdExecutionException { return evalCommit.getFullMessage().trim(); }
private void writeMergeInfo(RevCommit commitToPick, List<RevCommit> newParents) throws IOException { repo.writeMergeHeads(newParents.subList(1, newParents.size())); repo.writeMergeCommitMsg(commitToPick.getFullMessage()); }
@SuppressWarnings("nls") private static String composeSquashMessage(boolean isSquash, RevCommit commitToPick, String currSquashMessage, int count) { StringBuilder sb = new StringBuilder(); String ordinal = getOrdinal(count); sb.setLength(0); sb.append("# This is a combination of ").append(count) .append(" commits.\n"); // Add the previous message without header (i.e first line) sb.append(currSquashMessage.substring(currSquashMessage.indexOf("\n") + 1)); sb.append("\n"); if (isSquash) { sb.append("# This is the ").append(count).append(ordinal) .append(" commit message:\n"); sb.append(commitToPick.getFullMessage()); } else { sb.append("# The ").append(count).append(ordinal) .append(" commit message will be skipped:\n# "); sb.append(commitToPick.getFullMessage().replaceAll("([\n\r])", "$1# ")); } return sb.toString(); }
public static ArrayMemory valueOf(RevCommit value) { ArrayMemory memory = valueOf((RevObject) value); memory.refOfIndex("commitTime").assign(value.getCommitTime()); memory.refOfIndex("encoding").assign(value.getEncodingName()); memory.refOfIndex("shortMessage").assign(value.getShortMessage()); memory.refOfIndex("fullMessage").assign(value.getFullMessage()); ArrayMemory parents = new ArrayMemory(); for (RevCommit revCommit : value.getParents()) { parents.add(valueOf((RevObject)revCommit)); } memory.refOfIndex("parents").assign(parents); PersonIdent authorIdent = value.getAuthorIdent(); memory.refOfIndex("author").assign(authorIdent == null ? Memory.NULL : valueOf(authorIdent)); PersonIdent committerIdent = value.getCommitterIdent(); memory.refOfIndex("committer").assign(committerIdent == null ? Memory.NULL : valueOf(committerIdent)); return memory; }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("refs/heads/master"); System.out.println("Found head: " + head); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("\nCommit-Message: " + commit.getFullMessage()); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("refs/heads/master"); System.out.println("Found head: " + head); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("\nCommit-Message: " + commit.getFullMessage()); walk.dispose(); } } } }
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 = ""; } }
private RevCommit doSquashFixup(boolean isSquash, RevCommit commitToPick, RebaseTodoLine nextStep, File messageFixup, File messageSquash) throws IOException, GitAPIException { if (!messageSquash.exists()) { // init squash/fixup sequence ObjectId headId = repo.resolve(Constants.HEAD); RevCommit previousCommit = walk.parseCommit(headId); initializeSquashFixupFile(MESSAGE_SQUASH, previousCommit.getFullMessage()); if (!isSquash) initializeSquashFixupFile(MESSAGE_FIXUP, previousCommit.getFullMessage()); } String currSquashMessage = rebaseState .readFile(MESSAGE_SQUASH); int count = parseSquashFixupSequenceCount(currSquashMessage) + 1; String content = composeSquashMessage(isSquash, commitToPick, currSquashMessage, count); rebaseState.createFile(MESSAGE_SQUASH, content); if (messageFixup.exists()) rebaseState.createFile(MESSAGE_FIXUP, content); return squashIntoPrevious( !messageFixup.exists(), nextStep); }
System.out.println("Found stash: " + rev + ": " + rev.getFullMessage());
System.out.println("Found stash: " + rev + ": " + rev.getFullMessage());
System.out.println("Before revert: " + logMessage.getName() + " - " + logMessage.getFullMessage()); System.out.println("After revert: " + logMessage.getName() + " - " + logMessage.getFullMessage());
System.out.println("Before revert: " + logMessage.getName() + " - " + logMessage.getFullMessage()); System.out.println("After revert: " + logMessage.getName() + " - " + logMessage.getFullMessage());
private RebaseResult stop(RevCommit commitToPick, RebaseResult.Status status) throws IOException { PersonIdent author = commitToPick.getAuthorIdent(); String authorScript = toAuthorScript(author); rebaseState.createFile(AUTHOR_SCRIPT, authorScript); rebaseState.createFile(MESSAGE, commitToPick.getFullMessage()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (DiffFormatter df = new DiffFormatter(bos)) { df.setRepository(repo); df.format(commitToPick.getParent(0), commitToPick); } rebaseState.createFile(PATCH, new String(bos.toByteArray(), UTF_8)); rebaseState.createFile(STOPPED_SHA, repo.newObjectReader() .abbreviate( commitToPick).name()); // Remove cherry pick state file created by CherryPickCommand, it's not // needed for rebase repo.writeCherryPickHead(null); return RebaseResult.result(status, commitToPick); }
return null; // continue rebase process on pick command case REWORD: String oldMessage = commitToPick.getFullMessage(); String newMessage = interactiveHandler .modifyCommitMessage(oldMessage);
/** * Get latest commit by ref name from local .git */ @Override public GitCommit commit(String refName) throws GitException { try (Git git = gitOpen()) { Repository repo = git.getRepository(); Ref head = repo.findRef(refName); if (head == null) { return null; } try (RevWalk walk = new RevWalk(repo)) { RevCommit commit = walk.parseCommit(head.getObjectId()); walk.dispose(); String id = commit.getId().getName(); String message = commit.getFullMessage(); String author = commit.getAuthorIdent().getName(); return new GitCommit(id, message, author); } } catch (IOException e) { throw new GitException("Fail to get commit message", e); } }
if (!noCommit) newHead = new Git(getRepository()).commit() .setMessage(srcCommit.getFullMessage()) .setReflogComment(reflogPrefix + " " //$NON-NLS-1$ + srcCommit.getShortMessage()) .formatWithConflicts(srcCommit.getFullMessage(), merger.getUnmergedPaths());