Browse Source

Set person and message on stash ref update

This will be the message and person used for the commit
of stashed working directory changes.

Bug: 372884
Change-Id: I2501b080f6b94e826cf7dba3fd526ae5c1d969d1
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
stable-2.0
Kevin Sawicki 13 years ago committed by Chris Aniszczyk
parent
commit
9e4b4fc41c
  1. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
  2. 8
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java

@ -54,10 +54,14 @@ import java.util.List;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.ReflogEntry;
import org.eclipse.jgit.storage.file.ReflogReader;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.FileUtils;
@ -394,4 +398,23 @@ public class StashCreateCommandTest extends RepositoryTestCase {
assertEquals(DiffEntry.ChangeType.ADD, diffs.get(1).getChangeType());
assertEquals("file2.txt", diffs.get(1).getNewPath());
}
@Test
public void refLogIncludesCommitMessage() throws Exception {
PersonIdent who = new PersonIdent("user", "user@email.com");
deleteTrashFile("file.txt");
RevCommit stashed = git.stashCreate().setPerson(who).call();
assertNotNull(stashed);
assertEquals("content", read(committedFile));
validateStashedCommit(stashed);
ReflogReader reader = new ReflogReader(git.getRepository(),
Constants.R_STASH);
ReflogEntry entry = reader.getLastEntry();
assertNotNull(entry);
assertEquals(ObjectId.zeroId(), entry.getOldId());
assertEquals(stashed, entry.getNewId());
assertEquals(who, entry.getWho());
assertEquals(stashed.getFullMessage(), entry.getComment());
}
}

8
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java

@ -180,10 +180,13 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
return builder;
}
private void updateStashRef(ObjectId commitId) throws IOException {
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent,
String refLogMessage) throws IOException {
Ref currentRef = repo.getRef(ref);
RefUpdate refUpdate = repo.updateRef(ref);
refUpdate.setNewObjectId(commitId);
refUpdate.setRefLogIdent(refLogIdent);
refUpdate.setRefLogMessage(refLogMessage, false);
if (currentRef != null)
refUpdate.setExpectedOldObjectId(currentRef.getObjectId());
else
@ -300,7 +303,8 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
commitId = inserter.insert(builder);
inserter.flush();
updateStashRef(commitId);
updateStashRef(commitId, builder.getAuthor(),
builder.getMessage());
} finally {
inserter.release();
cache.unlock();

Loading…
Cancel
Save