Dulwich.io dulwich / 7b3ae1e
Add dulwich.porcelain.write_tree. Jelmer Vernooń≥ 17 days ago
4 changed file(s) with 36 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 0.19.10 UNRELEASED
1
2 IMPROVEMENTS
3
4 * Add `dulwich.porcelain.write_tree`.
5 (Jelmer Vernooń≥)
16
27 0.19.9 2018-11-17
38
385385 from dulwich import porcelain
386386 porcelain.web_daemon(gitdir, address=options.listen_address,
387387 port=options.port)
388
389
390 class cmd_write_tree(Command):
391
392 def run(self, args):
393 parser = optparse.OptionParser()
394 options, args = parser.parse_args(args)
395 sys.stdout.write('%s\n' % porcelain.write_tree('.'))
388396
389397
390398 class cmd_receive_pack(Command):
688696 "update-server-info": cmd_update_server_info,
689697 "upload-pack": cmd_upload_pack,
690698 "web-daemon": cmd_web_daemon,
699 "write-tree": cmd_write_tree,
691700 }
692701
693702 if len(sys.argv) < 2:
14101410 r.object_store.__getitem__,
14111411 base_tree, path)
14121412 return r[sha]
1413
1414
1415 def write_tree(repo):
1416 """Write a tree object from the index.
1417
1418 :param repo: Repository for which to write tree
1419 :return: tree id for the tree that was written
1420 """
1421 with open_repo_closing(repo) as r:
1422 return r.open_index().commit(r.object_store)
15611561 self.assertRaises(
15621562 KeyError,
15631563 porcelain.get_object_by_path, self.repo, 'foo')
1564
1565
1566 class WriteTreeTests(PorcelainTestCase):
1567
1568 def test_simple(self):
1569 fullpath = os.path.join(self.repo.path, 'foo')
1570 with open(fullpath, 'w') as f:
1571 f.write("BAR")
1572 porcelain.add(repo=self.repo.path, paths=[fullpath])
1573 self.assertEqual(
1574 b'd2092c8a9f311f0311083bf8d177f2ca0ab5b241',
1575 porcelain.write_tree(self.repo))