test_porcelain.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. # test_porcelain.py -- porcelain tests
  2. # Copyright (C) 2013 Jelmer Vernooij <jelmer@samba.org>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) a later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. """Tests for dulwich.porcelain."""
  19. from io import BytesIO
  20. import os
  21. import shutil
  22. import tarfile
  23. import tempfile
  24. from dulwich import porcelain
  25. from dulwich.diff_tree import tree_changes
  26. from dulwich.objects import (
  27. Blob,
  28. Tag,
  29. Tree,
  30. )
  31. from dulwich.repo import Repo
  32. from dulwich.tests import (
  33. TestCase,
  34. )
  35. from dulwich.tests.compat.utils import require_git_version
  36. from dulwich.tests.utils import (
  37. build_commit_graph,
  38. make_object,
  39. )
  40. class PorcelainTestCase(TestCase):
  41. def setUp(self):
  42. super(TestCase, self).setUp()
  43. repo_dir = tempfile.mkdtemp()
  44. self.addCleanup(shutil.rmtree, repo_dir)
  45. self.repo = Repo.init(repo_dir)
  46. class ArchiveTests(PorcelainTestCase):
  47. """Tests for the archive command."""
  48. def test_simple(self):
  49. # TODO(jelmer): Remove this once dulwich has its own implementation of archive.
  50. require_git_version((1, 5, 0))
  51. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1], [3, 1, 2]])
  52. self.repo.refs["refs/heads/master"] = c3.id
  53. out = BytesIO()
  54. err = BytesIO()
  55. porcelain.archive(self.repo.path, "refs/heads/master", outstream=out,
  56. errstream=err)
  57. self.assertEqual("", err.getvalue())
  58. tf = tarfile.TarFile(fileobj=out)
  59. self.addCleanup(tf.close)
  60. self.assertEqual([], tf.getnames())
  61. class UpdateServerInfoTests(PorcelainTestCase):
  62. def test_simple(self):
  63. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  64. [3, 1, 2]])
  65. self.repo.refs["refs/heads/foo"] = c3.id
  66. porcelain.update_server_info(self.repo.path)
  67. self.assertTrue(os.path.exists(os.path.join(self.repo.controldir(),
  68. 'info', 'refs')))
  69. class CommitTests(PorcelainTestCase):
  70. def test_custom_author(self):
  71. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  72. [3, 1, 2]])
  73. self.repo.refs["refs/heads/foo"] = c3.id
  74. sha = porcelain.commit(self.repo.path, message="Some message",
  75. author="Joe <joe@example.com>", committer="Bob <bob@example.com>")
  76. self.assertTrue(isinstance(sha, str))
  77. self.assertEqual(len(sha), 40)
  78. class CloneTests(PorcelainTestCase):
  79. def test_simple_local(self):
  80. f1_1 = make_object(Blob, data='f1')
  81. commit_spec = [[1], [2, 1], [3, 1, 2]]
  82. trees = {1: [('f1', f1_1), ('f2', f1_1)],
  83. 2: [('f1', f1_1), ('f2', f1_1)],
  84. 3: [('f1', f1_1), ('f2', f1_1)], }
  85. c1, c2, c3 = build_commit_graph(self.repo.object_store,
  86. commit_spec, trees)
  87. self.repo.refs["refs/heads/master"] = c3.id
  88. target_path = tempfile.mkdtemp()
  89. outstream = BytesIO()
  90. self.addCleanup(shutil.rmtree, target_path)
  91. r = porcelain.clone(self.repo.path, target_path,
  92. checkout=False, outstream=outstream)
  93. self.assertEqual(r.path, target_path)
  94. self.assertEqual(Repo(target_path).head(), c3.id)
  95. self.assertTrue('f1' not in os.listdir(target_path))
  96. self.assertTrue('f2' not in os.listdir(target_path))
  97. def test_simple_local_with_checkout(self):
  98. f1_1 = make_object(Blob, data='f1')
  99. commit_spec = [[1], [2, 1], [3, 1, 2]]
  100. trees = {1: [('f1', f1_1), ('f2', f1_1)],
  101. 2: [('f1', f1_1), ('f2', f1_1)],
  102. 3: [('f1', f1_1), ('f2', f1_1)], }
  103. c1, c2, c3 = build_commit_graph(self.repo.object_store,
  104. commit_spec, trees)
  105. self.repo.refs["refs/heads/master"] = c3.id
  106. target_path = tempfile.mkdtemp()
  107. outstream = BytesIO()
  108. self.addCleanup(shutil.rmtree, target_path)
  109. r = porcelain.clone(self.repo.path, target_path,
  110. checkout=True, outstream=outstream)
  111. self.assertEqual(r.path, target_path)
  112. self.assertEqual(Repo(target_path).head(), c3.id)
  113. self.assertTrue('f1' in os.listdir(target_path))
  114. self.assertTrue('f2' in os.listdir(target_path))
  115. def test_bare_local_with_checkout(self):
  116. f1_1 = make_object(Blob, data='f1')
  117. commit_spec = [[1], [2, 1], [3, 1, 2]]
  118. trees = {1: [('f1', f1_1), ('f2', f1_1)],
  119. 2: [('f1', f1_1), ('f2', f1_1)],
  120. 3: [('f1', f1_1), ('f2', f1_1)], }
  121. c1, c2, c3 = build_commit_graph(self.repo.object_store,
  122. commit_spec, trees)
  123. self.repo.refs["refs/heads/master"] = c3.id
  124. target_path = tempfile.mkdtemp()
  125. outstream = BytesIO()
  126. self.addCleanup(shutil.rmtree, target_path)
  127. r = porcelain.clone(self.repo.path, target_path,
  128. bare=True, outstream=outstream)
  129. self.assertEqual(r.path, target_path)
  130. self.assertEqual(Repo(target_path).head(), c3.id)
  131. self.assertFalse('f1' in os.listdir(target_path))
  132. self.assertFalse('f2' in os.listdir(target_path))
  133. def test_no_checkout_with_bare(self):
  134. f1_1 = make_object(Blob, data='f1')
  135. commit_spec = [[1]]
  136. trees = {1: [('f1', f1_1), ('f2', f1_1)]}
  137. (c1, ) = build_commit_graph(self.repo.object_store, commit_spec, trees)
  138. self.repo.refs["refs/heads/master"] = c1.id
  139. target_path = tempfile.mkdtemp()
  140. outstream = BytesIO()
  141. self.addCleanup(shutil.rmtree, target_path)
  142. self.assertRaises(ValueError, porcelain.clone, self.repo.path,
  143. target_path, checkout=True, bare=True, outstream=outstream)
  144. class InitTests(TestCase):
  145. def test_non_bare(self):
  146. repo_dir = tempfile.mkdtemp()
  147. self.addCleanup(shutil.rmtree, repo_dir)
  148. porcelain.init(repo_dir)
  149. def test_bare(self):
  150. repo_dir = tempfile.mkdtemp()
  151. self.addCleanup(shutil.rmtree, repo_dir)
  152. porcelain.init(repo_dir, bare=True)
  153. class AddTests(PorcelainTestCase):
  154. def test_add_default_paths(self):
  155. # create a file for initial commit
  156. with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
  157. f.write("\n")
  158. porcelain.add(repo=self.repo.path, paths=['blah'])
  159. porcelain.commit(repo=self.repo.path, message='test',
  160. author='test', committer='test')
  161. # Add a second test file and a file in a directory
  162. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  163. f.write("\n")
  164. os.mkdir(os.path.join(self.repo.path, 'adir'))
  165. with open(os.path.join(self.repo.path, 'adir', 'afile'), 'w') as f:
  166. f.write("\n")
  167. porcelain.add(self.repo.path)
  168. # Check that foo was added and nothing in .git was modified
  169. index = self.repo.open_index()
  170. self.assertEqual(list(index), ['blah', 'foo', 'adir/afile'])
  171. def test_add_file(self):
  172. with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
  173. f.write("BAR")
  174. porcelain.add(self.repo.path, paths=["foo"])
  175. class RemoveTests(PorcelainTestCase):
  176. def test_remove_file(self):
  177. f = open(os.path.join(self.repo.path, 'foo'), 'w')
  178. try:
  179. f.write("BAR")
  180. finally:
  181. f.close()
  182. porcelain.add(self.repo.path, paths=["foo"])
  183. porcelain.rm(self.repo.path, paths=["foo"])
  184. class LogTests(PorcelainTestCase):
  185. def test_simple(self):
  186. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  187. [3, 1, 2]])
  188. self.repo.refs["HEAD"] = c3.id
  189. outstream = BytesIO()
  190. porcelain.log(self.repo.path, outstream=outstream)
  191. self.assertEqual(3, outstream.getvalue().count("-" * 50))
  192. def test_max_entries(self):
  193. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  194. [3, 1, 2]])
  195. self.repo.refs["HEAD"] = c3.id
  196. outstream = BytesIO()
  197. porcelain.log(self.repo.path, outstream=outstream, max_entries=1)
  198. self.assertEqual(1, outstream.getvalue().count("-" * 50))
  199. class ShowTests(PorcelainTestCase):
  200. def test_nolist(self):
  201. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  202. [3, 1, 2]])
  203. self.repo.refs["HEAD"] = c3.id
  204. outstream = BytesIO()
  205. porcelain.show(self.repo.path, objects=c3.id, outstream=outstream)
  206. self.assertTrue(outstream.getvalue().startswith("-" * 50))
  207. def test_simple(self):
  208. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  209. [3, 1, 2]])
  210. self.repo.refs["HEAD"] = c3.id
  211. outstream = BytesIO()
  212. porcelain.show(self.repo.path, objects=[c3.id], outstream=outstream)
  213. self.assertTrue(outstream.getvalue().startswith("-" * 50))
  214. def test_blob(self):
  215. b = Blob.from_string("The Foo\n")
  216. self.repo.object_store.add_object(b)
  217. outstream = BytesIO()
  218. porcelain.show(self.repo.path, objects=[b.id], outstream=outstream)
  219. self.assertEqual(outstream.getvalue(), "The Foo\n")
  220. class SymbolicRefTests(PorcelainTestCase):
  221. def test_set_wrong_symbolic_ref(self):
  222. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  223. [3, 1, 2]])
  224. self.repo.refs["HEAD"] = c3.id
  225. self.assertRaises(ValueError, porcelain.symbolic_ref, self.repo.path, 'foobar')
  226. def test_set_force_wrong_symbolic_ref(self):
  227. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  228. [3, 1, 2]])
  229. self.repo.refs["HEAD"] = c3.id
  230. porcelain.symbolic_ref(self.repo.path, 'force_foobar', force=True)
  231. #test if we actually changed the file
  232. with self.repo.get_named_file('HEAD') as f:
  233. new_ref = f.read()
  234. self.assertEqual(new_ref, b'ref: refs/heads/force_foobar\n')
  235. def test_set_symbolic_ref(self):
  236. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  237. [3, 1, 2]])
  238. self.repo.refs["HEAD"] = c3.id
  239. porcelain.symbolic_ref(self.repo.path, 'master')
  240. def test_set_symbolic_ref_other_than_master(self):
  241. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  242. [3, 1, 2]], attrs=dict(refs='develop'))
  243. self.repo.refs["HEAD"] = c3.id
  244. self.repo.refs["refs/heads/develop"] = c3.id
  245. porcelain.symbolic_ref(self.repo.path, 'develop')
  246. #test if we actually changed the file
  247. with self.repo.get_named_file('HEAD') as f:
  248. new_ref = f.read()
  249. self.assertEqual(new_ref, b'ref: refs/heads/develop\n')
  250. class DiffTreeTests(PorcelainTestCase):
  251. def test_empty(self):
  252. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  253. [3, 1, 2]])
  254. self.repo.refs["HEAD"] = c3.id
  255. outstream = BytesIO()
  256. porcelain.diff_tree(self.repo.path, c2.tree, c3.tree, outstream=outstream)
  257. self.assertEqual(outstream.getvalue(), "")
  258. class CommitTreeTests(PorcelainTestCase):
  259. def test_simple(self):
  260. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  261. [3, 1, 2]])
  262. b = Blob()
  263. b.data = "foo the bar"
  264. t = Tree()
  265. t.add("somename", 0o100644, b.id)
  266. self.repo.object_store.add_object(t)
  267. self.repo.object_store.add_object(b)
  268. sha = porcelain.commit_tree(
  269. self.repo.path, t.id, message="Withcommit.",
  270. author="Joe <joe@example.com>",
  271. committer="Jane <jane@example.com>")
  272. self.assertTrue(isinstance(sha, str))
  273. self.assertEqual(len(sha), 40)
  274. class RevListTests(PorcelainTestCase):
  275. def test_simple(self):
  276. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  277. [3, 1, 2]])
  278. outstream = BytesIO()
  279. porcelain.rev_list(
  280. self.repo.path, [c3.id], outstream=outstream)
  281. self.assertEqual(
  282. "%s\n%s\n%s\n" % (c3.id, c2.id, c1.id),
  283. outstream.getvalue())
  284. class TagTests(PorcelainTestCase):
  285. def test_annotated(self):
  286. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  287. [3, 1, 2]])
  288. self.repo.refs["HEAD"] = c3.id
  289. porcelain.tag(self.repo.path, "tryme", 'foo <foo@bar.com>', 'bar',
  290. annotated=True)
  291. tags = self.repo.refs.as_dict("refs/tags")
  292. self.assertEqual(tags.keys(), ["tryme"])
  293. tag = self.repo['refs/tags/tryme']
  294. self.assertTrue(isinstance(tag, Tag))
  295. self.assertEqual("foo <foo@bar.com>", tag.tagger)
  296. self.assertEqual("bar", tag.message)
  297. def test_unannotated(self):
  298. c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
  299. [3, 1, 2]])
  300. self.repo.refs["HEAD"] = c3.id
  301. porcelain.tag(self.repo.path, "tryme", annotated=False)
  302. tags = self.repo.refs.as_dict("refs/tags")
  303. self.assertEqual(tags.keys(), ["tryme"])
  304. self.repo['refs/tags/tryme']
  305. self.assertEqual(tags.values(), [self.repo.head()])
  306. class ListTagsTests(PorcelainTestCase):
  307. def test_empty(self):
  308. tags = porcelain.list_tags(self.repo.path)
  309. self.assertEqual([], tags)
  310. def test_simple(self):
  311. self.repo.refs["refs/tags/foo"] = "aa" * 20
  312. self.repo.refs["refs/tags/bar/bla"] = "bb" * 20
  313. tags = porcelain.list_tags(self.repo.path)
  314. self.assertEqual(["bar/bla", "foo"], tags)
  315. class ResetTests(PorcelainTestCase):
  316. def test_hard_head(self):
  317. f = open(os.path.join(self.repo.path, 'foo'), 'w')
  318. try:
  319. f.write("BAR")
  320. finally:
  321. f.close()
  322. porcelain.add(self.repo.path, paths=["foo"])
  323. porcelain.commit(self.repo.path, message="Some message",
  324. committer="Jane <jane@example.com>",
  325. author="John <john@example.com>")
  326. f = open(os.path.join(self.repo.path, 'foo'), 'w')
  327. try:
  328. f.write("OOH")
  329. finally:
  330. f.close()
  331. porcelain.reset(self.repo, "hard", "HEAD")
  332. index = self.repo.open_index()
  333. changes = list(tree_changes(self.repo,
  334. index.commit(self.repo.object_store),
  335. self.repo['HEAD'].tree))
  336. self.assertEqual([], changes)
  337. class PushTests(PorcelainTestCase):
  338. def test_simple(self):
  339. """
  340. Basic test of porcelain push where self.repo is the remote. First
  341. clone the remote, commit a file to the clone, then push the changes
  342. back to the remote.
  343. """
  344. outstream = BytesIO()
  345. errstream = BytesIO()
  346. porcelain.commit(repo=self.repo.path, message='init',
  347. author='', committer='')
  348. # Setup target repo cloned from temp test repo
  349. clone_path = tempfile.mkdtemp()
  350. porcelain.clone(self.repo.path, target=clone_path, outstream=outstream)
  351. # create a second file to be pushed back to origin
  352. handle, fullpath = tempfile.mkstemp(dir=clone_path)
  353. porcelain.add(repo=clone_path, paths=[os.path.basename(fullpath)])
  354. porcelain.commit(repo=clone_path, message='push',
  355. author='', committer='')
  356. # Setup a non-checked out branch in the remote
  357. refs_path = os.path.join('refs', 'heads', 'foo')
  358. self.repo[refs_path] = self.repo['HEAD']
  359. # Push to the remote
  360. porcelain.push(clone_path, self.repo.path, refs_path, outstream=outstream,
  361. errstream=errstream)
  362. # Check that the target and source
  363. r_clone = Repo(clone_path)
  364. # Get the change in the target repo corresponding to the add
  365. # this will be in the foo branch.
  366. change = list(tree_changes(self.repo, self.repo['HEAD'].tree,
  367. self.repo['refs/heads/foo'].tree))[0]
  368. self.assertEqual(r_clone['HEAD'].id, self.repo[refs_path].id)
  369. self.assertEqual(os.path.basename(fullpath), change.new.path)
  370. class PullTests(PorcelainTestCase):
  371. def test_simple(self):
  372. outstream = BytesIO()
  373. errstream = BytesIO()
  374. # create a file for initial commit
  375. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  376. filename = os.path.basename(fullpath)
  377. porcelain.add(repo=self.repo.path, paths=filename)
  378. porcelain.commit(repo=self.repo.path, message='test',
  379. author='test', committer='test')
  380. # Setup target repo
  381. target_path = tempfile.mkdtemp()
  382. porcelain.clone(self.repo.path, target=target_path, outstream=outstream)
  383. # create a second file to be pushed
  384. handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
  385. filename = os.path.basename(fullpath)
  386. porcelain.add(repo=self.repo.path, paths=filename)
  387. porcelain.commit(repo=self.repo.path, message='test2',
  388. author='test2', committer='test2')
  389. # Pull changes into the cloned repo
  390. porcelain.pull(target_path, self.repo.path, 'refs/heads/master',
  391. outstream=outstream, errstream=errstream)
  392. # Check the target repo for pushed changes
  393. r = Repo(target_path)
  394. self.assertEqual(r['HEAD'].id, self.repo['HEAD'].id)
  395. class StatusTests(PorcelainTestCase):
  396. def test_status(self):
  397. """Integration test for `status` functionality."""
  398. # Commit a dummy file then modify it
  399. fullpath = os.path.join(self.repo.path, 'foo')
  400. with open(fullpath, 'w') as f:
  401. f.write('origstuff')
  402. porcelain.add(repo=self.repo.path, paths=['foo'])
  403. porcelain.commit(repo=self.repo.path, message='test status',
  404. author='', committer='')
  405. # modify access and modify time of path
  406. os.utime(fullpath, (0, 0))
  407. with open(fullpath, 'w') as f:
  408. f.write('stuff')
  409. # Make a dummy file and stage it
  410. filename_add = 'bar'
  411. fullpath = os.path.join(self.repo.path, filename_add)
  412. with open(fullpath, 'w') as f:
  413. f.write('stuff')
  414. porcelain.add(repo=self.repo.path, paths=filename_add)
  415. results = porcelain.status(self.repo)
  416. self.assertEqual(results.staged['add'][0], filename_add)
  417. self.assertEqual(results.unstaged, ['foo'])
  418. def test_get_tree_changes_add(self):
  419. """Unit test for get_tree_changes add."""
  420. # Make a dummy file, stage
  421. filename = 'bar'
  422. with open(os.path.join(self.repo.path, filename), 'w') as f:
  423. f.write('stuff')
  424. porcelain.add(repo=self.repo.path, paths=filename)
  425. porcelain.commit(repo=self.repo.path, message='test status',
  426. author='', committer='')
  427. filename = 'foo'
  428. with open(os.path.join(self.repo.path, filename), 'w') as f:
  429. f.write('stuff')
  430. porcelain.add(repo=self.repo.path, paths=filename)
  431. changes = porcelain.get_tree_changes(self.repo.path)
  432. self.assertEqual(changes['add'][0], filename)
  433. self.assertEqual(len(changes['add']), 1)
  434. self.assertEqual(len(changes['modify']), 0)
  435. self.assertEqual(len(changes['delete']), 0)
  436. def test_get_tree_changes_modify(self):
  437. """Unit test for get_tree_changes modify."""
  438. # Make a dummy file, stage, commit, modify
  439. filename = 'foo'
  440. fullpath = os.path.join(self.repo.path, filename)
  441. with open(fullpath, 'w') as f:
  442. f.write('stuff')
  443. porcelain.add(repo=self.repo.path, paths=filename)
  444. porcelain.commit(repo=self.repo.path, message='test status',
  445. author='', committer='')
  446. with open(fullpath, 'w') as f:
  447. f.write('otherstuff')
  448. porcelain.add(repo=self.repo.path, paths=filename)
  449. changes = porcelain.get_tree_changes(self.repo.path)
  450. self.assertEqual(changes['modify'][0], filename)
  451. self.assertEqual(len(changes['add']), 0)
  452. self.assertEqual(len(changes['modify']), 1)
  453. self.assertEqual(len(changes['delete']), 0)
  454. def test_get_tree_changes_delete(self):
  455. """Unit test for get_tree_changes delete."""
  456. # Make a dummy file, stage, commit, remove
  457. filename = 'foo'
  458. with open(os.path.join(self.repo.path, filename), 'w') as f:
  459. f.write('stuff')
  460. porcelain.add(repo=self.repo.path, paths=filename)
  461. porcelain.commit(repo=self.repo.path, message='test status',
  462. author='', committer='')
  463. porcelain.rm(repo=self.repo.path, paths=[filename])
  464. changes = porcelain.get_tree_changes(self.repo.path)
  465. self.assertEqual(changes['delete'][0], filename)
  466. self.assertEqual(len(changes['add']), 0)
  467. self.assertEqual(len(changes['modify']), 0)
  468. self.assertEqual(len(changes['delete']), 1)
  469. # TODO(jelmer): Add test for dulwich.porcelain.daemon