From 9e4b4fc41c4220779a96afeca17c669f36945721 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 29 Feb 2012 10:16:56 -0800 Subject: [PATCH] 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 --- .../jgit/api/StashCreateCommandTest.java | 23 +++++++++++++++++++ .../eclipse/jgit/api/StashCreateCommand.java | 8 +++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java index b91a50a94..16fadef15 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java +++ b/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()); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java index e26ae879f..d5fffb9cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java @@ -180,10 +180,13 @@ public class StashCreateCommand extends GitCommand { 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 { commitId = inserter.insert(builder); inserter.flush(); - updateStashRef(commitId); + updateStashRef(commitId, builder.getAuthor(), + builder.getMessage()); } finally { inserter.release(); cache.unlock();