diff options
author | Dave Borowitz <dborowitz@google.com> | 2015-03-12 12:14:47 -0700 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2015-03-12 12:47:18 -0700 |
commit | 8b6f9ace1519d79d41ae0179c633cbd21219f7d8 (patch) | |
tree | 93421cece918461a5c8c40bb0ed334de04d505f7 /org.eclipse.jgit.junit/src | |
parent | 6ed07f5cb5f5c296c8abca8ac06a6f923b96119c (diff) | |
download | jgit-8b6f9ace1519d79d41ae0179c633cbd21219f7d8.tar.gz jgit-8b6f9ace1519d79d41ae0179c633cbd21219f7d8.zip |
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
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java | 31 |
1 files changed, 22 insertions, 9 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 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<R extends Repository> { private PersonIdent author; private PersonIdent committer; - private boolean insertChangeId; + private String changeId; private boolean updateCommitterTime; @@ -1002,7 +1002,14 @@ public class TestRepository<R extends Repository> { } 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<R extends Repository> { 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<R extends Repository> { 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<R extends Repository> { 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 { |