Dulwich.io dulwich / c32cd5e
Add implementation of 'show' for porcelain. Jelmer Vernooij 6 years ago
3 changed file(s) with 35 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
183183 porcelain.update_server_info(".")
184184
185185
186 def cmd_show(args):
187 opts, args = getopt(args, "", [])
188 porcelain.show(".")
189
190
186191 commands = {
187192 "commit": cmd_commit,
188193 "fetch-pack": cmd_fetch_pack,
196201 "update-server-info": cmd_update_server_info,
197202 "diff": cmd_diff,
198203 "add": cmd_add,
199 "rm": cmd_rm
204 "rm": cmd_rm,
205 "show": cmd_show,
200206 }
201207
202208 if len(sys.argv) < 2:
1919 import sys
2020
2121 from dulwich.client import get_transport_and_path
22 from dulwich.patch import write_tree_diff
2223 from dulwich.repo import (BaseRepo, Repo)
2324 from dulwich.server import update_server_info as server_update_server_info
2425
175176 walker = r.get_walker()
176177 for entry in walker:
177178 print_commit(entry.commit, outstream)
179
180
181 def show(repo=".", committish=None, outstream=sys.stdout):
182 """Print the changes in a commit.
183
184 :param repo: Path to repository
185 :param committish: Commit to write
186 :param outstream: Stream to write to
187 """
188 if committish is None:
189 committish = "HEAD"
190 r = open_repo(repo)
191 commit = r[committish]
192 parent_commit = r[commit.parents[0]]
193 print_commit(commit, outstream)
194 write_tree_diff(outstream, r.object_store, parent_commit.tree, commit.tree)
140140 outstream = StringIO()
141141 porcelain.log(self.repo.path, outstream=outstream)
142142 self.assertTrue(outstream.getvalue().startswith("-" * 50))
143
144
145 class ShowTests(PorcelainTestCase):
146
147 def test_simple(self):
148 c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
149 [3, 1, 2]])
150 self.repo.refs["HEAD"] = c3.id
151 outstream = StringIO()
152 porcelain.show(self.repo.path, committish=c3.id, outstream=outstream)
153 self.assertTrue(outstream.getvalue().startswith("-" * 50))