Store ChangeMessage in body of commit message
Taught ChangeUpdate how to write out the ChangeMessage into the message. Also taught ChangeNotes how to parse the ChangeMessage out of the commit message. Change-Id: I563eabbd848364150fdf8a5c4af5a2e1562aaefe
This commit is contained in:

committed by
Dave Borowitz

parent
b4edfabc03
commit
9d1bd96c3f
@@ -212,6 +212,31 @@ public class ChangeNotesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessageCommitFormatSimple() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeMessage("Just a little code change.\n"
|
||||
+ "How about a new line");
|
||||
update.commit();
|
||||
assertEquals("refs/changes/01/1/meta", update.getRefName());
|
||||
|
||||
RevWalk walk = new RevWalk(repo);
|
||||
try {
|
||||
RevCommit commit = walk.parseCommit(update.getRevision());
|
||||
walk.parseBody(commit);
|
||||
assertEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Just a little code change.\n"
|
||||
+ "How about a new line\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
commit.getFullMessage());
|
||||
} finally {
|
||||
walk.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void approvalTombstoneCommitFormat() throws Exception {
|
||||
Change c = newChange();
|
||||
@@ -608,6 +633,138 @@ public class ChangeNotesTest {
|
||||
assertEquals((short) 2, psas.get(1).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessageOnePatchSet() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.setChangeMessage("Just a little code change.\n");
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<String> changeMessages = notes.getChangeMessages();
|
||||
assertEquals(1, changeMessages.size());
|
||||
assertEquals("Just a little code change.\n", changeMessages.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessagesMultiplePatchSets() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.setChangeMessage("This is the change message for the first PS.");
|
||||
update.commit();
|
||||
PatchSet.Id ps1 = c.currentPatchSetId();
|
||||
|
||||
incrementPatchSet(c);
|
||||
update = newUpdate(c, changeOwner);
|
||||
|
||||
update.setChangeMessage("This is the change message for the second PS.");
|
||||
update.commit();
|
||||
PatchSet.Id ps2 = c.currentPatchSetId();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<String> changeMessages = notes.getChangeMessages();
|
||||
assertEquals(2, changeMessages.size());
|
||||
assertEquals("This is the change message for the second PS.", changeMessages.get(0));
|
||||
assertEquals("This is the change message for the first PS.", changeMessages.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noChangeMessage() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
RevWalk walk = new RevWalk(repo);
|
||||
try {
|
||||
RevCommit commit = walk.parseCommit(update.getRevision());
|
||||
walk.parseBody(commit);
|
||||
assertEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Reviewer: Change Owner <1@gerrit>\n",
|
||||
commit.getFullMessage());
|
||||
} finally {
|
||||
walk.release();
|
||||
}
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<String> changeMessages = notes.getChangeMessages();
|
||||
assertEquals(0, changeMessages.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessageWithTrailingDoubleNewline() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeMessage("Testing trailing double newline\n"
|
||||
+ "\n");
|
||||
update.commit();
|
||||
|
||||
RevWalk walk = new RevWalk(repo);
|
||||
try {
|
||||
RevCommit commit = walk.parseCommit(update.getRevision());
|
||||
walk.parseBody(commit);
|
||||
assertEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Testing trailing double newline\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
commit.getFullMessage());
|
||||
} finally {
|
||||
walk.release();
|
||||
}
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<String> changeMessages = notes.getChangeMessages();
|
||||
assertEquals(1, changeMessages.size());
|
||||
assertEquals("Testing trailing double newline\n"
|
||||
+ "\n", changeMessages.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessageWithMultipleParagraphs() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeMessage("Testing paragraph 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3");
|
||||
update.commit();
|
||||
|
||||
RevWalk walk = new RevWalk(repo);
|
||||
try {
|
||||
RevCommit commit = walk.parseCommit(update.getRevision());
|
||||
walk.parseBody(commit);
|
||||
assertEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
commit.getFullMessage());
|
||||
} finally {
|
||||
walk.release();
|
||||
}
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
List<String> changeMessages = notes.getChangeMessages();
|
||||
assertEquals(1, changeMessages.size());
|
||||
assertEquals("Testing paragraph 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3", changeMessages.get(0));
|
||||
}
|
||||
|
||||
private Change newChange() {
|
||||
Change.Id changeId = new Change.Id(1);
|
||||
Change c = new Change(
|
||||
|
Reference in New Issue
Block a user