test_porcelain.py 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. # test_porcelain.py -- porcelain tests
  2. # Copyright (C) 2013 Jelmer Vernooij <jelmer@samba.org>
  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 dulwich.porcelain."""
  21. from io import BytesIO
  22. try:
  23. from StringIO import StringIO
  24. except ImportError:
  25. from io import StringIO
  26. import os
  27. import shutil
  28. import tarfile
  29. import tempfile
  30. import time
  31. from dulwich import porcelain
  32. from dulwich.diff_tree import tree_changes
  33. from dulwich.objects import (
  34. Blob,
  35. Tag,
  36. Tree,
  37. ZERO_SHA,
  38. )
  39. from dulwich.repo import Repo
  40. from dulwich.tests import (
  41. TestCase,
  42. )
  43. from dulwich.tests.utils import (
  44. build_commit_graph,
  45. make_commit,
  46. make_object,
  47. )
  48. class PorcelainTestCase(TestCase):
  49. def setUp(self):
  50. super(PorcelainTestCase, self).setUp()
  51. repo_dir = tempfile.mkdtemp()
  52. self.addCleanup(shutil.rmtree, repo_dir)
  53. self.repo = Repo.init(repo_dir)
  54. def tearDown(self):
  55. super(PorcelainTestCase, self).tearDown()
  56. self.repo.close()
  57. class ArchiveTests(PorcelainTestCase):
  58. """Tests for the archive command."""
  59. def test_simple(self):
  60. c1, c2, c3 = build_commit_graph(
  61. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  62. self.repo.refs[b"refs/heads/master"] = c3.id
  63. out = BytesIO()
  64. err = BytesIO()
  65. porcelain.archive(self.repo.path, b"refs/heads/master", outstream=out,
  66. errstream=err)
  67. self.assertEqual(b"", err.getvalue())
  68. tf = tarfile.TarFile(fileobj=out)
  69. self.addCleanup(tf.close)
  70. self.assertEqual([], tf.getnames())
  71. class UpdateServerInfoTests(PorcelainTestCase):
  72. def test_simple(self):
  73. c1, c2, c3 = build_commit_graph(
  74. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  75. self.repo.refs[b"refs/heads/foo"] = c3.id
  76. porcelain.update_server_info(self.repo.path)
  77. self.assertTrue(os.path.exists(
  78. os.path.join(self.repo.controldir(), 'info', 'refs')))
  79. class CommitTests(PorcelainTestCase):
  80. def test_custom_author(self):
  81. c1, c2, c3 = build_commit_graph(
  82. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  83. self.repo.refs[b"refs/heads/foo"] = c3.id
  84. sha = porcelain.commit(
  85. self.repo.path, message=b"Some message",
  86. author=b"Joe <joe@example.com>",
  87. committer=b"Bob <bob@example.com>")
  88. self.assertTrue(isinstance(sha, bytes))
  89. self.assertEqual(len(sha), 40)
  90. class CloneTests(PorcelainTestCase):
  91. def test_simple_local(self):
  92. f1_1 = make_object(Blob, data=b'f1')
  93. commit_spec = [[1], [2, 1], [3, 1, 2]]
  94. trees = {1: [(b'f1', f1_1), (b'f2', f1_1)],
  95. 2: [(b'f1', f1_1), (b'f2', f1_1)],
  96. 3: [(b'f1', f1_1), (b'f2', f1_1)], }
  97. c1, c2, c3 = build_commit_graph(self.repo.object_store,
  98. commit_spec, trees)
  99. self.repo.refs[b"refs/heads/master"] = c3.id
  100. self.repo.refs[b"refs/tags/foo"] = c3.id
  101. target_path = tempfile.mkdtemp()
  102. errstream = BytesIO()
  103. self.addCleanup(shutil.rmtree, target_path)
  104. r = porcelain.clone(self.repo.path, target_path,
  105. checkout=False, errstream=errstream)
  106. self.assertEqual(r.path, target_path)
  107. target_repo = Repo(target_path)
  108. self.assertEqual(target_repo.head(), c3.id)
  109. self.assertEqual(c3.id, target_repo.refs[b'refs/tags/foo'])
  110. self.assertTrue(b'f1' not in os.listdir(target_path))
  111. self.assertTrue(b'f2' not in os.listdir(target_path))
  112. c = r.get_config()
  113. encoded_path = self.repo.path
  114. if not isinstance(encoded_path, bytes):
  115. encoded_path = encoded_path.encode('utf-8')
  116. self.assertEqual(encoded_path, c.get((b'remote', b'origin'), b'url'))
  117. self.assertEqual(
  118. b'+refs/heads/*:refs/remotes/origin/*',
  119. c.get((b'remote', b'origin'), b'fetch'))
  120. def test_simple_local_with_checkout(self):
  121. f1_1 = make_object(Blob, data=b'f1')
  122. commit_spec = [[1], [2, 1], [3, 1, 2]]
  123. trees = {1: [(b'f1', f1_1), (b'f2', f1_1)],
  124. 2: [(b'f1', f1_1), (b'f2', f1_1)],
  125. 3: [(b'f1', f1_1), (b'f2', f1_1)], }
  126. c1, c2, c3 = build_commit_graph(self.repo.object_store,
  127. commit_spec, trees)
  128. self.repo.refs[b"refs/heads/master"] = c3.id
  129. target_path = tempfile.mkdtemp()
  130. errstream = BytesIO()
  131. self.addCleanup(shutil.rmtree, target_path)
  132. with porcelain.clone(self.repo.path, target_path,
  133. checkout=True,
  134. errstream=errstream) as r:
  135. self.assertEqual(r.path, target_path)
  136. with Repo(target_path) as r:
  137. self.assertEqual(r.head(), c3.id)
  138. self.assertTrue('f1' in os.listdir(target_path))
  139. self.assertTrue('f2' in os.listdir(target_path))
  140. def test_bare_local_with_checkout(self):
  141. f1_1 = make_object(Blob, data=b'f1')
  142. commit_spec = [[1], [2, 1], [3, 1, 2]]
  143. trees = {1: [(b'f1', f1_1), (b'f2', f1_1)],
  144. 2: [(b'f1', f1_1), (b'f2', f1_1)],
  145. 3: [(b'f1', f1_1), (b'f2', f1_1)], }
  146. c1, c2, c3 = build_commit_graph(self.repo.object_store,
  147. commit_spec, trees)
  148. self.repo.refs[b"refs/heads/master"] = c3.id
  149. target_path = tempfile.mkdtemp()
  150. errstream = BytesIO()
  151. self.addCleanup(shutil.rmtree, target_path)
  152. with porcelain.clone(
  153. self.repo.path, target_path, bare=True,
  154. errstream=errstream) as r:
  155. self.assertEqual(r.path, target_path)
  156. with Repo(target_path) as r:
  157. self.assertRaises(KeyError, r.head)
  158. self.assertFalse(b'f1' in os.listdir(target_path))
  159. self.assertFalse(b'f2' in os.listdir(target_path))
  160. def test_no_checkout_with_bare(self):
  161. f1_1 = make_object(Blob, data=b'f1')
  162. commit_spec = [[1]]
  163. trees = {1: [(b'f1', f1_1), (b'f2', f1_1)]}
  164. (c1, ) = build_commit_graph(self.repo.object_store, commit_spec, trees)
  165. self.repo.refs[b"refs/heads/master"] = c1.id
  166. self.repo.refs[b"HEAD"] = c1.id
  167. target_path = tempfile.mkdtemp()
  168. errstream = BytesIO()
  169. self.addCleanup(shutil.rmtree, target_path)
  170. self.assertRaises(
  171. ValueError, porcelain.clone, self.repo.path,
  172. target_path, checkout=True, bare=True, errstream=errstream)
  173. def test_no_head_no_checkout(self):
  174. f1_1 = make_object(Blob, data=b'f1')
  175. commit_spec = [[1]]
  176. trees = {1: [(b'f1', f1_1), (b'f2', f1_1)]}
  177. (c1, ) = build_commit_graph(self.repo.object_store, commit_spec, trees)
  178. self.repo.refs[b"refs/heads/master"] = c1.id
  179. target_path = tempfile.mkdtemp()
  180. self.addCleanup(shutil.rmtree, target_path)
  181. errstream = BytesIO()
  182. r = porcelain.clone(
  183. self.repo.path, target_path, checkout=True, errstream=errstream)
  184. r.close()
  185. class InitTests(TestCase):
  186. def test_non_bare(self):
  187. repo_dir = tempfile.mkdtemp()
  188. self.addCleanup(shutil.rmtree, repo_dir)
  189. porcelain.init(repo_dir)
  190. def test_bare(self):
  191. repo_dir = tempfile.mkdtemp()
  192. self.addCleanup(shutil.rmtree, repo_dir)
  193. porcelain.init(repo_dir, bare=True)
  194. class AddTests(PorcelainTestCase):
  195. def test_add_default_paths(self):
  196. # create a file for initial commit
  197. fullpath = os.path.join(self.repo.path, 'blah')
  198. with open(fullpath, 'w') as f:
  199. f.write("\n")
  200. porcelain.add(repo=self.repo.path, paths=[fullpath])
  201. porcelain.commit(repo=self.repo.path, message=b'test',
  202. author=b'test', committer=b'test')
  203. # Add a second test file and a file in a directory
  204. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  205. f.write("\n")
  206. os.mkdir(os.path.join(self.repo.path, 'adir'))
  207. with open(os.path.join(self.repo.path, 'adir', 'afile'), 'w') as f:
  208. f.write("\n")
  209. cwd = os.getcwd()
  210. try:
  211. os.chdir(self.repo.path)
  212. porcelain.add(self.repo.path)
  213. finally:
  214. os.chdir(cwd)
  215. # Check that foo was added and nothing in .git was modified
  216. index = self.repo.open_index()
  217. self.assertEqual(sorted(index), [b'adir/afile', b'blah', b'foo'])
  218. def test_add_default_paths_subdir(self):
  219. os.mkdir(os.path.join(self.repo.path, 'foo'))
  220. with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
  221. f.write("\n")
  222. with open(os.path.join(self.repo.path, 'foo', 'blie'), 'w') as f:
  223. f.write("\n")
  224. cwd = os.getcwd()
  225. try:
  226. os.chdir(os.path.join(self.repo.path, 'foo'))
  227. porcelain.add(repo=self.repo.path)
  228. porcelain.commit(repo=self.repo.path, message=b'test',
  229. author=b'test', committer=b'test')
  230. finally:
  231. os.chdir(cwd)
  232. index = self.repo.open_index()
  233. self.assertEqual(sorted(index), [b'foo/blie'])
  234. def test_add_file(self):
  235. fullpath = os.path.join(self.repo.path, 'foo')
  236. with open(fullpath, 'w') as f:
  237. f.write("BAR")
  238. porcelain.add(self.repo.path, paths=[fullpath])
  239. self.assertIn(b"foo", self.repo.open_index())
  240. def test_add_ignored(self):
  241. with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
  242. f.write("foo")
  243. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  244. f.write("BAR")
  245. with open(os.path.join(self.repo.path, 'bar'), 'w') as f:
  246. f.write("BAR")
  247. (added, ignored) = porcelain.add(self.repo.path, paths=[
  248. os.path.join(self.repo.path, "foo"),
  249. os.path.join(self.repo.path, "bar")])
  250. self.assertIn(b"bar", self.repo.open_index())
  251. self.assertEqual(set(['bar']), set(added))
  252. self.assertEqual(set(['foo']), ignored)
  253. def test_add_file_absolute_path(self):
  254. # Absolute paths are (not yet) supported
  255. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  256. f.write("BAR")
  257. porcelain.add(self.repo, paths=[os.path.join(self.repo.path, "foo")])
  258. self.assertIn(b"foo", self.repo.open_index())
  259. class RemoveTests(PorcelainTestCase):
  260. def test_remove_file(self):
  261. fullpath = os.path.join(self.repo.path, 'foo')
  262. with open(fullpath, 'w') as f:
  263. f.write("BAR")
  264. porcelain.add(self.repo.path, paths=[fullpath])
  265. porcelain.commit(repo=self.repo, message=b'test', author=b'test',
  266. committer=b'test')
  267. self.assertTrue(os.path.exists(os.path.join(self.repo.path, 'foo')))
  268. cwd = os.getcwd()
  269. try:
  270. os.chdir(self.repo.path)
  271. porcelain.remove(self.repo.path, paths=["foo"])
  272. finally:
  273. os.chdir(cwd)
  274. self.assertFalse(os.path.exists(os.path.join(self.repo.path, 'foo')))
  275. def test_remove_file_staged(self):
  276. fullpath = os.path.join(self.repo.path, 'foo')
  277. with open(fullpath, 'w') as f:
  278. f.write("BAR")
  279. cwd = os.getcwd()
  280. try:
  281. os.chdir(self.repo.path)
  282. porcelain.add(self.repo.path, paths=[fullpath])
  283. self.assertRaises(Exception, porcelain.rm, self.repo.path,
  284. paths=["foo"])
  285. finally:
  286. os.chdir(cwd)
  287. class LogTests(PorcelainTestCase):
  288. def test_simple(self):
  289. c1, c2, c3 = build_commit_graph(
  290. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  291. self.repo.refs[b"HEAD"] = c3.id
  292. outstream = StringIO()
  293. porcelain.log(self.repo.path, outstream=outstream)
  294. self.assertEqual(3, outstream.getvalue().count("-" * 50))
  295. def test_max_entries(self):
  296. c1, c2, c3 = build_commit_graph(
  297. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  298. self.repo.refs[b"HEAD"] = c3.id
  299. outstream = StringIO()
  300. porcelain.log(self.repo.path, outstream=outstream, max_entries=1)
  301. self.assertEqual(1, outstream.getvalue().count("-" * 50))
  302. class ShowTests(PorcelainTestCase):
  303. def test_nolist(self):
  304. c1, c2, c3 = build_commit_graph(
  305. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  306. self.repo.refs[b"HEAD"] = c3.id
  307. outstream = StringIO()
  308. porcelain.show(self.repo.path, objects=c3.id, outstream=outstream)
  309. self.assertTrue(outstream.getvalue().startswith("-" * 50))
  310. def test_simple(self):
  311. c1, c2, c3 = build_commit_graph(
  312. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  313. self.repo.refs[b"HEAD"] = c3.id
  314. outstream = StringIO()
  315. porcelain.show(self.repo.path, objects=[c3.id], outstream=outstream)
  316. self.assertTrue(outstream.getvalue().startswith("-" * 50))
  317. def test_blob(self):
  318. b = Blob.from_string(b"The Foo\n")
  319. self.repo.object_store.add_object(b)
  320. outstream = StringIO()
  321. porcelain.show(self.repo.path, objects=[b.id], outstream=outstream)
  322. self.assertEqual(outstream.getvalue(), "The Foo\n")
  323. def test_commit_no_parent(self):
  324. a = Blob.from_string(b"The Foo\n")
  325. ta = Tree()
  326. ta.add(b"somename", 0o100644, a.id)
  327. ca = make_commit(tree=ta.id)
  328. self.repo.object_store.add_objects([(a, None), (ta, None), (ca, None)])
  329. outstream = StringIO()
  330. porcelain.show(self.repo.path, objects=[ca.id], outstream=outstream)
  331. self.assertMultiLineEqual(outstream.getvalue(), """\
  332. --------------------------------------------------
  333. commit: 344da06c1bb85901270b3e8875c988a027ec087d
  334. Author: Test Author <test@nodomain.com>
  335. Committer: Test Committer <test@nodomain.com>
  336. Date: Fri Jan 01 2010 00:00:00 +0000
  337. Test message.
  338. diff --git /dev/null b/somename
  339. new mode 100644
  340. index 0000000..ea5c7bf 100644
  341. --- /dev/null
  342. +++ b/somename
  343. @@ -1,0 +1,1 @@
  344. +The Foo
  345. """)
  346. def test_commit_with_change(self):
  347. a = Blob.from_string(b"The Foo\n")
  348. ta = Tree()
  349. ta.add(b"somename", 0o100644, a.id)
  350. ca = make_commit(tree=ta.id)
  351. b = Blob.from_string(b"The Bar\n")
  352. tb = Tree()
  353. tb.add(b"somename", 0o100644, b.id)
  354. cb = make_commit(tree=tb.id, parents=[ca.id])
  355. self.repo.object_store.add_objects(
  356. [(a, None), (b, None), (ta, None), (tb, None),
  357. (ca, None), (cb, None)])
  358. outstream = StringIO()
  359. porcelain.show(self.repo.path, objects=[cb.id], outstream=outstream)
  360. self.assertMultiLineEqual(outstream.getvalue(), """\
  361. --------------------------------------------------
  362. commit: 2c6b6c9cb72c130956657e1fdae58e5b103744fa
  363. Author: Test Author <test@nodomain.com>
  364. Committer: Test Committer <test@nodomain.com>
  365. Date: Fri Jan 01 2010 00:00:00 +0000
  366. Test message.
  367. diff --git a/somename b/somename
  368. index ea5c7bf..fd38bcb 100644
  369. --- a/somename
  370. +++ b/somename
  371. @@ -1,1 +1,1 @@
  372. -The Foo
  373. +The Bar
  374. """)
  375. class SymbolicRefTests(PorcelainTestCase):
  376. def test_set_wrong_symbolic_ref(self):
  377. c1, c2, c3 = build_commit_graph(
  378. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  379. self.repo.refs[b"HEAD"] = c3.id
  380. self.assertRaises(ValueError, porcelain.symbolic_ref, self.repo.path,
  381. b'foobar')
  382. def test_set_force_wrong_symbolic_ref(self):
  383. c1, c2, c3 = build_commit_graph(
  384. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  385. self.repo.refs[b"HEAD"] = c3.id
  386. porcelain.symbolic_ref(self.repo.path, b'force_foobar', force=True)
  387. # test if we actually changed the file
  388. with self.repo.get_named_file('HEAD') as f:
  389. new_ref = f.read()
  390. self.assertEqual(new_ref, b'ref: refs/heads/force_foobar\n')
  391. def test_set_symbolic_ref(self):
  392. c1, c2, c3 = build_commit_graph(
  393. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  394. self.repo.refs[b"HEAD"] = c3.id
  395. porcelain.symbolic_ref(self.repo.path, b'master')
  396. def test_set_symbolic_ref_other_than_master(self):
  397. c1, c2, c3 = build_commit_graph(
  398. self.repo.object_store, [[1], [2, 1], [3, 1, 2]],
  399. attrs=dict(refs='develop'))
  400. self.repo.refs[b"HEAD"] = c3.id
  401. self.repo.refs[b"refs/heads/develop"] = c3.id
  402. porcelain.symbolic_ref(self.repo.path, b'develop')
  403. # test if we actually changed the file
  404. with self.repo.get_named_file('HEAD') as f:
  405. new_ref = f.read()
  406. self.assertEqual(new_ref, b'ref: refs/heads/develop\n')
  407. class DiffTreeTests(PorcelainTestCase):
  408. def test_empty(self):
  409. c1, c2, c3 = build_commit_graph(
  410. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  411. self.repo.refs[b"HEAD"] = c3.id
  412. outstream = BytesIO()
  413. porcelain.diff_tree(self.repo.path, c2.tree, c3.tree,
  414. outstream=outstream)
  415. self.assertEqual(outstream.getvalue(), b"")
  416. class CommitTreeTests(PorcelainTestCase):
  417. def test_simple(self):
  418. c1, c2, c3 = build_commit_graph(
  419. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  420. b = Blob()
  421. b.data = b"foo the bar"
  422. t = Tree()
  423. t.add(b"somename", 0o100644, b.id)
  424. self.repo.object_store.add_object(t)
  425. self.repo.object_store.add_object(b)
  426. sha = porcelain.commit_tree(
  427. self.repo.path, t.id, message=b"Withcommit.",
  428. author=b"Joe <joe@example.com>",
  429. committer=b"Jane <jane@example.com>")
  430. self.assertTrue(isinstance(sha, bytes))
  431. self.assertEqual(len(sha), 40)
  432. class RevListTests(PorcelainTestCase):
  433. def test_simple(self):
  434. c1, c2, c3 = build_commit_graph(
  435. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  436. outstream = BytesIO()
  437. porcelain.rev_list(
  438. self.repo.path, [c3.id], outstream=outstream)
  439. self.assertEqual(
  440. c3.id + b"\n" +
  441. c2.id + b"\n" +
  442. c1.id + b"\n",
  443. outstream.getvalue())
  444. class TagCreateTests(PorcelainTestCase):
  445. def test_annotated(self):
  446. c1, c2, c3 = build_commit_graph(
  447. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  448. self.repo.refs[b"HEAD"] = c3.id
  449. porcelain.tag_create(self.repo.path, b"tryme", b'foo <foo@bar.com>',
  450. b'bar', annotated=True)
  451. tags = self.repo.refs.as_dict(b"refs/tags")
  452. self.assertEqual(list(tags.keys()), [b"tryme"])
  453. tag = self.repo[b'refs/tags/tryme']
  454. self.assertTrue(isinstance(tag, Tag))
  455. self.assertEqual(b"foo <foo@bar.com>", tag.tagger)
  456. self.assertEqual(b"bar", tag.message)
  457. self.assertLess(time.time() - tag.tag_time, 5)
  458. def test_unannotated(self):
  459. c1, c2, c3 = build_commit_graph(
  460. self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  461. self.repo.refs[b"HEAD"] = c3.id
  462. porcelain.tag_create(self.repo.path, b"tryme", annotated=False)
  463. tags = self.repo.refs.as_dict(b"refs/tags")
  464. self.assertEqual(list(tags.keys()), [b"tryme"])
  465. self.repo[b'refs/tags/tryme']
  466. self.assertEqual(list(tags.values()), [self.repo.head()])
  467. class TagListTests(PorcelainTestCase):
  468. def test_empty(self):
  469. tags = porcelain.tag_list(self.repo.path)
  470. self.assertEqual([], tags)
  471. def test_simple(self):
  472. self.repo.refs[b"refs/tags/foo"] = b"aa" * 20
  473. self.repo.refs[b"refs/tags/bar/bla"] = b"bb" * 20
  474. tags = porcelain.tag_list(self.repo.path)
  475. self.assertEqual([b"bar/bla", b"foo"], tags)
  476. class TagDeleteTests(PorcelainTestCase):
  477. def test_simple(self):
  478. [c1] = build_commit_graph(self.repo.object_store, [[1]])
  479. self.repo[b"HEAD"] = c1.id
  480. porcelain.tag_create(self.repo, b'foo')
  481. self.assertTrue(b"foo" in porcelain.tag_list(self.repo))
  482. porcelain.tag_delete(self.repo, b'foo')
  483. self.assertFalse(b"foo" in porcelain.tag_list(self.repo))
  484. class ResetTests(PorcelainTestCase):
  485. def test_hard_head(self):
  486. fullpath = os.path.join(self.repo.path, 'foo')
  487. with open(fullpath, 'w') as f:
  488. f.write("BAR")
  489. porcelain.add(self.repo.path, paths=[fullpath])
  490. porcelain.commit(self.repo.path, message=b"Some message",
  491. committer=b"Jane <jane@example.com>",
  492. author=b"John <john@example.com>")
  493. with open(os.path.join(self.repo.path, 'foo'), 'wb') as f:
  494. f.write(b"OOH")
  495. porcelain.reset(self.repo, "hard", b"HEAD")
  496. index = self.repo.open_index()
  497. changes = list(tree_changes(self.repo,
  498. index.commit(self.repo.object_store),
  499. self.repo[b'HEAD'].tree))
  500. self.assertEqual([], changes)
  501. def test_hard_commit(self):
  502. fullpath = os.path.join(self.repo.path, 'foo')
  503. with open(fullpath, 'w') as f:
  504. f.write("BAR")
  505. porcelain.add(self.repo.path, paths=[fullpath])
  506. sha = porcelain.commit(self.repo.path, message=b"Some message",
  507. committer=b"Jane <jane@example.com>",
  508. author=b"John <john@example.com>")
  509. with open(fullpath, 'wb') as f:
  510. f.write(b"BAZ")
  511. porcelain.add(self.repo.path, paths=[fullpath])
  512. porcelain.commit(self.repo.path, message=b"Some other message",
  513. committer=b"Jane <jane@example.com>",
  514. author=b"John <john@example.com>")
  515. porcelain.reset(self.repo, "hard", sha)
  516. index = self.repo.open_index()
  517. changes = list(tree_changes(self.repo,
  518. index.commit(self.repo.object_store),
  519. self.repo[sha].tree))
  520. self.assertEqual([], changes)
  521. class PushTests(PorcelainTestCase):
  522. def test_simple(self):
  523. """
  524. Basic test of porcelain push where self.repo is the remote. First
  525. clone the remote, commit a file to the clone, then push the changes
  526. back to the remote.
  527. """
  528. outstream = BytesIO()
  529. errstream = BytesIO()
  530. porcelain.commit(repo=self.repo.path, message=b'init',
  531. author=b'', committer=b'')
  532. # Setup target repo cloned from temp test repo
  533. clone_path = tempfile.mkdtemp()
  534. self.addCleanup(shutil.rmtree, clone_path)
  535. target_repo = porcelain.clone(self.repo.path, target=clone_path,
  536. errstream=errstream)
  537. try:
  538. self.assertEqual(target_repo[b'HEAD'], self.repo[b'HEAD'])
  539. finally:
  540. target_repo.close()
  541. # create a second file to be pushed back to origin
  542. handle, fullpath = tempfile.mkstemp(dir=clone_path)
  543. os.close(handle)
  544. porcelain.add(repo=clone_path, paths=[fullpath])
  545. porcelain.commit(repo=clone_path, message=b'push',
  546. author=b'', committer=b'')
  547. # Setup a non-checked out branch in the remote
  548. refs_path = b"refs/heads/foo"
  549. new_id = self.repo[b'HEAD'].id
  550. self.assertNotEqual(new_id, ZERO_SHA)
  551. self.repo.refs[refs_path] = new_id
  552. # Push to the remote
  553. porcelain.push(clone_path, self.repo.path, b"HEAD:" + refs_path,
  554. outstream=outstream, errstream=errstream)
  555. # Check that the target and source
  556. with Repo(clone_path) as r_clone:
  557. self.assertEqual({
  558. b'HEAD': new_id,
  559. b'refs/heads/foo': r_clone[b'HEAD'].id,
  560. b'refs/heads/master': new_id,
  561. }, self.repo.get_refs())
  562. self.assertEqual(r_clone[b'HEAD'].id, self.repo[refs_path].id)
  563. # Get the change in the target repo corresponding to the add
  564. # this will be in the foo branch.
  565. change = list(tree_changes(self.repo, self.repo[b'HEAD'].tree,
  566. self.repo[b'refs/heads/foo'].tree))[0]
  567. self.assertEqual(os.path.basename(fullpath),
  568. change.new.path.decode('ascii'))
  569. def test_delete(self):
  570. """Basic test of porcelain push, removing a branch.
  571. """
  572. outstream = BytesIO()
  573. errstream = BytesIO()
  574. porcelain.commit(repo=self.repo.path, message=b'init',
  575. author=b'', committer=b'')
  576. # Setup target repo cloned from temp test repo
  577. clone_path = tempfile.mkdtemp()
  578. self.addCleanup(shutil.rmtree, clone_path)
  579. target_repo = porcelain.clone(self.repo.path, target=clone_path,
  580. errstream=errstream)
  581. target_repo.close()
  582. # Setup a non-checked out branch in the remote
  583. refs_path = b"refs/heads/foo"
  584. new_id = self.repo[b'HEAD'].id
  585. self.assertNotEqual(new_id, ZERO_SHA)
  586. self.repo.refs[refs_path] = new_id
  587. # Push to the remote
  588. porcelain.push(clone_path, self.repo.path, b":" + refs_path,
  589. outstream=outstream, errstream=errstream)
  590. self.assertEqual({
  591. b'HEAD': new_id,
  592. b'refs/heads/master': new_id,
  593. }, self.repo.get_refs())
  594. class PullTests(PorcelainTestCase):
  595. def setUp(self):
  596. super(PullTests, self).setUp()
  597. # create a file for initial commit
  598. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  599. os.close(handle)
  600. porcelain.add(repo=self.repo.path, paths=fullpath)
  601. porcelain.commit(repo=self.repo.path, message=b'test',
  602. author=b'test', committer=b'test')
  603. # Setup target repo
  604. self.target_path = tempfile.mkdtemp()
  605. self.addCleanup(shutil.rmtree, self.target_path)
  606. target_repo = porcelain.clone(self.repo.path, target=self.target_path,
  607. errstream=BytesIO())
  608. target_repo.close()
  609. # create a second file to be pushed
  610. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  611. os.close(handle)
  612. porcelain.add(repo=self.repo.path, paths=fullpath)
  613. porcelain.commit(repo=self.repo.path, message=b'test2',
  614. author=b'test2', committer=b'test2')
  615. self.assertTrue(b'refs/heads/master' in self.repo.refs)
  616. self.assertTrue(b'refs/heads/master' in target_repo.refs)
  617. def test_simple(self):
  618. outstream = BytesIO()
  619. errstream = BytesIO()
  620. # Pull changes into the cloned repo
  621. porcelain.pull(self.target_path, self.repo.path, b'refs/heads/master',
  622. outstream=outstream, errstream=errstream)
  623. # Check the target repo for pushed changes
  624. with Repo(self.target_path) as r:
  625. self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
  626. def test_no_refspec(self):
  627. outstream = BytesIO()
  628. errstream = BytesIO()
  629. # Pull changes into the cloned repo
  630. porcelain.pull(self.target_path, self.repo.path, outstream=outstream,
  631. errstream=errstream)
  632. # Check the target repo for pushed changes
  633. with Repo(self.target_path) as r:
  634. self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
  635. class StatusTests(PorcelainTestCase):
  636. def test_empty(self):
  637. results = porcelain.status(self.repo)
  638. self.assertEqual(
  639. {'add': [], 'delete': [], 'modify': []},
  640. results.staged)
  641. self.assertEqual([], results.unstaged)
  642. def test_status(self):
  643. """Integration test for `status` functionality."""
  644. # Commit a dummy file then modify it
  645. fullpath = os.path.join(self.repo.path, 'foo')
  646. with open(fullpath, 'w') as f:
  647. f.write('origstuff')
  648. porcelain.add(repo=self.repo.path, paths=[fullpath])
  649. porcelain.commit(repo=self.repo.path, message=b'test status',
  650. author=b'', committer=b'')
  651. # modify access and modify time of path
  652. os.utime(fullpath, (0, 0))
  653. with open(fullpath, 'wb') as f:
  654. f.write(b'stuff')
  655. # Make a dummy file and stage it
  656. filename_add = 'bar'
  657. fullpath = os.path.join(self.repo.path, filename_add)
  658. with open(fullpath, 'w') as f:
  659. f.write('stuff')
  660. porcelain.add(repo=self.repo.path, paths=fullpath)
  661. results = porcelain.status(self.repo)
  662. self.assertEqual(results.staged['add'][0],
  663. filename_add.encode('ascii'))
  664. self.assertEqual(results.unstaged, [b'foo'])
  665. def test_get_tree_changes_add(self):
  666. """Unit test for get_tree_changes add."""
  667. # Make a dummy file, stage
  668. filename = 'bar'
  669. fullpath = os.path.join(self.repo.path, filename)
  670. with open(fullpath, 'w') as f:
  671. f.write('stuff')
  672. porcelain.add(repo=self.repo.path, paths=fullpath)
  673. porcelain.commit(repo=self.repo.path, message=b'test status',
  674. author=b'', committer=b'')
  675. filename = 'foo'
  676. fullpath = os.path.join(self.repo.path, filename)
  677. with open(fullpath, 'w') as f:
  678. f.write('stuff')
  679. porcelain.add(repo=self.repo.path, paths=fullpath)
  680. changes = porcelain.get_tree_changes(self.repo.path)
  681. self.assertEqual(changes['add'][0], filename.encode('ascii'))
  682. self.assertEqual(len(changes['add']), 1)
  683. self.assertEqual(len(changes['modify']), 0)
  684. self.assertEqual(len(changes['delete']), 0)
  685. def test_get_tree_changes_modify(self):
  686. """Unit test for get_tree_changes modify."""
  687. # Make a dummy file, stage, commit, modify
  688. filename = 'foo'
  689. fullpath = os.path.join(self.repo.path, filename)
  690. with open(fullpath, 'w') as f:
  691. f.write('stuff')
  692. porcelain.add(repo=self.repo.path, paths=fullpath)
  693. porcelain.commit(repo=self.repo.path, message=b'test status',
  694. author=b'', committer=b'')
  695. with open(fullpath, 'w') as f:
  696. f.write('otherstuff')
  697. porcelain.add(repo=self.repo.path, paths=fullpath)
  698. changes = porcelain.get_tree_changes(self.repo.path)
  699. self.assertEqual(changes['modify'][0], filename.encode('ascii'))
  700. self.assertEqual(len(changes['add']), 0)
  701. self.assertEqual(len(changes['modify']), 1)
  702. self.assertEqual(len(changes['delete']), 0)
  703. def test_get_tree_changes_delete(self):
  704. """Unit test for get_tree_changes delete."""
  705. # Make a dummy file, stage, commit, remove
  706. filename = 'foo'
  707. fullpath = os.path.join(self.repo.path, filename)
  708. with open(fullpath, 'w') as f:
  709. f.write('stuff')
  710. porcelain.add(repo=self.repo.path, paths=fullpath)
  711. porcelain.commit(repo=self.repo.path, message=b'test status',
  712. author=b'', committer=b'')
  713. cwd = os.getcwd()
  714. try:
  715. os.chdir(self.repo.path)
  716. porcelain.remove(repo=self.repo.path, paths=[filename])
  717. finally:
  718. os.chdir(cwd)
  719. changes = porcelain.get_tree_changes(self.repo.path)
  720. self.assertEqual(changes['delete'][0], filename.encode('ascii'))
  721. self.assertEqual(len(changes['add']), 0)
  722. self.assertEqual(len(changes['modify']), 0)
  723. self.assertEqual(len(changes['delete']), 1)
  724. def test_get_untracked_paths(self):
  725. with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
  726. f.write('ignored\n')
  727. with open(os.path.join(self.repo.path, 'ignored'), 'w') as f:
  728. f.write('blah\n')
  729. with open(os.path.join(self.repo.path, 'notignored'), 'w') as f:
  730. f.write('blah\n')
  731. self.assertEqual(
  732. set(['ignored', 'notignored', '.gitignore']),
  733. set(porcelain.get_untracked_paths(self.repo.path, self.repo.path,
  734. self.repo.open_index())))
  735. self.assertEqual(set(['.gitignore', 'notignored']),
  736. set(porcelain.status(self.repo).untracked))
  737. self.assertEqual(set(['.gitignore', 'notignored', 'ignored']),
  738. set(porcelain.status(self.repo, ignored=True)
  739. .untracked))
  740. def test_get_untracked_paths_nested(self):
  741. with open(os.path.join(self.repo.path, 'notignored'), 'w') as f:
  742. f.write('blah\n')
  743. subrepo = Repo.init(os.path.join(self.repo.path, 'nested'), mkdir=True)
  744. with open(os.path.join(subrepo.path, 'another'), 'w') as f:
  745. f.write('foo\n')
  746. self.assertEqual(
  747. set(['notignored']),
  748. set(porcelain.get_untracked_paths(self.repo.path, self.repo.path,
  749. self.repo.open_index())))
  750. self.assertEqual(
  751. set(['another']),
  752. set(porcelain.get_untracked_paths(subrepo.path, subrepo.path,
  753. subrepo.open_index())))
  754. # TODO(jelmer): Add test for dulwich.porcelain.daemon
  755. class UploadPackTests(PorcelainTestCase):
  756. """Tests for upload_pack."""
  757. def test_upload_pack(self):
  758. outf = BytesIO()
  759. exitcode = porcelain.upload_pack(
  760. self.repo.path, BytesIO(b"0000"), outf)
  761. outlines = outf.getvalue().splitlines()
  762. self.assertEqual([b"0000"], outlines)
  763. self.assertEqual(0, exitcode)
  764. class ReceivePackTests(PorcelainTestCase):
  765. """Tests for receive_pack."""
  766. def test_receive_pack(self):
  767. filename = 'foo'
  768. fullpath = os.path.join(self.repo.path, filename)
  769. with open(fullpath, 'w') as f:
  770. f.write('stuff')
  771. porcelain.add(repo=self.repo.path, paths=fullpath)
  772. self.repo.do_commit(message=b'test status',
  773. author=b'', committer=b'',
  774. author_timestamp=1402354300,
  775. commit_timestamp=1402354300, author_timezone=0,
  776. commit_timezone=0)
  777. outf = BytesIO()
  778. exitcode = porcelain.receive_pack(
  779. self.repo.path, BytesIO(b"0000"), outf)
  780. outlines = outf.getvalue().splitlines()
  781. self.assertEqual([
  782. b'00739e65bdcf4a22cdd4f3700604a275cd2aaf146b23 HEAD\x00 report-status ' # noqa: E501
  783. b'delete-refs quiet ofs-delta side-band-64k no-done',
  784. b'003f9e65bdcf4a22cdd4f3700604a275cd2aaf146b23 refs/heads/master',
  785. b'0000'], outlines)
  786. self.assertEqual(0, exitcode)
  787. class BranchListTests(PorcelainTestCase):
  788. def test_standard(self):
  789. self.assertEqual(set([]), set(porcelain.branch_list(self.repo)))
  790. def test_new_branch(self):
  791. [c1] = build_commit_graph(self.repo.object_store, [[1]])
  792. self.repo[b"HEAD"] = c1.id
  793. porcelain.branch_create(self.repo, b"foo")
  794. self.assertEqual(
  795. set([b"master", b"foo"]),
  796. set(porcelain.branch_list(self.repo)))
  797. class BranchCreateTests(PorcelainTestCase):
  798. def test_branch_exists(self):
  799. [c1] = build_commit_graph(self.repo.object_store, [[1]])
  800. self.repo[b"HEAD"] = c1.id
  801. porcelain.branch_create(self.repo, b"foo")
  802. self.assertRaises(KeyError, porcelain.branch_create, self.repo, b"foo")
  803. porcelain.branch_create(self.repo, b"foo", force=True)
  804. def test_new_branch(self):
  805. [c1] = build_commit_graph(self.repo.object_store, [[1]])
  806. self.repo[b"HEAD"] = c1.id
  807. porcelain.branch_create(self.repo, b"foo")
  808. self.assertEqual(
  809. set([b"master", b"foo"]),
  810. set(porcelain.branch_list(self.repo)))
  811. class BranchDeleteTests(PorcelainTestCase):
  812. def test_simple(self):
  813. [c1] = build_commit_graph(self.repo.object_store, [[1]])
  814. self.repo[b"HEAD"] = c1.id
  815. porcelain.branch_create(self.repo, b'foo')
  816. self.assertTrue(b"foo" in porcelain.branch_list(self.repo))
  817. porcelain.branch_delete(self.repo, b'foo')
  818. self.assertFalse(b"foo" in porcelain.branch_list(self.repo))
  819. class FetchTests(PorcelainTestCase):
  820. def test_simple(self):
  821. outstream = BytesIO()
  822. errstream = BytesIO()
  823. # create a file for initial commit
  824. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  825. os.close(handle)
  826. porcelain.add(repo=self.repo.path, paths=fullpath)
  827. porcelain.commit(repo=self.repo.path, message=b'test',
  828. author=b'test', committer=b'test')
  829. # Setup target repo
  830. target_path = tempfile.mkdtemp()
  831. self.addCleanup(shutil.rmtree, target_path)
  832. target_repo = porcelain.clone(self.repo.path, target=target_path,
  833. errstream=errstream)
  834. # create a second file to be pushed
  835. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  836. os.close(handle)
  837. porcelain.add(repo=self.repo.path, paths=fullpath)
  838. porcelain.commit(repo=self.repo.path, message=b'test2',
  839. author=b'test2', committer=b'test2')
  840. self.assertFalse(self.repo[b'HEAD'].id in target_repo)
  841. target_repo.close()
  842. # Fetch changes into the cloned repo
  843. porcelain.fetch(target_path, self.repo.path, outstream=outstream,
  844. errstream=errstream)
  845. # Check the target repo for pushed changes
  846. with Repo(target_path) as r:
  847. self.assertTrue(self.repo[b'HEAD'].id in r)
  848. class RepackTests(PorcelainTestCase):
  849. def test_empty(self):
  850. porcelain.repack(self.repo)
  851. def test_simple(self):
  852. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  853. os.close(handle)
  854. porcelain.add(repo=self.repo.path, paths=fullpath)
  855. porcelain.repack(self.repo)
  856. class LsTreeTests(PorcelainTestCase):
  857. def test_empty(self):
  858. porcelain.commit(repo=self.repo.path, message=b'test status',
  859. author=b'', committer=b'')
  860. f = StringIO()
  861. porcelain.ls_tree(self.repo, b"HEAD", outstream=f)
  862. self.assertEqual(f.getvalue(), "")
  863. def test_simple(self):
  864. # Commit a dummy file then modify it
  865. fullpath = os.path.join(self.repo.path, 'foo')
  866. with open(fullpath, 'w') as f:
  867. f.write('origstuff')
  868. porcelain.add(repo=self.repo.path, paths=[fullpath])
  869. porcelain.commit(repo=self.repo.path, message=b'test status',
  870. author=b'', committer=b'')
  871. f = StringIO()
  872. porcelain.ls_tree(self.repo, b"HEAD", outstream=f)
  873. self.assertEqual(
  874. f.getvalue(),
  875. '100644 blob 8b82634d7eae019850bb883f06abf428c58bc9aa\tfoo\n')
  876. class LsRemoteTests(PorcelainTestCase):
  877. def test_empty(self):
  878. self.assertEqual({}, porcelain.ls_remote(self.repo.path))
  879. def test_some(self):
  880. cid = porcelain.commit(repo=self.repo.path, message=b'test status',
  881. author=b'', committer=b'')
  882. self.assertEqual({
  883. b'refs/heads/master': cid,
  884. b'HEAD': cid},
  885. porcelain.ls_remote(self.repo.path))
  886. class RemoteAddTests(PorcelainTestCase):
  887. def test_new(self):
  888. porcelain.remote_add(
  889. self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
  890. c = self.repo.get_config()
  891. self.assertEqual(
  892. c.get((b'remote', b'jelmer'), b'url'),
  893. b'git://jelmer.uk/code/dulwich')
  894. def test_exists(self):
  895. porcelain.remote_add(
  896. self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
  897. self.assertRaises(porcelain.RemoteExists, porcelain.remote_add,
  898. self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
  899. class CheckIgnoreTests(PorcelainTestCase):
  900. def test_check_ignored(self):
  901. with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
  902. f.write("foo")
  903. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  904. f.write("BAR")
  905. with open(os.path.join(self.repo.path, 'bar'), 'w') as f:
  906. f.write("BAR")
  907. self.assertEqual(
  908. ['foo'],
  909. list(porcelain.check_ignore(self.repo, ['foo'])))
  910. self.assertEqual([], list(porcelain.check_ignore(self.repo, ['bar'])))
  911. def test_check_added(self):
  912. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  913. f.write("BAR")
  914. self.repo.stage(['foo'])
  915. with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
  916. f.write("foo\n")
  917. self.assertEqual(
  918. [], list(porcelain.check_ignore(self.repo, ['foo'])))
  919. self.assertEqual(
  920. ['foo'],
  921. list(porcelain.check_ignore(self.repo, ['foo'], no_index=True)))