From 8b6f9ace1519d79d41ae0179c633cbd21219f7d8 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Thu, 12 Mar 2015 12:14:47 -0700 Subject: TestRepository: Allow setting explicit Change-Id This includes both leaving existing Change-Ids alone (as, for example Gerrit's commit-msg hook does) and programmatically setting a value. Change-Id: Iaaffb0107ae27de24df1f0e95a8d628fb8ea5364 --- .../src/org/eclipse/jgit/junit/TestRepository.java | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'org.eclipse.jgit.junit/src') 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 2afc7163b0..be17bcdc79 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 @@ -875,7 +875,7 @@ public class TestRepository { private PersonIdent author; private PersonIdent committer; - private boolean insertChangeId; + private String changeId; private boolean updateCommitterTime; @@ -1002,7 +1002,14 @@ public class TestRepository { } public CommitBuilder insertChangeId() { - insertChangeId = true; + changeId = ""; + return this; + } + + public CommitBuilder insertChangeId(String c) { + // Validate, but store as a string so we can use "" as a sentinel. + ObjectId.fromString(c); + changeId = c; return this; } @@ -1029,8 +1036,7 @@ public class TestRepository { c.setTreeId(topLevelTree); else c.setTreeId(tree.writeTree(ins)); - if (insertChangeId) - insertChangeId(c); + insertChangeId(c); c.setMessage(message); commitId = ins.insert(c); ins.flush(); @@ -1045,6 +1051,8 @@ public class TestRepository { private void insertChangeId(org.eclipse.jgit.lib.CommitBuilder c) throws IOException { + if (changeId == null) + return; int idx = ChangeIdUtil.indexOfChangeId(message, "\n"); if (idx >= 0) return; @@ -1052,13 +1060,18 @@ public class TestRepository { 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) + + ObjectId cid; + if (changeId.equals("")) + cid = ChangeIdUtil.computeChangeId(c.getTreeId(), firstParentId, + c.getAuthor(), c.getCommitter(), message); + else + cid = ObjectId.fromString(changeId); + message = ChangeIdUtil.insertId(message, cid); + if (cid != 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$ + + cid.getName() + "\n"); //$NON-NLS-1$ } public CommitBuilder child() throws Exception { -- cgit v1.2.3