private static List<RevCommit> filterValidCommits(List<RevCommit> revCommits) { final List<RevCommit> filteredCommits = new LinkedList<>(); for (RevCommit commit : revCommits) { final String commitAuthor = commit.getAuthorIdent().getName(); if (!USERS_EXCLUDED_FROM_VALIDATION.contains(commitAuthor)) { filteredCommits.add(commit); } } return filteredCommits; }
private static List<RevCommit> getCommitsByLastCommitAuthor( Iterator<RevCommit> previousCommitsIterator) { final List<RevCommit> commits = new LinkedList<>(); if (previousCommitsIterator.hasNext()) { final RevCommit lastCommit = previousCommitsIterator.next(); final String lastCommitAuthor = lastCommit.getAuthorIdent().getName(); commits.add(lastCommit); boolean wasLastCheckedCommitAuthorSameAsLastCommit = true; while (wasLastCheckedCommitAuthorSameAsLastCommit && previousCommitsIterator.hasNext()) { final RevCommit currentCommit = previousCommitsIterator.next(); final String currentCommitAuthor = currentCommit.getAuthorIdent().getName(); if (currentCommitAuthor.equals(lastCommitAuthor)) { commits.add(currentCommit); } else { wasLastCheckedCommitAuthorSameAsLastCommit = false; } } } return commits; }
String getMergedConfig(String branchName, RevCommit newCommit) throws GitAPIException, IOException { MergeResult result = null; try { checkout(branchName); result = git.merge().include(newCommit).call(); } catch (GitAPIException e) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw e; } if (!result.getMergeStatus().isSuccessful()) { LOGGER.info("[CONFIG_MERGE] Merging commit {} by user {} to branch {} at revision {} failed as config file has changed", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); throw new ConfigFileHasChangedException(); } LOGGER.info("[CONFIG_MERGE] Successfully merged commit {} by user {} to branch {}. Merge commit revision is {}", newCommit.getId().getName(), newCommit.getAuthorIdent().getName(), branchName, getCurrentRevCommit().getId().getName()); return FileUtils.readFileToString(new File(workingDir, CRUISE_CONFIG_XML), UTF_8); }
PersonIdent getAuthor() { return sourceCommit.getAuthorIdent(); }
@Override public String getCommitAuthorName() throws GitCommitIdExecutionException { return evalCommit.getAuthorIdent().getName(); }
@Override public String getCommitAuthorEmail() throws GitCommitIdExecutionException { return evalCommit.getAuthorIdent().getEmailAddress(); }
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; }
/** * 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(); }
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); }
private boolean autoStashApply() throws IOException, GitAPIException { boolean conflicts = false; if (rebaseState.getFile(AUTOSTASH).exists()) { String stash = rebaseState.readFile(AUTOSTASH); try (Git git = Git.wrap(repo)) { git.stashApply().setStashRef(stash) .ignoreRepositoryState(true).setStrategy(strategy) .call(); } catch (StashApplyFailureException e) { conflicts = true; try (RevWalk rw = new RevWalk(repo)) { ObjectId stashId = repo.resolve(stash); RevCommit commit = rw.parseCommit(stashId); updateStashRef(commit, commit.getAuthorIdent(), commit.getShortMessage()); } } } return conflicts; }
/** * 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); } }
public int compare(RevCommit o1, RevCommit o2) { return o1.getAuthorIdent().getWhen() .compareTo(o2.getAuthorIdent().getWhen()); } });
private void prepareAuthor() { if(author == null) { if(!amend) author = committer; else author = status.commit().getAuthorIdent(); } }
private PersonIdent committerOf(final RevCommit c) { if (lastCommit != c) { lastCommit = c; lastAuthor = c.getAuthorIdent(); lastCommitter = c.getCommitterIdent(); } return lastCommitter; }
public Date getDate() { PersonIdent person = commit.getAuthorIdent(); if( person == null) person = commit.getCommitterIdent(); return person != null ? person.getWhen() : new Date(0); }
commit.setAuthor(commitToPick.getAuthorIdent()); commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$ + commitToPick.getShortMessage()); if (mergeResult.getMergeStatus().isSuccessful()) { CommitCommand commit = git.commit(); commit.setAuthor(commitToPick.getAuthorIdent()); commit.setMessage(commitToPick.getFullMessage()); commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
parents.add(p.getId()); if (author == null) author = previousCommit.getAuthorIdent(); } else { parents.add(0, headId);
.setReflogComment(reflogPrefix + " " //$NON-NLS-1$ + srcCommit.getShortMessage()) .setAuthor(srcCommit.getAuthorIdent()) .setNoVerify(true).call(); cherryPickedRefs.add(src);
public Value(RevCommit commit) { this.id = commit.copy(); this.author = commit.getAuthorIdent(); this.commitDate = commit.getCommitterIdent().getWhen(); this.summary = StringUtils.substringBefore(commit.getFullMessage(), "\n").trim(); }
public CommitInfo createCommitInfo(RevCommit entry) { final Date date = GitFacade.getCommitDate(entry); String author = entry.getAuthorIdent().getName(); boolean merge = entry.getParentCount() > 1; String shortMessage = entry.getShortMessage(); String trimmedMessage = Strings.trimString(shortMessage, 78); String name = entry.getName(); String commitHashText = getShortCommitHash(name); return new CommitInfo(commitHashText, name, author, date, merge, trimmedMessage, shortMessage); }