* The message will be formatted with the current branch, abbreviated commit * id, and short commit message when used. * * @param message * the stash message * @return {@code this} */ public StashCreateCommand setIndexMessage(String message) { indexMessage = message; return this; } /** * Set the message used when committing working directory changes *
* The message will be formatted with the current branch, abbreviated commit * id, and short commit message when used. * * @param message * the working directory message * @return {@code this} */ public StashCreateCommand setWorkingDirectoryMessage(String message) { workingDirectoryMessage = message; return this; } /** * Set the person to use as the author and committer in the commits made * * @param person * the {@link org.eclipse.jgit.lib.PersonIdent} of the person who * creates the stash. * @return {@code this} */ public StashCreateCommand setPerson(PersonIdent person) { this.person = person; return this; } /** * Set the reference to update with the stashed commit id If null, no * reference is updated *
* This value defaults to {@link org.eclipse.jgit.lib.Constants#R_STASH} * * @param ref * the name of the {@code Ref} to update * @return {@code this} */ public StashCreateCommand setRef(String ref) { this.ref = ref; return this; } /** * Whether to include untracked files in the stash. * * @param includeUntracked * whether to include untracked files in the stash * @return {@code this} * @since 3.4 */ public StashCreateCommand setIncludeUntracked(boolean includeUntracked) { this.includeUntracked = includeUntracked; return this; } private RevCommit parseCommit(final ObjectReader reader, final ObjectId headId) throws IOException { try (RevWalk walk = new RevWalk(reader)) { return walk.parseCommit(headId); } } private CommitBuilder createBuilder() { CommitBuilder builder = new CommitBuilder(); PersonIdent author = person; if (author == null) author = new PersonIdent(repo); builder.setAuthor(author); builder.setCommitter(author); return builder; } private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) throws IOException { if (ref == null) return; Ref currentRef = repo.findRef(ref); RefUpdate refUpdate = repo.updateRef(ref); refUpdate.setNewObjectId(commitId); refUpdate.setRefLogIdent(refLogIdent); refUpdate.setRefLogMessage(refLogMessage, false); refUpdate.setForceRefLog(true); if (currentRef != null) refUpdate.setExpectedOldObjectId(currentRef.getObjectId()); else refUpdate.setExpectedOldObjectId(ObjectId.zeroId()); refUpdate.forceUpdate(); } private Ref getHead() throws GitAPIException { try { Ref head = repo.exactRef(Constants.HEAD); if (head == null || head.getObjectId() == null) throw new NoHeadException(JGitText.get().headRequiredToStash); return head; } catch (IOException e) { throw new JGitInternalException(JGitText.get().stashFailed, e); } } /** * {@inheritDoc} *
* Stash the contents on the working directory and index in separate commits
* and reset to the current HEAD commit.
*/
@Override
public RevCommit call() throws GitAPIException {
checkCallable();
List