Dulwich.io dulwich / 8d4d28c
Add porcelain for diff-tree. Jelmer Vernooij 6 years ago
3 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
196196 def cmd_show(args):
197197 opts, args = getopt(args, "", [])
198198 porcelain.show(".")
199
200
201 def cmd_diff_tree(args):
202 opts, args = getopt(args, "", [])
203 if len(args) < 2:
204 print "Usage: dulwich diff-tree OLD-TREE NEW-TREE"
205 sys.exit(1)
206 porcelain.diff_tree(".", args[0], args[1])
199207
200208
201209 commands = {
214222 "add": cmd_add,
215223 "rm": cmd_rm,
216224 "show": cmd_show,
225 "diff-tree": cmd_diff_tree,
217226 }
218227
219228 if len(sys.argv) < 2:
214214 parent_commit = r[commit.parents[0]]
215215 print_commit(commit, outstream)
216216 write_tree_diff(outstream, r.object_store, parent_commit.tree, commit.tree)
217
218
219 def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
220 """Compares the content and mode of blobs found via two tree objects.
221
222 :param repo: Path to repository
223 :param old_tree: Id of old tree
224 :param new_tree: Id of new tree
225 :param outstream: Stream to write to
226 """
227 r = open_repo(repo)
228 write_tree_diff(outstream, r.object_store, old_tree, new_tree)
200200 #test if we actually changed the file
201201 new_ref = self.repo.get_named_file('HEAD').read()
202202 self.assertEqual(new_ref, 'ref: refs/heads/develop\n')
203
204
205 class DiffTreeTests(PorcelainTestCase):
206
207 def test_empty(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 = StringIO()
212 porcelain.diff_tree(self.repo.path, c2.tree, c3.tree, outstream=outstream)
213 self.assertEquals(outstream.getvalue(), "")