summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2015-03-11 11:33:27 -0700
committerDave Borowitz <dborowitz@google.com>2015-03-12 10:47:12 -0700
commitc1d40caa320ff5b22beab97702acd6e39bb02c83 (patch)
tree7f0ad6a40125d7b3465f25df2742c33924f0309e /org.eclipse.jgit.junit
parentc3b8615ce895301f12e6d90a0e273512f145b2e5 (diff)
downloadjgit-c1d40caa320ff5b22beab97702acd6e39bb02c83.tar.gz
jgit-c1d40caa320ff5b22beab97702acd6e39bb02c83.zip
TestRepository: Optionally insert Change-Id in commit message
Copied the implementation from CommitCommand. Change-Id: Iade0e2d70bde70cfa830fe23bcc41959b011a14a
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java26
1 files changed, 25 insertions, 1 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index 687076f103..8549118ab2 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -96,6 +96,7 @@ import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.eclipse.jgit.util.ChangeIdUtil;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
@@ -749,6 +750,8 @@ public class TestRepository<R extends Repository> {
private PersonIdent author;
private PersonIdent committer;
+ private boolean insertChangeId;
+
CommitBuilder() {
branch = null;
}
@@ -856,6 +859,11 @@ public class TestRepository<R extends Repository> {
return this;
}
+ public CommitBuilder insertChangeId() {
+ insertChangeId = true;
+ return this;
+ }
+
public RevCommit create() throws Exception {
if (self == null) {
TestRepository.this.tick(tick);
@@ -869,7 +877,6 @@ public class TestRepository<R extends Repository> {
c.setAuthor(author);
if (committer != null)
c.setCommitter(committer);
- c.setMessage(message);
ObjectId commitId;
try (ObjectInserter ins = inserter) {
@@ -877,6 +884,9 @@ public class TestRepository<R extends Repository> {
c.setTreeId(topLevelTree);
else
c.setTreeId(tree.writeTree(ins));
+ if (insertChangeId)
+ insertChangeId(c);
+ c.setMessage(message);
commitId = ins.insert(c);
ins.flush();
}
@@ -888,6 +898,20 @@ public class TestRepository<R extends Repository> {
return self;
}
+ private void insertChangeId(org.eclipse.jgit.lib.CommitBuilder c)
+ throws IOException {
+ ObjectId firstParentId = null;
+ if (!parents.isEmpty())
+ firstParentId = parents.get(0);
+ ObjectId changeId = ChangeIdUtil.computeChangeId(c.getTreeId(),
+ firstParentId, c.getAuthor(), c.getCommitter(), message);
+ message = ChangeIdUtil.insertId(message, changeId);
+ if (changeId != null)
+ message = message.replaceAll("\nChange-Id: I" //$NON-NLS-1$
+ + ObjectId.zeroId().getName() + "\n", "\nChange-Id: I" //$NON-NLS-1$ //$NON-NLS-2$
+ + changeId.getName() + "\n"); //$NON-NLS-1$
+ }
+
public CommitBuilder child() throws Exception {
return new CommitBuilder(this);
}