diff options
author | Jens Baumgart <jens.baumgart@sap.com> | 2011-03-17 18:15:41 +0100 |
---|---|---|
committer | Mathias Kinzler <mathias.kinzler@sap.com> | 2011-03-17 18:15:41 +0100 |
commit | fd963a9180af73b6a05a5c1a2af6dd7168899170 (patch) | |
tree | 565fc7fd73c17090961db2a666eb8e604f06b1c4 /org.eclipse.jgit.test | |
parent | 6e2e7280d02f4da25207ec7f54cca2cb32d8f075 (diff) | |
download | jgit-fd963a9180af73b6a05a5c1a2af6dd7168899170.tar.gz jgit-fd963a9180af73b6a05a5c1a2af6dd7168899170.zip |
CommitCommand: add option to insert a change id
An option to insert a change id into the commit message was added
to CommitCommand.
This change is a prerequisite for removing GitIndex from EGit.
Change-Id: Iff9e26a8aaf21d8224bfd6ce3c98821c077bcd82
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index d863f45d53..356ba0bfa7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -71,6 +72,7 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.ReflogReader; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.util.FileUtils; +import org.eclipse.jgit.util.RawParseUtils; import org.junit.Test; /** @@ -1159,6 +1161,65 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { + "[d6/f12.txt, mode:100644, content:c12]", indexState(CONTENT)); } + @Test + public void testInsertChangeId() throws NoHeadException, + NoMessageException, + UnmergedPathException, ConcurrentRefUpdateException, + JGitInternalException, WrongRepositoryStateException { + Git git = new Git(db); + String messageHeader = "Some header line\n\nSome detail explanation\n"; + String changeIdTemplate = "\nChange-Id: I" + + ObjectId.zeroId().getName() + "\n"; + String messageFooter = "Some foooter lines\nAnother footer line\n"; + RevCommit commit = git.commit().setMessage( + messageHeader + messageFooter) + .setInsertChangeId(true).call(); + // we should find a real change id (at the end of the file) + byte[] chars = commit.getFullMessage().getBytes(); + int lastLineBegin = RawParseUtils.prevLF(chars, chars.length - 2); + String lastLine = RawParseUtils.decode(chars, lastLineBegin + 1, + chars.length); + assertTrue(lastLine.contains("Change-Id:")); + assertFalse(lastLine.contains( + "Change-Id: I" + ObjectId.zeroId().getName())); + + commit = git.commit().setMessage( + messageHeader + changeIdTemplate + messageFooter) + .setInsertChangeId(true).call(); + // we should find a real change id (in the line as dictated by the + // template) + chars = commit.getFullMessage().getBytes(); + int lineStart = 0; + int lineEnd = 0; + for (int i = 0; i < 4; i++) { + lineStart = RawParseUtils.nextLF(chars, lineStart); + } + lineEnd = RawParseUtils.nextLF(chars, lineStart); + + String line = RawParseUtils.decode(chars, lineStart, lineEnd); + + assertTrue(line.contains("Change-Id:")); + assertFalse(line.contains( + "Change-Id: I" + ObjectId.zeroId().getName())); + + commit = git.commit().setMessage( + messageHeader + changeIdTemplate + messageFooter) + .setInsertChangeId(false).call(); + // we should find the untouched template + chars = commit.getFullMessage().getBytes(); + lineStart = 0; + lineEnd = 0; + for (int i = 0; i < 4; i++) { + lineStart = RawParseUtils.nextLF(chars, lineStart); + } + lineEnd = RawParseUtils.nextLF(chars, lineStart); + + line = RawParseUtils.decode(chars, lineStart, lineEnd); + + assertTrue(commit.getFullMessage().contains( + "Change-Id: I" + ObjectId.zeroId().getName())); + } + @SuppressWarnings("unused") private File prepare_f1_1(final Git git) throws IOException { return writeTrashFile(F1, "c1"); |