You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChangeIdUtilTest.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * Copyright (C) 2010, Robin Rosenberg
  3. * Copyright (C) 2009, Google, Inc.
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.util;
  45. import static org.junit.Assert.assertEquals;
  46. import java.io.IOException;
  47. import java.util.concurrent.TimeUnit;
  48. import org.eclipse.jgit.junit.MockSystemReader;
  49. import org.eclipse.jgit.lib.ObjectId;
  50. import org.eclipse.jgit.lib.PersonIdent;
  51. import org.junit.Test;
  52. /**
  53. * Portions of this test is from CommitMsgHookTest in the Android project Gerrit
  54. */
  55. public class ChangeIdUtilTest {
  56. private final String SOB1 = "Signed-off-by: J Author <ja@example.com>\n";
  57. private final String SOB2 = "Signed-off-by: J Committer <jc@example.com>\n";
  58. final PersonIdent p = RawParseUtils.parsePersonIdent(
  59. "A U Thor <author@example.com> 1142878501 -0500");
  60. final PersonIdent q = RawParseUtils.parsePersonIdent(
  61. "W Riter <writer@example.com> 1142878502 -0500");
  62. ObjectId treeId = ObjectId
  63. .fromString("f51de923607cd51cf872b928a6b523ba823f7f35");
  64. ObjectId treeId1 = ObjectId
  65. .fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904");
  66. final ObjectId treeId2 = ObjectId
  67. .fromString("617601c79811cbbae338512798318b4e5b70c9ac");
  68. ObjectId parentId = ObjectId
  69. .fromString("91fea719aaf9447feb9580477eb3dd08b62b5eca");
  70. ObjectId parentId1 = null;
  71. final ObjectId parentId2 = ObjectId
  72. .fromString("485c91e0600b165c301c278bfbae3e492413980c");
  73. MockSystemReader mockSystemReader = new MockSystemReader();
  74. final long when = mockSystemReader.getCurrentTime();
  75. final int tz = new MockSystemReader().getTimezone(when);
  76. PersonIdent author = new PersonIdent("J. Author", "ja@example.com");
  77. {
  78. author = new PersonIdent(author, when, tz);
  79. }
  80. PersonIdent committer = new PersonIdent("J. Committer", "jc@example.com");
  81. {
  82. committer = new PersonIdent(committer, when, tz);
  83. }
  84. @Test
  85. public void testClean() {
  86. assertEquals("hej", ChangeIdUtil.clean("hej\n\n"));
  87. assertEquals("hej\n\nsan", ChangeIdUtil.clean("hej\n\nsan\n\n"));
  88. assertEquals("hej\nsan", ChangeIdUtil.clean("hej\n#men\nsan\n\n#men"));
  89. assertEquals("hej\nsan", ChangeIdUtil.clean("hej\nsan\n\n#men"));
  90. assertEquals("hej\nsan", ChangeIdUtil.clean("#no\nhej\nsan\n\n#men"));
  91. assertEquals("hej\nsan", ChangeIdUtil
  92. .clean("#no\nhej\nsan\nSigned-off-by: me \n#men"));
  93. }
  94. @Test
  95. public void testId() throws IOException {
  96. String msg = "A\nMessage\n";
  97. ObjectId id = ChangeIdUtil.computeChangeId(treeId, parentId, p, q, msg);
  98. assertEquals("73f3751208ac92cbb76f9a26ac4a0d9d472e381b", ObjectId
  99. .toString(id));
  100. }
  101. @Test
  102. public void testHasChangeid() throws Exception {
  103. assertEquals(
  104. "has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n",
  105. call("has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n"));
  106. }
  107. @Test
  108. public void testHasChangeidWithReplacement() throws Exception {
  109. assertEquals(
  110. "has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I988d2d7a6f2c0578fccabd4ebd3cec0768bc7f9f\nAnd then some\n",
  111. call("has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n",
  112. true));
  113. }
  114. @Test
  115. public void testOneliner() throws Exception {
  116. assertEquals(
  117. "oneliner\n\nChange-Id: I3a98091ce4470de88d52ae317fcd297e2339f063\n",
  118. call("oneliner\n"));
  119. }
  120. @Test
  121. public void testOnelinerFollowedByBlank() throws Exception {
  122. assertEquals(
  123. "oneliner followed by blank\n\nChange-Id: I3a12c21ef342a18498f95c62efbc186cd782b743\n",
  124. call("oneliner followed by blank\n"));
  125. }
  126. @Test
  127. public void testATwoLines() throws Exception {
  128. assertEquals(
  129. "a two lines\nwith text withour break after subject line\n\nChange-Id: I549a0fed3d69b7876c54b4f5a35637135fd43fac\n",
  130. call("a two lines\nwith text withour break after subject line\n"));
  131. }
  132. @Test
  133. public void testRegularCommit() throws Exception {
  134. assertEquals(
  135. "regular commit\n\nwith header and body\n\nChange-Id: I62d8749d3c3a888c11e3fadc3924220a19389766\n",
  136. call("regular commit\n\nwith header and body\n"));
  137. }
  138. @Test
  139. public void testRegularCommitWithSob_ButNoBody() throws Exception {
  140. assertEquals(
  141. "regular commit with sob, but no body\n\nChange-Id: I0f0b4307e9944ecbd5a9f6b9489e25cfaede43c4\nSigned-off-by: me@you.too\n",
  142. call("regular commit with sob, but no body\n\nSigned-off-by: me@you.too\n"));
  143. }
  144. @Test
  145. public void testACommitWithBug_SubButNoBody() throws Exception {
  146. assertEquals(
  147. "a commit with bug, sub but no body\n\nBug: 33\nChange-Id: I337e264868613dab6d1e11a34f394db369487412\nSigned-off-by: me@you.too\n",
  148. call("a commit with bug, sub but no body\n\nBug: 33\nSigned-off-by: me@you.too\n"));
  149. }
  150. @Test
  151. public void testACommitWithSubject_NoBodySobAndBug() throws Exception {
  152. assertEquals(
  153. "a commit with subject, no body sob and bug\n\nChange-Id: Ib3616d4bf77707a3215a6cb0602c004ee119a445\nSigned-off-by: me@you.too\nBug: 33\n",
  154. call("a commit with subject, no body sob and bug\n\nSigned-off-by: me@you.too\nBug: 33\n"));
  155. }
  156. @Test
  157. public void testACommitWithSubjectBug_NonFooterLineAndSob()
  158. throws Exception {
  159. assertEquals(
  160. "a commit with subject bug, non-footer line and sob\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\n\nChange-Id: Ia8500eab2304e6e5eac6ae488ff44d5d850d118a\n",
  161. call("a commit with subject bug, non-footer line and sob\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\n"));
  162. }
  163. @Test
  164. public void testACommitWithSubject_NonFooterAndBugAndSob() throws Exception {
  165. assertEquals(
  166. "a commit with subject, non-footer and bug and sob\n\nmore text (two empty lines after bug)\nBug: 33\n\n\nChange-Id: Idac75ccbad2ab6727b8612e344df5190d87891dd\nSigned-off-by: me@you.too\n",
  167. call("a commit with subject, non-footer and bug and sob\n\nmore text (two empty lines after bug)\nBug: 33\n\n\nSigned-off-by: me@you.too\n"));
  168. }
  169. @Test
  170. public void testACommitWithSubjectBodyBugBrackersAndSob() throws Exception {
  171. assertEquals(
  172. "a commit with subject body, bug. brackers and sob\n\nText\n\nBug: 33\nChange-Id: I90ecb589bef766302532c3e00915e10114b00f62\n[bracket]\nSigned-off-by: me@you.too\n",
  173. call("a commit with subject body, bug. brackers and sob\n\nText\n\nBug: 33\n[bracket]\nSigned-off-by: me@you.too\n\n"));
  174. }
  175. @Test
  176. public void testACommitWithSubjectBodyBugLineWithASpaceAndSob()
  177. throws Exception {
  178. assertEquals(
  179. "a commit with subject body, bug. line with a space and sob\n\nText\n\nBug: 33\nChange-Id: I864e2218bdee033c8ce9a7f923af9e0d5dc16863\n \nSigned-off-by: me@you.too\n",
  180. call("a commit with subject body, bug. line with a space and sob\n\nText\n\nBug: 33\n \nSigned-off-by: me@you.too\n\n"));
  181. }
  182. @Test
  183. public void testACommitWithSubjectBodyBugEmptyLineAndSob() throws Exception {
  184. assertEquals(
  185. "a commit with subject body, bug. empty line and sob\n\nText\n\nBug: 33\nChange-Id: I33f119f533313883e6ada3df600c4f0d4db23a76\n \nSigned-off-by: me@you.too\n",
  186. call("a commit with subject body, bug. empty line and sob\n\nText\n\nBug: 33\n \nSigned-off-by: me@you.too\n\n"));
  187. }
  188. @Test
  189. public void testEmptyMessages() throws Exception {
  190. // Empty input must not produce a change id.
  191. hookDoesNotModify("");
  192. hookDoesNotModify(" ");
  193. hookDoesNotModify("\n");
  194. hookDoesNotModify("\n\n");
  195. hookDoesNotModify(" \n ");
  196. hookDoesNotModify("#");
  197. hookDoesNotModify("#\n");
  198. hookDoesNotModify("# on branch master\n# Untracked files:\n");
  199. hookDoesNotModify("\n# on branch master\n# Untracked files:\n");
  200. hookDoesNotModify("\n\n# on branch master\n# Untracked files:\n");
  201. hookDoesNotModify("\n# on branch master\ndiff --git a/src b/src\n"
  202. + "new file mode 100644\nindex 0000000..c78b7f0\n");
  203. }
  204. @Test
  205. public void testChangeIdAlreadySet() throws Exception {
  206. // If a Change-Id is already present in the footer, the hook must
  207. // not modify the message but instead must leave the identity alone.
  208. //
  209. hookDoesNotModify("a\n" + //
  210. "\n" + //
  211. "Change-Id: Iaeac9b4149291060228ef0154db2985a31111335\n");
  212. hookDoesNotModify("fix: this thing\n" + //
  213. "\n" + //
  214. "Change-Id: I388bdaf52ed05b55e62a22d0a20d2c1ae0d33e7e\n");
  215. hookDoesNotModify("fix-a-widget: this thing\n" + //
  216. "\n" + //
  217. "Change-Id: Id3bc5359d768a6400450283e12bdfb6cd135ea4b\n");
  218. hookDoesNotModify("FIX: this thing\n" + //
  219. "\n" + //
  220. "Change-Id: I1b55098b5a2cce0b3f3da783dda50d5f79f873fa\n");
  221. hookDoesNotModify("Fix-A-Widget: this thing\n" + //
  222. "\n" + //
  223. "Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n");
  224. }
  225. @Test
  226. public void testChangeIdAlreadySetWithReplacement() throws Exception {
  227. // If a Change-Id is already present in the footer, the hook
  228. // replaces the Change-Id with the new value..
  229. //
  230. assertEquals("a\n" + //
  231. "\n" + //
  232. "Change-Id: Ifa324efa85bfb3c8696a46a0f67fa70c35be5f5f\n",
  233. call("a\n" + //
  234. "\n" + //
  235. "Change-Id: Iaeac9b4149291060228ef0154db2985a31111335\n",
  236. true));
  237. assertEquals("fix: this thing\n" + //
  238. "\n" + //
  239. "Change-Id: Ib63e4990a06412a3f24bd93bb160e98ac1bd412b\n",
  240. call("fix: this thing\n" + //
  241. "\n" + //
  242. "Change-Id: I388bdaf52ed05b55e62a22d0a20d2c1ae0d33e7e\n",
  243. true));
  244. assertEquals("fix-a-widget: this thing\n" + //
  245. "\n" + //
  246. "Change-Id: If0444e4d0cabcf41b3d3b46b7e9a7a64a82117af\n",
  247. call("fix-a-widget: this thing\n" + //
  248. "\n" + //
  249. "Change-Id: Id3bc5359d768a6400450283e12bdfb6cd135ea4b\n",
  250. true));
  251. assertEquals("FIX: this thing\n" + //
  252. "\n" + //
  253. "Change-Id: Iba5a3b2d5e5df46448f6daf362b6bfa775c6491d\n",
  254. call("FIX: this thing\n" + //
  255. "\n" + //
  256. "Change-Id: I1b55098b5a2cce0b3f3da783dda50d5f79f873fa\n",
  257. true));
  258. assertEquals("Fix-A-Widget: this thing\n" + //
  259. "\n" + //
  260. "Change-Id: I2573d47c62c42429fbe424d70cfba931f8f87848\n",
  261. call("Fix-A-Widget: this thing\n" + //
  262. "\n" + //
  263. "Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n",
  264. true));
  265. }
  266. @Test
  267. public void testTimeAltersId() throws Exception {
  268. assertEquals("a\n" + //
  269. "\n" + //
  270. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  271. call("a\n"));
  272. tick();
  273. assertEquals("a\n" + //
  274. "\n" + //
  275. "Change-Id: I3251906b99dda598a58a6346d8126237ee1ea800\n",//
  276. call("a\n"));
  277. tick();
  278. assertEquals("a\n" + //
  279. "\n" + //
  280. "Change-Id: I69adf9208d828f41a3d7e41afbca63aff37c0c5c\n",//
  281. call("a\n"));
  282. }
  283. /** Increment the {@link #author} and {@link #committer} times. */
  284. protected void tick() {
  285. final long delta = TimeUnit.MILLISECONDS.convert(5 * 60,
  286. TimeUnit.SECONDS);
  287. final long now = author.getWhen().getTime() + delta;
  288. author = new PersonIdent(author, now, tz);
  289. committer = new PersonIdent(committer, now, tz);
  290. }
  291. @Test
  292. public void testFirstParentAltersId() throws Exception {
  293. assertEquals("a\n" + //
  294. "\n" + //
  295. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  296. call("a\n"));
  297. parentId1 = parentId2;
  298. assertEquals("a\n" + //
  299. "\n" + //
  300. "Change-Id: I51e86482bde7f92028541aaf724d3a3f996e7ea2\n",//
  301. call("a\n"));
  302. }
  303. @Test
  304. public void testDirCacheAltersId() throws Exception {
  305. assertEquals("a\n" + //
  306. "\n" + //
  307. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  308. call("a\n"));
  309. treeId1 = treeId2;
  310. assertEquals("a\n" + //
  311. "\n" + //
  312. "Change-Id: If56597ea9759f23b070677ea6f064c60c38da631\n",//
  313. call("a\n"));
  314. }
  315. @Test
  316. public void testSingleLineMessages() throws Exception {
  317. assertEquals("a\n" + //
  318. "\n" + //
  319. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  320. call("a\n"));
  321. assertEquals("fix: this thing\n" + //
  322. "\n" + //
  323. "Change-Id: I0f13d0e6c739ca3ae399a05a93792e80feb97f37\n",//
  324. call("fix: this thing\n"));
  325. assertEquals("fix-a-widget: this thing\n" + //
  326. "\n" + //
  327. "Change-Id: I1a1a0c751e4273d532e4046a501a612b9b8a775e\n",//
  328. call("fix-a-widget: this thing\n"));
  329. assertEquals("FIX: this thing\n" + //
  330. "\n" + //
  331. "Change-Id: If816d944c57d3893b60cf10c65931fead1290d97\n",//
  332. call("FIX: this thing\n"));
  333. assertEquals("Fix-A-Widget: this thing\n" + //
  334. "\n" + //
  335. "Change-Id: I3e18d00cbda2ba1f73aeb63ed8c7d57d7fd16c76\n",//
  336. call("Fix-A-Widget: this thing\n"));
  337. }
  338. @Test
  339. public void testMultiLineMessagesWithoutFooter() throws Exception {
  340. assertEquals("a\n" + //
  341. "\n" + //
  342. "b\n" + //
  343. "\n" + //
  344. "Change-Id: Id0b4f42d3d6fc1569595c9b97cb665e738486f5d\n",//
  345. call("a\n" + "\n" + "b\n"));
  346. assertEquals("a\n" + //
  347. "\n" + //
  348. "b\nc\nd\ne\n" + //
  349. "\n" + //
  350. "Change-Id: I7d237b20058a0f46cc3f5fabc4a0476877289d75\n",//
  351. call("a\n" + "\n" + "b\nc\nd\ne\n"));
  352. assertEquals("a\n" + //
  353. "\n" + //
  354. "b\nc\nd\ne\n" + //
  355. "\n" + //
  356. "f\ng\nh\n" + //
  357. "\n" + //
  358. "Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n",//
  359. call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n"));
  360. }
  361. @Test
  362. public void testSingleLineMessagesWithSignedOffBy() throws Exception {
  363. assertEquals("a\n" + //
  364. "\n" + //
  365. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
  366. SOB1,//
  367. call("a\n" + "\n" + SOB1));
  368. assertEquals("a\n" + //
  369. "\n" + //
  370. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
  371. SOB1 + //
  372. SOB2,//
  373. call("a\n" + "\n" + SOB1 + SOB2));
  374. }
  375. @Test
  376. public void testMultiLineMessagesWithSignedOffBy() throws Exception {
  377. assertEquals("a\n" + //
  378. "\n" + //
  379. "b\nc\nd\ne\n" + //
  380. "\n" + //
  381. "f\ng\nh\n" + //
  382. "\n" + //
  383. "Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n" + //
  384. SOB1,//
  385. call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n" + "\n"
  386. + SOB1));
  387. assertEquals("a\n" + //
  388. "\n" + //
  389. "b\nc\nd\ne\n" + //
  390. "\n" + //
  391. "f\ng\nh\n" + //
  392. "\n" + //
  393. "Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n" + //
  394. SOB1 + //
  395. SOB2,//
  396. call("a\n" + //
  397. "\n" + //
  398. "b\nc\nd\ne\n" + //
  399. "\n" + //
  400. "f\ng\nh\n" + //
  401. "\n" + //
  402. SOB1 + //
  403. SOB2));
  404. assertEquals("a\n" + //
  405. "\n" + //
  406. "b: not a footer\nc\nd\ne\n" + //
  407. "\n" + //
  408. "f\ng\nh\n" + //
  409. "\n" + //
  410. "Change-Id: I8869aabd44b3017cd55d2d7e0d546a03e3931ee2\n" + //
  411. SOB1 + //
  412. SOB2,//
  413. call("a\n" + //
  414. "\n" + //
  415. "b: not a footer\nc\nd\ne\n" + //
  416. "\n" + //
  417. "f\ng\nh\n" + //
  418. "\n" + //
  419. SOB1 + //
  420. SOB2));
  421. }
  422. @Test
  423. public void testNoteInMiddle() throws Exception {
  424. assertEquals("a\n" + //
  425. "\n" + //
  426. "NOTE: This\n" + //
  427. "does not fix it.\n" + //
  428. "\n" + //
  429. "Change-Id: I988a127969a6ee5e58db546aab74fc46e66847f8\n", //
  430. call("a\n" + //
  431. "\n" + //
  432. "NOTE: This\n" + //
  433. "does not fix it.\n"));
  434. }
  435. @Test
  436. public void testKernelStyleFooter() throws Exception {
  437. assertEquals("a\n" + //
  438. "\n" + //
  439. "Change-Id: I1bd787f9e7590a2ac82b02c404c955ffb21877c4\n" + //
  440. SOB1 + //
  441. "[ja: Fixed\n" + //
  442. " the indentation]\n" + //
  443. SOB2, //
  444. call("a\n" + //
  445. "\n" + //
  446. SOB1 + //
  447. "[ja: Fixed\n" + //
  448. " the indentation]\n" + //
  449. SOB2));
  450. }
  451. @Test
  452. public void testChangeIdAfterBugOrIssue() throws Exception {
  453. assertEquals("a\n" + //
  454. "\n" + //
  455. "Bug: 42\n" + //
  456. "Change-Id: I8c0321227c4324e670b9ae8cf40eccc87af21b1b\n" + //
  457. SOB1,//
  458. call("a\n" + //
  459. "\n" + //
  460. "Bug: 42\n" + //
  461. SOB1));
  462. assertEquals("a\n" + //
  463. "\n" + //
  464. "Issue: 42\n" + //
  465. "Change-Id: Ie66e07d89ae5b114c0975b49cf326e90331dd822\n" + //
  466. SOB1,//
  467. call("a\n" + //
  468. "\n" + //
  469. "Issue: 42\n" + //
  470. SOB1));
  471. }
  472. public void notestCommitDashV() throws Exception {
  473. assertEquals("a\n" + //
  474. "\n" + //
  475. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
  476. SOB1 + //
  477. SOB2, //
  478. call("a\n" + //
  479. "\n" + //
  480. SOB1 + //
  481. SOB2 + //
  482. "\n" + //
  483. "# on branch master\n" + //
  484. "diff --git a/src b/src\n" + //
  485. "new file mode 100644\n" + //
  486. "index 0000000..c78b7f0\n"));
  487. }
  488. @Test
  489. public void testWithEndingURL() throws Exception {
  490. assertEquals("a\n" + //
  491. "\n" + //
  492. "http://example.com/ fixes this\n" + //
  493. "\n" + //
  494. "Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n", //
  495. call("a\n" + //
  496. "\n" + //
  497. "http://example.com/ fixes this\n"));
  498. assertEquals("a\n" + //
  499. "\n" + //
  500. "https://example.com/ fixes this\n" + //
  501. "\n" + //
  502. "Change-Id: I62b9039e2fc0dce274af55e8f99312a8a80a805d\n", //
  503. call("a\n" + //
  504. "\n" + //
  505. "https://example.com/ fixes this\n"));
  506. assertEquals("a\n" + //
  507. "\n" + //
  508. "ftp://example.com/ fixes this\n" + //
  509. "\n" + //
  510. "Change-Id: I71b05dc1f6b9a5540a53a693e64d58b65a8910e8\n", //
  511. call("a\n" + //
  512. "\n" + //
  513. "ftp://example.com/ fixes this\n"));
  514. assertEquals("a\n" + //
  515. "\n" + //
  516. "git://example.com/ fixes this\n" + //
  517. "\n" + //
  518. "Change-Id: Id34e942baa68d790633737d815ddf11bac9183e5\n", //
  519. call("a\n" + //
  520. "\n" + //
  521. "git://example.com/ fixes this\n"));
  522. }
  523. private void hookDoesNotModify(final String in) throws Exception {
  524. assertEquals(in, call(in));
  525. }
  526. private String call(final String body) throws Exception {
  527. return call(body, false);
  528. }
  529. private String call(final String body, boolean replaceExisting) throws Exception {
  530. ObjectId computeChangeId = ChangeIdUtil.computeChangeId(treeId1,
  531. parentId1, author, committer, body);
  532. if (computeChangeId == null)
  533. return body;
  534. return ChangeIdUtil.insertId(body, computeChangeId, replaceExisting);
  535. }
  536. }