diff options
author | Ben Rohlfs <brohlfs@google.com> | 2025-02-20 10:53:55 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2025-02-24 22:34:21 +0100 |
commit | 70a3131d6bb7332f50827335babb194677382d7f (patch) | |
tree | 53c083726dd7198e71179c3d477e3ec881716727 | |
parent | 4aae789d285ee94414395f59a408a734a6bc6a36 (diff) | |
download | jgit-70a3131d6bb7332f50827335babb194677382d7f.tar.gz jgit-70a3131d6bb7332f50827335babb194677382d7f.zip |
Update Change-Id insertion logic to insert after footers
Before this change we were inserting the Change-Id at the beginning
of the footer block, but after any Bug or Issue footers.
After this change we are inserting the Change-Id at the end of the
footer block, but before any Signed-off-by footers.
The overall goal is to stay consistent with Gerrit's commit-msg hook.
Change-Id: Id3a73e901ac3c289f79941d12979459c66cb7a13
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java | 10 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java | 7 |
2 files changed, 13 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java index e7f2049bb9..95c2fe3b51 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java @@ -528,7 +528,7 @@ public class ChangeIdUtilTest { } @Test - public void testChangeIdAfterBugOrIssue() throws Exception { + public void testChangeIdAfterOtherFooters() throws Exception { assertEquals("a\n" + // "\n" + // "Bug: 42\n" + // @@ -548,6 +548,14 @@ public class ChangeIdUtilTest { "\n" + // "Issue: 42\n" + // SOB1)); + + assertEquals("a\n" + // + "\n" + // + "Other: none\n" + // + "Change-Id: Ide70e625dea61854206378a377dd12e462ae720f\n",// + call("a\n" + // + "\n" + // + "Other: none\n")); } @Test diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java index 12af374b2e..cd169f9bb7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java @@ -86,8 +86,8 @@ public class ChangeIdUtil { } } - private static final Pattern issuePattern = Pattern - .compile("^(Bug|Issue)[a-zA-Z0-9-]*:.*$"); //$NON-NLS-1$ + private static final Pattern signedOffByPattern = Pattern + .compile("^Signed-off-by:.*$"); //$NON-NLS-1$ private static final Pattern footerPattern = Pattern .compile("(^[a-zA-Z0-9-]+:(?!//).*$)"); //$NON-NLS-1$ @@ -159,7 +159,8 @@ public class ChangeIdUtil { int footerFirstLine = indexOfFirstFooterLine(lines); int insertAfter = footerFirstLine; for (int i = footerFirstLine; i < lines.length; ++i) { - if (issuePattern.matcher(lines[i]).matches()) { + if (footerPattern.matcher(lines[i]).matches() && + !signedOffByPattern.matcher(lines[i]).matches()) { insertAfter = i + 1; continue; } |