test_patch.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. # test_patch.py -- tests for patch.py
  2. # Copyright (C) 2010 Jelmer Vernooij <jelmer@jelmer.uk>
  3. #
  4. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  5. # General Public License as public by the Free Software Foundation; version 2.0
  6. # or (at your option) any later version. You can redistribute it and/or
  7. # modify it under the terms of either of these two licenses.
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. # You should have received a copy of the licenses; if not, see
  16. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  17. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  18. # License, Version 2.0.
  19. #
  20. """Tests for patch.py."""
  21. from io import BytesIO, StringIO
  22. from dulwich.objects import (
  23. Blob,
  24. Commit,
  25. S_IFGITLINK,
  26. Tree,
  27. )
  28. from dulwich.object_store import (
  29. MemoryObjectStore,
  30. )
  31. from dulwich.patch import (
  32. get_summary,
  33. git_am_patch_split,
  34. write_blob_diff,
  35. write_commit_patch,
  36. write_object_diff,
  37. write_tree_diff,
  38. )
  39. from dulwich.tests import (
  40. SkipTest,
  41. TestCase,
  42. )
  43. class WriteCommitPatchTests(TestCase):
  44. def test_simple_bytesio(self):
  45. f = BytesIO()
  46. c = Commit()
  47. c.committer = c.author = b"Jelmer <jelmer@samba.org>"
  48. c.commit_time = c.author_time = 1271350201
  49. c.commit_timezone = c.author_timezone = 0
  50. c.message = b"This is the first line\nAnd this is the second line.\n"
  51. c.tree = Tree().id
  52. write_commit_patch(f, c, b"CONTENTS", (1, 1), version="custom")
  53. f.seek(0)
  54. lines = f.readlines()
  55. self.assertTrue(lines[0].startswith(
  56. b"From 0b0d34d1b5b596c928adc9a727a4b9e03d025298"))
  57. self.assertEqual(lines[1], b"From: Jelmer <jelmer@samba.org>\n")
  58. self.assertTrue(lines[2].startswith(b"Date: "))
  59. self.assertEqual([
  60. b"Subject: [PATCH 1/1] This is the first line\n",
  61. b"And this is the second line.\n",
  62. b"\n",
  63. b"\n",
  64. b"---\n"], lines[3:8])
  65. self.assertEqual([
  66. b"CONTENTS-- \n",
  67. b"custom\n"], lines[-2:])
  68. if len(lines) >= 12:
  69. # diffstat may not be present
  70. self.assertEqual(lines[8], b" 0 files changed\n")
  71. class ReadGitAmPatch(TestCase):
  72. def test_extract_string(self):
  73. text = b"""\
  74. From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
  75. From: Jelmer Vernooij <jelmer@samba.org>
  76. Date: Thu, 15 Apr 2010 15:40:28 +0200
  77. Subject: [PATCH 1/2] Remove executable bit from prey.ico (triggers a warning).
  78. ---
  79. pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  80. 1 files changed, 0 insertions(+), 0 deletions(-)
  81. mode change 100755 => 100644 pixmaps/prey.ico
  82. --
  83. 1.7.0.4
  84. """ # noqa: W291
  85. c, diff, version = git_am_patch_split(
  86. StringIO(text.decode("utf-8")), "utf-8")
  87. self.assertEqual(b"Jelmer Vernooij <jelmer@samba.org>", c.committer)
  88. self.assertEqual(b"Jelmer Vernooij <jelmer@samba.org>", c.author)
  89. self.assertEqual(b"Remove executable bit from prey.ico "
  90. b"(triggers a warning).\n", c.message)
  91. self.assertEqual(b""" pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  92. 1 files changed, 0 insertions(+), 0 deletions(-)
  93. mode change 100755 => 100644 pixmaps/prey.ico
  94. """, diff)
  95. self.assertEqual(b"1.7.0.4", version)
  96. def test_extract_bytes(self):
  97. text = b"""\
  98. From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
  99. From: Jelmer Vernooij <jelmer@samba.org>
  100. Date: Thu, 15 Apr 2010 15:40:28 +0200
  101. Subject: [PATCH 1/2] Remove executable bit from prey.ico (triggers a warning).
  102. ---
  103. pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  104. 1 files changed, 0 insertions(+), 0 deletions(-)
  105. mode change 100755 => 100644 pixmaps/prey.ico
  106. --
  107. 1.7.0.4
  108. """ # noqa: W291
  109. c, diff, version = git_am_patch_split(BytesIO(text))
  110. self.assertEqual(b"Jelmer Vernooij <jelmer@samba.org>", c.committer)
  111. self.assertEqual(b"Jelmer Vernooij <jelmer@samba.org>", c.author)
  112. self.assertEqual(b"Remove executable bit from prey.ico "
  113. b"(triggers a warning).\n", c.message)
  114. self.assertEqual(b""" pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  115. 1 files changed, 0 insertions(+), 0 deletions(-)
  116. mode change 100755 => 100644 pixmaps/prey.ico
  117. """, diff)
  118. self.assertEqual(b"1.7.0.4", version)
  119. def test_extract_spaces(self):
  120. text = b"""From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
  121. From: Jelmer Vernooij <jelmer@samba.org>
  122. Date: Thu, 15 Apr 2010 15:40:28 +0200
  123. Subject: [Dulwich-users] [PATCH] Added unit tests for
  124. dulwich.object_store.tree_lookup_path.
  125. * dulwich/tests/test_object_store.py
  126. (TreeLookupPathTests): This test case contains a few tests that ensure the
  127. tree_lookup_path function works as expected.
  128. ---
  129. pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  130. 1 files changed, 0 insertions(+), 0 deletions(-)
  131. mode change 100755 => 100644 pixmaps/prey.ico
  132. --
  133. 1.7.0.4
  134. """ # noqa: W291
  135. c, diff, version = git_am_patch_split(BytesIO(text), "utf-8")
  136. self.assertEqual(b'''\
  137. Added unit tests for dulwich.object_store.tree_lookup_path.
  138. * dulwich/tests/test_object_store.py
  139. (TreeLookupPathTests): This test case contains a few tests that ensure the
  140. tree_lookup_path function works as expected.
  141. ''', c.message)
  142. def test_extract_pseudo_from_header(self):
  143. text = b"""From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
  144. From: Jelmer Vernooij <jelmer@samba.org>
  145. Date: Thu, 15 Apr 2010 15:40:28 +0200
  146. Subject: [Dulwich-users] [PATCH] Added unit tests for
  147. dulwich.object_store.tree_lookup_path.
  148. From: Jelmer Vernooij <jelmer@debian.org>
  149. * dulwich/tests/test_object_store.py
  150. (TreeLookupPathTests): This test case contains a few tests that ensure the
  151. tree_lookup_path function works as expected.
  152. ---
  153. pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  154. 1 files changed, 0 insertions(+), 0 deletions(-)
  155. mode change 100755 => 100644 pixmaps/prey.ico
  156. --
  157. 1.7.0.4
  158. """ # noqa: W291
  159. c, diff, version = git_am_patch_split(BytesIO(text), "utf-8")
  160. self.assertEqual(b"Jelmer Vernooij <jelmer@debian.org>", c.author)
  161. self.assertEqual(b'''\
  162. Added unit tests for dulwich.object_store.tree_lookup_path.
  163. * dulwich/tests/test_object_store.py
  164. (TreeLookupPathTests): This test case contains a few tests that ensure the
  165. tree_lookup_path function works as expected.
  166. ''', c.message)
  167. def test_extract_no_version_tail(self):
  168. text = b"""\
  169. From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
  170. From: Jelmer Vernooij <jelmer@samba.org>
  171. Date: Thu, 15 Apr 2010 15:40:28 +0200
  172. Subject: [Dulwich-users] [PATCH] Added unit tests for
  173. dulwich.object_store.tree_lookup_path.
  174. From: Jelmer Vernooij <jelmer@debian.org>
  175. ---
  176. pixmaps/prey.ico | Bin 9662 -> 9662 bytes
  177. 1 files changed, 0 insertions(+), 0 deletions(-)
  178. mode change 100755 => 100644 pixmaps/prey.ico
  179. """
  180. c, diff, version = git_am_patch_split(BytesIO(text), "utf-8")
  181. self.assertEqual(None, version)
  182. def test_extract_mercurial(self):
  183. raise SkipTest(
  184. "git_am_patch_split doesn't handle Mercurial patches "
  185. "properly yet")
  186. expected_diff = """\
  187. diff --git a/dulwich/tests/test_patch.py b/dulwich/tests/test_patch.py
  188. --- a/dulwich/tests/test_patch.py
  189. +++ b/dulwich/tests/test_patch.py
  190. @@ -158,7 +158,7 @@
  191. '''
  192. c, diff, version = git_am_patch_split(BytesIO(text))
  193. - self.assertIs(None, version)
  194. + self.assertEqual(None, version)
  195. class DiffTests(TestCase):
  196. """ # noqa: W291,W293
  197. text = """\
  198. From dulwich-users-bounces+jelmer=samba.org@lists.launchpad.net \
  199. Mon Nov 29 00:58:18 2010
  200. Date: Sun, 28 Nov 2010 17:57:27 -0600
  201. From: Augie Fackler <durin42@gmail.com>
  202. To: dulwich-users <dulwich-users@lists.launchpad.net>
  203. Subject: [Dulwich-users] [PATCH] test_patch: fix tests on Python 2.6
  204. Content-Transfer-Encoding: 8bit
  205. Change-Id: I5e51313d4ae3a65c3f00c665002a7489121bb0d6
  206. %s
  207. _______________________________________________
  208. Mailing list: https://launchpad.net/~dulwich-users
  209. Post to : dulwich-users@lists.launchpad.net
  210. Unsubscribe : https://launchpad.net/~dulwich-users
  211. More help : https://help.launchpad.net/ListHelp
  212. """ % expected_diff # noqa: W291
  213. c, diff, version = git_am_patch_split(BytesIO(text))
  214. self.assertEqual(expected_diff, diff)
  215. self.assertEqual(None, version)
  216. class DiffTests(TestCase):
  217. """Tests for write_blob_diff and write_tree_diff."""
  218. def test_blob_diff(self):
  219. f = BytesIO()
  220. write_blob_diff(
  221. f, (b"foo.txt", 0o644, Blob.from_string(b"old\nsame\n")),
  222. (b"bar.txt", 0o644, Blob.from_string(b"new\nsame\n")))
  223. self.assertEqual([
  224. b"diff --git a/foo.txt b/bar.txt",
  225. b"index 3b0f961..a116b51 644",
  226. b"--- a/foo.txt",
  227. b"+++ b/bar.txt",
  228. b"@@ -1,2 +1,2 @@",
  229. b"-old",
  230. b"+new",
  231. b" same"
  232. ], f.getvalue().splitlines())
  233. def test_blob_add(self):
  234. f = BytesIO()
  235. write_blob_diff(
  236. f, (None, None, None),
  237. (b"bar.txt", 0o644, Blob.from_string(b"new\nsame\n")))
  238. self.assertEqual([
  239. b'diff --git a/bar.txt b/bar.txt',
  240. b'new file mode 644',
  241. b'index 0000000..a116b51',
  242. b'--- /dev/null',
  243. b'+++ b/bar.txt',
  244. b'@@ -0,0 +1,2 @@',
  245. b'+new',
  246. b'+same'
  247. ], f.getvalue().splitlines())
  248. def test_blob_remove(self):
  249. f = BytesIO()
  250. write_blob_diff(
  251. f, (b"bar.txt", 0o644, Blob.from_string(b"new\nsame\n")),
  252. (None, None, None))
  253. self.assertEqual([
  254. b'diff --git a/bar.txt b/bar.txt',
  255. b'deleted file mode 644',
  256. b'index a116b51..0000000',
  257. b'--- a/bar.txt',
  258. b'+++ /dev/null',
  259. b'@@ -1,2 +0,0 @@',
  260. b'-new',
  261. b'-same'
  262. ], f.getvalue().splitlines())
  263. def test_tree_diff(self):
  264. f = BytesIO()
  265. store = MemoryObjectStore()
  266. added = Blob.from_string(b"add\n")
  267. removed = Blob.from_string(b"removed\n")
  268. changed1 = Blob.from_string(b"unchanged\nremoved\n")
  269. changed2 = Blob.from_string(b"unchanged\nadded\n")
  270. unchanged = Blob.from_string(b"unchanged\n")
  271. tree1 = Tree()
  272. tree1.add(b"removed.txt", 0o644, removed.id)
  273. tree1.add(b"changed.txt", 0o644, changed1.id)
  274. tree1.add(b"unchanged.txt", 0o644, changed1.id)
  275. tree2 = Tree()
  276. tree2.add(b"added.txt", 0o644, added.id)
  277. tree2.add(b"changed.txt", 0o644, changed2.id)
  278. tree2.add(b"unchanged.txt", 0o644, changed1.id)
  279. store.add_objects([(o, None) for o in [
  280. tree1, tree2, added, removed, changed1, changed2, unchanged]])
  281. write_tree_diff(f, store, tree1.id, tree2.id)
  282. self.assertEqual([
  283. b'diff --git a/added.txt b/added.txt',
  284. b'new file mode 644',
  285. b'index 0000000..76d4bb8',
  286. b'--- /dev/null',
  287. b'+++ b/added.txt',
  288. b'@@ -0,0 +1 @@',
  289. b'+add',
  290. b'diff --git a/changed.txt b/changed.txt',
  291. b'index bf84e48..1be2436 644',
  292. b'--- a/changed.txt',
  293. b'+++ b/changed.txt',
  294. b'@@ -1,2 +1,2 @@',
  295. b' unchanged',
  296. b'-removed',
  297. b'+added',
  298. b'diff --git a/removed.txt b/removed.txt',
  299. b'deleted file mode 644',
  300. b'index 2c3f0b3..0000000',
  301. b'--- a/removed.txt',
  302. b'+++ /dev/null',
  303. b'@@ -1 +0,0 @@',
  304. b'-removed',
  305. ], f.getvalue().splitlines())
  306. def test_tree_diff_submodule(self):
  307. f = BytesIO()
  308. store = MemoryObjectStore()
  309. tree1 = Tree()
  310. tree1.add(b"asubmodule", S_IFGITLINK,
  311. b"06d0bdd9e2e20377b3180e4986b14c8549b393e4")
  312. tree2 = Tree()
  313. tree2.add(b"asubmodule", S_IFGITLINK,
  314. b"cc975646af69f279396d4d5e1379ac6af80ee637")
  315. store.add_objects([(o, None) for o in [tree1, tree2]])
  316. write_tree_diff(f, store, tree1.id, tree2.id)
  317. self.assertEqual([
  318. b'diff --git a/asubmodule b/asubmodule',
  319. b'index 06d0bdd..cc97564 160000',
  320. b'--- a/asubmodule',
  321. b'+++ b/asubmodule',
  322. b'@@ -1 +1 @@',
  323. b'-Submodule commit 06d0bdd9e2e20377b3180e4986b14c8549b393e4',
  324. b'+Submodule commit cc975646af69f279396d4d5e1379ac6af80ee637',
  325. ], f.getvalue().splitlines())
  326. def test_object_diff_blob(self):
  327. f = BytesIO()
  328. b1 = Blob.from_string(b"old\nsame\n")
  329. b2 = Blob.from_string(b"new\nsame\n")
  330. store = MemoryObjectStore()
  331. store.add_objects([(b1, None), (b2, None)])
  332. write_object_diff(f, store, (b"foo.txt", 0o644, b1.id),
  333. (b"bar.txt", 0o644, b2.id))
  334. self.assertEqual([
  335. b"diff --git a/foo.txt b/bar.txt",
  336. b"index 3b0f961..a116b51 644",
  337. b"--- a/foo.txt",
  338. b"+++ b/bar.txt",
  339. b"@@ -1,2 +1,2 @@",
  340. b"-old",
  341. b"+new",
  342. b" same"
  343. ], f.getvalue().splitlines())
  344. def test_object_diff_add_blob(self):
  345. f = BytesIO()
  346. store = MemoryObjectStore()
  347. b2 = Blob.from_string(b"new\nsame\n")
  348. store.add_object(b2)
  349. write_object_diff(f, store, (None, None, None),
  350. (b"bar.txt", 0o644, b2.id))
  351. self.assertEqual([
  352. b'diff --git a/bar.txt b/bar.txt',
  353. b'new file mode 644',
  354. b'index 0000000..a116b51',
  355. b'--- /dev/null',
  356. b'+++ b/bar.txt',
  357. b'@@ -0,0 +1,2 @@',
  358. b'+new',
  359. b'+same'
  360. ], f.getvalue().splitlines())
  361. def test_object_diff_remove_blob(self):
  362. f = BytesIO()
  363. b1 = Blob.from_string(b"new\nsame\n")
  364. store = MemoryObjectStore()
  365. store.add_object(b1)
  366. write_object_diff(f, store, (b"bar.txt", 0o644, b1.id),
  367. (None, None, None))
  368. self.assertEqual([
  369. b'diff --git a/bar.txt b/bar.txt',
  370. b'deleted file mode 644',
  371. b'index a116b51..0000000',
  372. b'--- a/bar.txt',
  373. b'+++ /dev/null',
  374. b'@@ -1,2 +0,0 @@',
  375. b'-new',
  376. b'-same'
  377. ], f.getvalue().splitlines())
  378. def test_object_diff_bin_blob_force(self):
  379. f = BytesIO()
  380. # Prepare two slightly different PNG headers
  381. b1 = Blob.from_string(
  382. b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
  383. b"\x00\x00\x00\x0d\x49\x48\x44\x52"
  384. b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
  385. b"\x08\x04\x00\x00\x00\x05\x04\x8b")
  386. b2 = Blob.from_string(
  387. b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
  388. b"\x00\x00\x00\x0d\x49\x48\x44\x52"
  389. b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
  390. b"\x08\x03\x00\x00\x00\x98\xd3\xb3")
  391. store = MemoryObjectStore()
  392. store.add_objects([(b1, None), (b2, None)])
  393. write_object_diff(
  394. f, store, (b'foo.png', 0o644, b1.id),
  395. (b'bar.png', 0o644, b2.id), diff_binary=True)
  396. self.assertEqual([
  397. b'diff --git a/foo.png b/bar.png',
  398. b'index f73e47d..06364b7 644',
  399. b'--- a/foo.png',
  400. b'+++ b/bar.png',
  401. b'@@ -1,4 +1,4 @@',
  402. b' \x89PNG',
  403. b' \x1a',
  404. b' \x00\x00\x00',
  405. b'-IHDR\x00\x00\x01\xd5\x00\x00\x00'
  406. b'\x9f\x08\x04\x00\x00\x00\x05\x04\x8b',
  407. b'\\ No newline at end of file',
  408. b'+IHDR\x00\x00\x01\xd5\x00\x00\x00\x9f'
  409. b'\x08\x03\x00\x00\x00\x98\xd3\xb3',
  410. b'\\ No newline at end of file'
  411. ], f.getvalue().splitlines())
  412. def test_object_diff_bin_blob(self):
  413. f = BytesIO()
  414. # Prepare two slightly different PNG headers
  415. b1 = Blob.from_string(
  416. b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
  417. b"\x00\x00\x00\x0d\x49\x48\x44\x52"
  418. b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
  419. b"\x08\x04\x00\x00\x00\x05\x04\x8b")
  420. b2 = Blob.from_string(
  421. b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
  422. b"\x00\x00\x00\x0d\x49\x48\x44\x52"
  423. b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
  424. b"\x08\x03\x00\x00\x00\x98\xd3\xb3")
  425. store = MemoryObjectStore()
  426. store.add_objects([(b1, None), (b2, None)])
  427. write_object_diff(f, store, (b'foo.png', 0o644, b1.id),
  428. (b'bar.png', 0o644, b2.id))
  429. self.assertEqual([
  430. b'diff --git a/foo.png b/bar.png',
  431. b'index f73e47d..06364b7 644',
  432. b'Binary files a/foo.png and b/bar.png differ'
  433. ], f.getvalue().splitlines())
  434. def test_object_diff_add_bin_blob(self):
  435. f = BytesIO()
  436. b2 = Blob.from_string(
  437. b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a'
  438. b'\x00\x00\x00\x0d\x49\x48\x44\x52'
  439. b'\x00\x00\x01\xd5\x00\x00\x00\x9f'
  440. b'\x08\x03\x00\x00\x00\x98\xd3\xb3')
  441. store = MemoryObjectStore()
  442. store.add_object(b2)
  443. write_object_diff(f, store, (None, None, None),
  444. (b'bar.png', 0o644, b2.id))
  445. self.assertEqual([
  446. b'diff --git a/bar.png b/bar.png',
  447. b'new file mode 644',
  448. b'index 0000000..06364b7',
  449. b'Binary files /dev/null and b/bar.png differ'
  450. ], f.getvalue().splitlines())
  451. def test_object_diff_remove_bin_blob(self):
  452. f = BytesIO()
  453. b1 = Blob.from_string(
  454. b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a'
  455. b'\x00\x00\x00\x0d\x49\x48\x44\x52'
  456. b'\x00\x00\x01\xd5\x00\x00\x00\x9f'
  457. b'\x08\x04\x00\x00\x00\x05\x04\x8b')
  458. store = MemoryObjectStore()
  459. store.add_object(b1)
  460. write_object_diff(f, store, (b'foo.png', 0o644, b1.id),
  461. (None, None, None))
  462. self.assertEqual([
  463. b'diff --git a/foo.png b/foo.png',
  464. b'deleted file mode 644',
  465. b'index f73e47d..0000000',
  466. b'Binary files a/foo.png and /dev/null differ'
  467. ], f.getvalue().splitlines())
  468. def test_object_diff_kind_change(self):
  469. f = BytesIO()
  470. b1 = Blob.from_string(b"new\nsame\n")
  471. store = MemoryObjectStore()
  472. store.add_object(b1)
  473. write_object_diff(
  474. f, store, (b"bar.txt", 0o644, b1.id),
  475. (b"bar.txt", 0o160000,
  476. b"06d0bdd9e2e20377b3180e4986b14c8549b393e4"))
  477. self.assertEqual([
  478. b'diff --git a/bar.txt b/bar.txt',
  479. b'old file mode 644',
  480. b'new file mode 160000',
  481. b'index a116b51..06d0bdd 160000',
  482. b'--- a/bar.txt',
  483. b'+++ b/bar.txt',
  484. b'@@ -1,2 +1 @@',
  485. b'-new',
  486. b'-same',
  487. b'+Submodule commit 06d0bdd9e2e20377b3180e4986b14c8549b393e4',
  488. ], f.getvalue().splitlines())
  489. class GetSummaryTests(TestCase):
  490. def test_simple(self):
  491. c = Commit()
  492. c.committer = c.author = b"Jelmer <jelmer@samba.org>"
  493. c.commit_time = c.author_time = 1271350201
  494. c.commit_timezone = c.author_timezone = 0
  495. c.message = b"This is the first line\nAnd this is the second line.\n"
  496. c.tree = Tree().id
  497. self.assertEqual('This-is-the-first-line', get_summary(c))