commit-msg: Fix jumbling of URL at end of message

If a commit message has a URL (e.g. http://) at the start of the
last line of the message the commit-msg hook was confusing it as
a footer line, and inserted the Change-Id before it.

Test for URLs at the start of the line and don't consider them to
be message footers.

Bug: issue 531
Change-Id: Iba4902502b4f154f456b6b3511b6f3b6cc0b3129
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-04-12 17:23:34 -07:00
parent f95bea43b9
commit e21f41e664
2 changed files with 39 additions and 1 deletions

View File

@@ -59,7 +59,10 @@ add_ChangeId() {
for($line = @message - 1; $line >= 0; $line--) {
$_ = $message[$line];
($haveFooter++, next) if /^[a-zA-Z0-9-]+:/;
if (/^[a-zA-Z0-9-]+:/ && !m,^[a-z0-9-]+://,) {
$haveFooter++;
next;
}
next if /^[ []/;
$startFooter = $line if ($haveFooter && /^\r?$/);
last;

View File

@@ -335,6 +335,41 @@ public class CommitMsgHookTest extends HookTestCase {
"index 0000000..c78b7f0\n"));
}
public void testWithEndingURL() throws Exception {
assertEquals("a\n" + //
"\n" + //
"http://example.com/ fixes this\n" + //
"\n" + //
"Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n", //
call("a\n" + //
"\n" + //
"http://example.com/ fixes this\n"));
assertEquals("a\n" + //
"\n" + //
"https://example.com/ fixes this\n" + //
"\n" + //
"Change-Id: I62b9039e2fc0dce274af55e8f99312a8a80a805d\n", //
call("a\n" + //
"\n" + //
"https://example.com/ fixes this\n"));
assertEquals("a\n" + //
"\n" + //
"ftp://example.com/ fixes this\n" + //
"\n" + //
"Change-Id: I71b05dc1f6b9a5540a53a693e64d58b65a8910e8\n", //
call("a\n" + //
"\n" + //
"ftp://example.com/ fixes this\n"));
assertEquals("a\n" + //
"\n" + //
"git://example.com/ fixes this\n" + //
"\n" + //
"Change-Id: Id34e942baa68d790633737d815ddf11bac9183e5\n", //
call("a\n" + //
"\n" + //
"git://example.com/ fixes this\n"));
}
private void hookDoesNotModify(final String in) throws Exception {
assertEquals(in, call(in));
}