test_patch.py 19 KB

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