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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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 java.io.IOException;
  46. import java.util.concurrent.TimeUnit;
  47. import junit.framework.TestCase;
  48. import org.eclipse.jgit.junit.MockSystemReader;
  49. import org.eclipse.jgit.lib.ObjectId;
  50. import org.eclipse.jgit.lib.PersonIdent;
  51. /**
  52. * Portions of this test is from CommitMsgHookTest in the Android project Gerrit
  53. */
  54. public class ChangeIdUtilTest extends TestCase {
  55. private final String SOB1 = "Signed-off-by: J Author <ja@example.com>\n";
  56. private final String SOB2 = "Signed-off-by: J Committer <jc@example.com>\n";
  57. final PersonIdent p = RawParseUtils.parsePersonIdent(
  58. "A U Thor <author@example.com> 1142878501 -0500");
  59. final PersonIdent q = RawParseUtils.parsePersonIdent(
  60. "W Riter <writer@example.com> 1142878502 -0500");
  61. ObjectId treeId = ObjectId
  62. .fromString("f51de923607cd51cf872b928a6b523ba823f7f35");
  63. ObjectId treeId1 = ObjectId
  64. .fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904");
  65. final ObjectId treeId2 = ObjectId
  66. .fromString("617601c79811cbbae338512798318b4e5b70c9ac");
  67. ObjectId parentId = ObjectId
  68. .fromString("91fea719aaf9447feb9580477eb3dd08b62b5eca");
  69. ObjectId parentId1 = null;
  70. final ObjectId parentId2 = ObjectId
  71. .fromString("485c91e0600b165c301c278bfbae3e492413980c");
  72. MockSystemReader mockSystemReader = new MockSystemReader();
  73. final long when = mockSystemReader.getCurrentTime();
  74. final int tz = new MockSystemReader().getTimezone(when);
  75. PersonIdent author = new PersonIdent("J. Author", "ja@example.com");
  76. {
  77. author = new PersonIdent(author, when, tz);
  78. }
  79. PersonIdent committer = new PersonIdent("J. Committer", "jc@example.com");
  80. {
  81. committer = new PersonIdent(committer, when, tz);
  82. }
  83. public void testClean() {
  84. assertEquals("hej", ChangeIdUtil.clean("hej\n\n"));
  85. assertEquals("hej\n\nsan", ChangeIdUtil.clean("hej\n\nsan\n\n"));
  86. assertEquals("hej\nsan", ChangeIdUtil.clean("hej\n#men\nsan\n\n#men"));
  87. assertEquals("hej\nsan", ChangeIdUtil.clean("hej\nsan\n\n#men"));
  88. assertEquals("hej\nsan", ChangeIdUtil.clean("#no\nhej\nsan\n\n#men"));
  89. assertEquals("hej\nsan", ChangeIdUtil
  90. .clean("#no\nhej\nsan\nSigned-off-by: me \n#men"));
  91. }
  92. public void testId() throws IOException {
  93. String msg = "A\nMessage\n";
  94. ObjectId id = ChangeIdUtil.computeChangeId(treeId, parentId, p, q, msg);
  95. assertEquals("73f3751208ac92cbb76f9a26ac4a0d9d472e381b", ObjectId
  96. .toString(id));
  97. }
  98. public void testHasChangeid() throws Exception {
  99. assertEquals(
  100. "has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n",
  101. call("has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n"));
  102. }
  103. public void testHasChangeidWithReplacement() throws Exception {
  104. assertEquals(
  105. "has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I988d2d7a6f2c0578fccabd4ebd3cec0768bc7f9f\nAnd then some\n",
  106. call("has changeid\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\nChange-Id: I0123456789012345678901234567890123456789\nAnd then some\n",
  107. true));
  108. }
  109. public void testOneliner() throws Exception {
  110. assertEquals(
  111. "oneliner\n\nChange-Id: I3a98091ce4470de88d52ae317fcd297e2339f063\n",
  112. call("oneliner\n"));
  113. }
  114. public void testOnelinerFollowedByBlank() throws Exception {
  115. assertEquals(
  116. "oneliner followed by blank\n\nChange-Id: I3a12c21ef342a18498f95c62efbc186cd782b743\n",
  117. call("oneliner followed by blank\n"));
  118. }
  119. public void testATwoLines() throws Exception {
  120. assertEquals(
  121. "a two lines\nwith text withour break after subject line\n\nChange-Id: I549a0fed3d69b7876c54b4f5a35637135fd43fac\n",
  122. call("a two lines\nwith text withour break after subject line\n"));
  123. }
  124. public void testRegularCommit() throws Exception {
  125. assertEquals(
  126. "regular commit\n\nwith header and body\n\nChange-Id: I62d8749d3c3a888c11e3fadc3924220a19389766\n",
  127. call("regular commit\n\nwith header and body\n"));
  128. }
  129. public void testRegularCommitWithSob_ButNoBody() throws Exception {
  130. assertEquals(
  131. "regular commit with sob, but no body\n\nChange-Id: I0f0b4307e9944ecbd5a9f6b9489e25cfaede43c4\nSigned-off-by: me@you.too\n",
  132. call("regular commit with sob, but no body\n\nSigned-off-by: me@you.too\n"));
  133. }
  134. public void testACommitWithBug_SubButNoBody() throws Exception {
  135. assertEquals(
  136. "a commit with bug, sub but no body\n\nBug: 33\nChange-Id: I337e264868613dab6d1e11a34f394db369487412\nSigned-off-by: me@you.too\n",
  137. call("a commit with bug, sub but no body\n\nBug: 33\nSigned-off-by: me@you.too\n"));
  138. }
  139. public void testACommitWithSubject_NoBodySobAndBug() throws Exception {
  140. assertEquals(
  141. "a commit with subject, no body sob and bug\n\nChange-Id: Ib3616d4bf77707a3215a6cb0602c004ee119a445\nSigned-off-by: me@you.too\nBug: 33\n",
  142. call("a commit with subject, no body sob and bug\n\nSigned-off-by: me@you.too\nBug: 33\n"));
  143. }
  144. public void testACommitWithSubjectBug_NonFooterLineAndSob()
  145. throws Exception {
  146. assertEquals(
  147. "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",
  148. call("a commit with subject bug, non-footer line and sob\n\nBug: 33\nmore text\nSigned-off-by: me@you.too\n"));
  149. }
  150. public void testACommitWithSubject_NonFooterAndBugAndSob() throws Exception {
  151. assertEquals(
  152. "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",
  153. 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"));
  154. }
  155. public void testACommitWithSubjectBodyBugBrackersAndSob() throws Exception {
  156. assertEquals(
  157. "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",
  158. 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"));
  159. }
  160. public void testACommitWithSubjectBodyBugLineWithASpaceAndSob()
  161. throws Exception {
  162. assertEquals(
  163. "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",
  164. 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"));
  165. }
  166. public void testACommitWithSubjectBodyBugEmptyLineAndSob() throws Exception {
  167. assertEquals(
  168. "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",
  169. 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"));
  170. }
  171. public void testEmptyMessages() throws Exception {
  172. // Empty input must not produce a change id.
  173. hookDoesNotModify("");
  174. hookDoesNotModify(" ");
  175. hookDoesNotModify("\n");
  176. hookDoesNotModify("\n\n");
  177. hookDoesNotModify(" \n ");
  178. hookDoesNotModify("#");
  179. hookDoesNotModify("#\n");
  180. hookDoesNotModify("# on branch master\n# Untracked files:\n");
  181. hookDoesNotModify("\n# on branch master\n# Untracked files:\n");
  182. hookDoesNotModify("\n\n# on branch master\n# Untracked files:\n");
  183. hookDoesNotModify("\n# on branch master\ndiff --git a/src b/src\n"
  184. + "new file mode 100644\nindex 0000000..c78b7f0\n");
  185. }
  186. public void testChangeIdAlreadySet() throws Exception {
  187. // If a Change-Id is already present in the footer, the hook must
  188. // not modify the message but instead must leave the identity alone.
  189. //
  190. hookDoesNotModify("a\n" + //
  191. "\n" + //
  192. "Change-Id: Iaeac9b4149291060228ef0154db2985a31111335\n");
  193. hookDoesNotModify("fix: this thing\n" + //
  194. "\n" + //
  195. "Change-Id: I388bdaf52ed05b55e62a22d0a20d2c1ae0d33e7e\n");
  196. hookDoesNotModify("fix-a-widget: this thing\n" + //
  197. "\n" + //
  198. "Change-Id: Id3bc5359d768a6400450283e12bdfb6cd135ea4b\n");
  199. hookDoesNotModify("FIX: this thing\n" + //
  200. "\n" + //
  201. "Change-Id: I1b55098b5a2cce0b3f3da783dda50d5f79f873fa\n");
  202. hookDoesNotModify("Fix-A-Widget: this thing\n" + //
  203. "\n" + //
  204. "Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n");
  205. }
  206. public void testChangeIdAlreadySetWithReplacement() throws Exception {
  207. // If a Change-Id is already present in the footer, the hook
  208. // replaces the Change-Id with the new value..
  209. //
  210. assertEquals("a\n" + //
  211. "\n" + //
  212. "Change-Id: Ifa324efa85bfb3c8696a46a0f67fa70c35be5f5f\n",
  213. call("a\n" + //
  214. "\n" + //
  215. "Change-Id: Iaeac9b4149291060228ef0154db2985a31111335\n",
  216. true));
  217. assertEquals("fix: this thing\n" + //
  218. "\n" + //
  219. "Change-Id: Ib63e4990a06412a3f24bd93bb160e98ac1bd412b\n",
  220. call("fix: this thing\n" + //
  221. "\n" + //
  222. "Change-Id: I388bdaf52ed05b55e62a22d0a20d2c1ae0d33e7e\n",
  223. true));
  224. assertEquals("fix-a-widget: this thing\n" + //
  225. "\n" + //
  226. "Change-Id: If0444e4d0cabcf41b3d3b46b7e9a7a64a82117af\n",
  227. call("fix-a-widget: this thing\n" + //
  228. "\n" + //
  229. "Change-Id: Id3bc5359d768a6400450283e12bdfb6cd135ea4b\n",
  230. true));
  231. assertEquals("FIX: this thing\n" + //
  232. "\n" + //
  233. "Change-Id: Iba5a3b2d5e5df46448f6daf362b6bfa775c6491d\n",
  234. call("FIX: this thing\n" + //
  235. "\n" + //
  236. "Change-Id: I1b55098b5a2cce0b3f3da783dda50d5f79f873fa\n",
  237. true));
  238. assertEquals("Fix-A-Widget: this thing\n" + //
  239. "\n" + //
  240. "Change-Id: I2573d47c62c42429fbe424d70cfba931f8f87848\n",
  241. call("Fix-A-Widget: this thing\n" + //
  242. "\n" + //
  243. "Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n",
  244. true));
  245. }
  246. public void testTimeAltersId() throws Exception {
  247. assertEquals("a\n" + //
  248. "\n" + //
  249. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  250. call("a\n"));
  251. tick();
  252. assertEquals("a\n" + //
  253. "\n" + //
  254. "Change-Id: I3251906b99dda598a58a6346d8126237ee1ea800\n",//
  255. call("a\n"));
  256. tick();
  257. assertEquals("a\n" + //
  258. "\n" + //
  259. "Change-Id: I69adf9208d828f41a3d7e41afbca63aff37c0c5c\n",//
  260. call("a\n"));
  261. }
  262. /** Increment the {@link #author} and {@link #committer} times. */
  263. protected void tick() {
  264. final long delta = TimeUnit.MILLISECONDS.convert(5 * 60,
  265. TimeUnit.SECONDS);
  266. final long now = author.getWhen().getTime() + delta;
  267. author = new PersonIdent(author, now, tz);
  268. committer = new PersonIdent(committer, now, tz);
  269. }
  270. public void testFirstParentAltersId() throws Exception {
  271. assertEquals("a\n" + //
  272. "\n" + //
  273. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  274. call("a\n"));
  275. parentId1 = parentId2;
  276. assertEquals("a\n" + //
  277. "\n" + //
  278. "Change-Id: I51e86482bde7f92028541aaf724d3a3f996e7ea2\n",//
  279. call("a\n"));
  280. }
  281. public void testDirCacheAltersId() throws Exception {
  282. assertEquals("a\n" + //
  283. "\n" + //
  284. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  285. call("a\n"));
  286. treeId1 = treeId2;
  287. assertEquals("a\n" + //
  288. "\n" + //
  289. "Change-Id: If56597ea9759f23b070677ea6f064c60c38da631\n",//
  290. call("a\n"));
  291. }
  292. public void testSingleLineMessages() throws Exception {
  293. assertEquals("a\n" + //
  294. "\n" + //
  295. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
  296. call("a\n"));
  297. assertEquals("fix: this thing\n" + //
  298. "\n" + //
  299. "Change-Id: I0f13d0e6c739ca3ae399a05a93792e80feb97f37\n",//
  300. call("fix: this thing\n"));
  301. assertEquals("fix-a-widget: this thing\n" + //
  302. "\n" + //
  303. "Change-Id: I1a1a0c751e4273d532e4046a501a612b9b8a775e\n",//
  304. call("fix-a-widget: this thing\n"));
  305. assertEquals("FIX: this thing\n" + //
  306. "\n" + //
  307. "Change-Id: If816d944c57d3893b60cf10c65931fead1290d97\n",//
  308. call("FIX: this thing\n"));
  309. assertEquals("Fix-A-Widget: this thing\n" + //
  310. "\n" + //
  311. "Change-Id: I3e18d00cbda2ba1f73aeb63ed8c7d57d7fd16c76\n",//
  312. call("Fix-A-Widget: this thing\n"));
  313. }
  314. public void testMultiLineMessagesWithoutFooter() throws Exception {
  315. assertEquals("a\n" + //
  316. "\n" + //
  317. "b\n" + //
  318. "\n" + //
  319. "Change-Id: Id0b4f42d3d6fc1569595c9b97cb665e738486f5d\n",//
  320. call("a\n" + "\n" + "b\n"));
  321. assertEquals("a\n" + //
  322. "\n" + //
  323. "b\nc\nd\ne\n" + //
  324. "\n" + //
  325. "Change-Id: I7d237b20058a0f46cc3f5fabc4a0476877289d75\n",//
  326. call("a\n" + "\n" + "b\nc\nd\ne\n"));
  327. assertEquals("a\n" + //
  328. "\n" + //
  329. "b\nc\nd\ne\n" + //
  330. "\n" + //
  331. "f\ng\nh\n" + //
  332. "\n" + //
  333. "Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n",//
  334. call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n"));
  335. }
  336. public void testSingleLineMessagesWithSignedOffBy() throws Exception {
  337. assertEquals("a\n" + //
  338. "\n" + //
  339. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
  340. SOB1,//
  341. call("a\n" + "\n" + SOB1));
  342. assertEquals("a\n" + //
  343. "\n" + //
  344. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
  345. SOB1 + //
  346. SOB2,//
  347. call("a\n" + "\n" + SOB1 + SOB2));
  348. }
  349. public void testMultiLineMessagesWithSignedOffBy() throws Exception {
  350. assertEquals("a\n" + //
  351. "\n" + //
  352. "b\nc\nd\ne\n" + //
  353. "\n" + //
  354. "f\ng\nh\n" + //
  355. "\n" + //
  356. "Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n" + //
  357. SOB1,//
  358. call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n" + "\n"
  359. + SOB1));
  360. assertEquals("a\n" + //
  361. "\n" + //
  362. "b\nc\nd\ne\n" + //
  363. "\n" + //
  364. "f\ng\nh\n" + //
  365. "\n" + //
  366. "Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n" + //
  367. SOB1 + //
  368. SOB2,//
  369. call("a\n" + //
  370. "\n" + //
  371. "b\nc\nd\ne\n" + //
  372. "\n" + //
  373. "f\ng\nh\n" + //
  374. "\n" + //
  375. SOB1 + //
  376. SOB2));
  377. assertEquals("a\n" + //
  378. "\n" + //
  379. "b: not a footer\nc\nd\ne\n" + //
  380. "\n" + //
  381. "f\ng\nh\n" + //
  382. "\n" + //
  383. "Change-Id: I8869aabd44b3017cd55d2d7e0d546a03e3931ee2\n" + //
  384. SOB1 + //
  385. SOB2,//
  386. call("a\n" + //
  387. "\n" + //
  388. "b: not a footer\nc\nd\ne\n" + //
  389. "\n" + //
  390. "f\ng\nh\n" + //
  391. "\n" + //
  392. SOB1 + //
  393. SOB2));
  394. }
  395. public void testNoteInMiddle() throws Exception {
  396. assertEquals("a\n" + //
  397. "\n" + //
  398. "NOTE: This\n" + //
  399. "does not fix it.\n" + //
  400. "\n" + //
  401. "Change-Id: I988a127969a6ee5e58db546aab74fc46e66847f8\n", //
  402. call("a\n" + //
  403. "\n" + //
  404. "NOTE: This\n" + //
  405. "does not fix it.\n"));
  406. }
  407. public void testKernelStyleFooter() throws Exception {
  408. assertEquals("a\n" + //
  409. "\n" + //
  410. "Change-Id: I1bd787f9e7590a2ac82b02c404c955ffb21877c4\n" + //
  411. SOB1 + //
  412. "[ja: Fixed\n" + //
  413. " the indentation]\n" + //
  414. SOB2, //
  415. call("a\n" + //
  416. "\n" + //
  417. SOB1 + //
  418. "[ja: Fixed\n" + //
  419. " the indentation]\n" + //
  420. SOB2));
  421. }
  422. public void testChangeIdAfterBugOrIssue() throws Exception {
  423. assertEquals("a\n" + //
  424. "\n" + //
  425. "Bug: 42\n" + //
  426. "Change-Id: I8c0321227c4324e670b9ae8cf40eccc87af21b1b\n" + //
  427. SOB1,//
  428. call("a\n" + //
  429. "\n" + //
  430. "Bug: 42\n" + //
  431. SOB1));
  432. assertEquals("a\n" + //
  433. "\n" + //
  434. "Issue: 42\n" + //
  435. "Change-Id: Ie66e07d89ae5b114c0975b49cf326e90331dd822\n" + //
  436. SOB1,//
  437. call("a\n" + //
  438. "\n" + //
  439. "Issue: 42\n" + //
  440. SOB1));
  441. }
  442. public void notestCommitDashV() throws Exception {
  443. assertEquals("a\n" + //
  444. "\n" + //
  445. "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
  446. SOB1 + //
  447. SOB2, //
  448. call("a\n" + //
  449. "\n" + //
  450. SOB1 + //
  451. SOB2 + //
  452. "\n" + //
  453. "# on branch master\n" + //
  454. "diff --git a/src b/src\n" + //
  455. "new file mode 100644\n" + //
  456. "index 0000000..c78b7f0\n"));
  457. }
  458. public void testWithEndingURL() throws Exception {
  459. assertEquals("a\n" + //
  460. "\n" + //
  461. "http://example.com/ fixes this\n" + //
  462. "\n" + //
  463. "Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n", //
  464. call("a\n" + //
  465. "\n" + //
  466. "http://example.com/ fixes this\n"));
  467. assertEquals("a\n" + //
  468. "\n" + //
  469. "https://example.com/ fixes this\n" + //
  470. "\n" + //
  471. "Change-Id: I62b9039e2fc0dce274af55e8f99312a8a80a805d\n", //
  472. call("a\n" + //
  473. "\n" + //
  474. "https://example.com/ fixes this\n"));
  475. assertEquals("a\n" + //
  476. "\n" + //
  477. "ftp://example.com/ fixes this\n" + //
  478. "\n" + //
  479. "Change-Id: I71b05dc1f6b9a5540a53a693e64d58b65a8910e8\n", //
  480. call("a\n" + //
  481. "\n" + //
  482. "ftp://example.com/ fixes this\n"));
  483. assertEquals("a\n" + //
  484. "\n" + //
  485. "git://example.com/ fixes this\n" + //
  486. "\n" + //
  487. "Change-Id: Id34e942baa68d790633737d815ddf11bac9183e5\n", //
  488. call("a\n" + //
  489. "\n" + //
  490. "git://example.com/ fixes this\n"));
  491. }
  492. private void hookDoesNotModify(final String in) throws Exception {
  493. assertEquals(in, call(in));
  494. }
  495. private String call(final String body) throws Exception {
  496. return call(body, false);
  497. }
  498. private String call(final String body, boolean replaceExisting) throws Exception {
  499. ObjectId computeChangeId = ChangeIdUtil.computeChangeId(treeId1,
  500. parentId1, author, committer, body);
  501. if (computeChangeId == null)
  502. return body;
  503. return ChangeIdUtil.insertId(body, computeChangeId, replaceExisting);
  504. }
  505. }