porcelain.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. # porcelain.py -- Porcelain-like layer on top of Dulwich
  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; either version 2
  7. # or (at your option) a later version of the License.
  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. """Simple wrapper that provides porcelain-like functions on top of Dulwich.
  19. Currently implemented:
  20. * archive
  21. * add
  22. * branch{_create,_delete,_list}
  23. * clone
  24. * commit
  25. * commit-tree
  26. * daemon
  27. * diff-tree
  28. * fetch
  29. * init
  30. * pull
  31. * push
  32. * rm
  33. * receive-pack
  34. * reset
  35. * rev-list
  36. * tag{_create,_delete,_list}
  37. * upload-pack
  38. * update-server-info
  39. * status
  40. * symbolic-ref
  41. These functions are meant to behave similarly to the git subcommands.
  42. Differences in behaviour are considered bugs.
  43. """
  44. __docformat__ = 'restructuredText'
  45. from collections import namedtuple
  46. import os
  47. import sys
  48. import time
  49. from dulwich import index
  50. from dulwich.client import get_transport_and_path
  51. from dulwich.errors import (
  52. SendPackError,
  53. UpdateRefsError,
  54. )
  55. from dulwich.index import get_unstaged_changes
  56. from dulwich.objects import (
  57. Tag,
  58. parse_timezone,
  59. )
  60. from dulwich.objectspec import parse_object
  61. from dulwich.patch import write_tree_diff
  62. from dulwich.protocol import Protocol
  63. from dulwich.repo import (BaseRepo, Repo)
  64. from dulwich.server import (
  65. FileSystemBackend,
  66. TCPGitServer,
  67. ReceivePackHandler,
  68. UploadPackHandler,
  69. update_server_info as server_update_server_info,
  70. )
  71. # Module level tuple definition for status output
  72. GitStatus = namedtuple('GitStatus', 'staged unstaged untracked')
  73. def open_repo(path_or_repo):
  74. """Open an argument that can be a repository or a path for a repository."""
  75. if isinstance(path_or_repo, BaseRepo):
  76. return path_or_repo
  77. return Repo(path_or_repo)
  78. def archive(location, committish=None, outstream=sys.stdout,
  79. errstream=sys.stderr):
  80. """Create an archive.
  81. :param location: Location of repository for which to generate an archive.
  82. :param committish: Commit SHA1 or ref to use
  83. :param outstream: Output stream (defaults to stdout)
  84. :param errstream: Error stream (defaults to stderr)
  85. """
  86. client, path = get_transport_and_path(location)
  87. if committish is None:
  88. committish = "HEAD"
  89. # TODO(jelmer): This invokes C git; this introduces a dependency.
  90. # Instead, dulwich should have its own archiver implementation.
  91. client.archive(path, committish, outstream.write, errstream.write,
  92. errstream.write)
  93. def update_server_info(repo="."):
  94. """Update server info files for a repository.
  95. :param repo: path to the repository
  96. """
  97. r = open_repo(repo)
  98. server_update_server_info(r)
  99. def symbolic_ref(repo, ref_name, force=False):
  100. """Set git symbolic ref into HEAD.
  101. :param repo: path to the repository
  102. :param ref_name: short name of the new ref
  103. :param force: force settings without checking if it exists in refs/heads
  104. """
  105. repo_obj = open_repo(repo)
  106. ref_path = 'refs/heads/%s' % ref_name
  107. if not force and ref_path not in repo_obj.refs.keys():
  108. raise ValueError('fatal: ref `%s` is not a ref' % ref_name)
  109. repo_obj.refs.set_symbolic_ref('HEAD', ref_path)
  110. def commit(repo=".", message=None, author=None, committer=None):
  111. """Create a new commit.
  112. :param repo: Path to repository
  113. :param message: Optional commit message
  114. :param author: Optional author name and email
  115. :param committer: Optional committer name and email
  116. :return: SHA1 of the new commit
  117. """
  118. # FIXME: Support --all argument
  119. # FIXME: Support --signoff argument
  120. r = open_repo(repo)
  121. return r.do_commit(message=message, author=author,
  122. committer=committer)
  123. def commit_tree(repo, tree, message=None, author=None, committer=None):
  124. """Create a new commit object.
  125. :param repo: Path to repository
  126. :param tree: An existing tree object
  127. :param author: Optional author name and email
  128. :param committer: Optional committer name and email
  129. """
  130. r = open_repo(repo)
  131. return r.do_commit(message=message, tree=tree, committer=committer,
  132. author=author)
  133. def init(path=".", bare=False):
  134. """Create a new git repository.
  135. :param path: Path to repository.
  136. :param bare: Whether to create a bare repository.
  137. :return: A Repo instance
  138. """
  139. if not os.path.exists(path):
  140. os.mkdir(path)
  141. if bare:
  142. return Repo.init_bare(path)
  143. else:
  144. return Repo.init(path)
  145. def clone(source, target=None, bare=False, checkout=None, outstream=sys.stdout):
  146. """Clone a local or remote git repository.
  147. :param source: Path or URL for source repository
  148. :param target: Path to target repository (optional)
  149. :param bare: Whether or not to create a bare repository
  150. :param outstream: Optional stream to write progress to
  151. :return: The new repository
  152. """
  153. if checkout is None:
  154. checkout = (not bare)
  155. if checkout and bare:
  156. raise ValueError("checkout and bare are incompatible")
  157. client, host_path = get_transport_and_path(source)
  158. if target is None:
  159. target = host_path.split("/")[-1]
  160. if not os.path.exists(target):
  161. os.mkdir(target)
  162. if bare:
  163. r = Repo.init_bare(target)
  164. else:
  165. r = Repo.init(target)
  166. remote_refs = client.fetch(host_path, r,
  167. determine_wants=r.object_store.determine_wants_all,
  168. progress=outstream.write)
  169. r["HEAD"] = remote_refs["HEAD"]
  170. if checkout:
  171. outstream.write('Checking out HEAD')
  172. r.reset_index()
  173. return r
  174. def add(repo=".", paths=None):
  175. """Add files to the staging area.
  176. :param repo: Repository for the files
  177. :param paths: Paths to add. No value passed stages all modified files.
  178. """
  179. # FIXME: Support patterns, directories.
  180. r = open_repo(repo)
  181. if not paths:
  182. # If nothing is specified, add all non-ignored files.
  183. paths = []
  184. for dirpath, dirnames, filenames in os.walk(r.path):
  185. # Skip .git and below.
  186. if '.git' in dirnames:
  187. dirnames.remove('.git')
  188. for filename in filenames:
  189. paths.append(os.path.join(dirpath[len(r.path)+1:], filename))
  190. r.stage(paths)
  191. def rm(repo=".", paths=None):
  192. """Remove files from the staging area.
  193. :param repo: Repository for the files
  194. :param paths: Paths to remove
  195. """
  196. r = open_repo(repo)
  197. index = r.open_index()
  198. for p in paths:
  199. del index[p]
  200. index.write()
  201. def print_commit(commit, outstream=sys.stdout):
  202. """Write a human-readable commit log entry.
  203. :param commit: A `Commit` object
  204. :param outstream: A stream file to write to
  205. """
  206. outstream.write("-" * 50 + "\n")
  207. outstream.write("commit: %s\n" % commit.id)
  208. if len(commit.parents) > 1:
  209. outstream.write("merge: %s\n" % "...".join(commit.parents[1:]))
  210. outstream.write("author: %s\n" % commit.author)
  211. outstream.write("committer: %s\n" % commit.committer)
  212. outstream.write("\n")
  213. outstream.write(commit.message + "\n")
  214. outstream.write("\n")
  215. def print_tag(tag, outstream=sys.stdout):
  216. """Write a human-readable tag.
  217. :param tag: A `Tag` object
  218. :param outstream: A stream to write to
  219. """
  220. outstream.write("Tagger: %s\n" % tag.tagger)
  221. outstream.write("Date: %s\n" % tag.tag_time)
  222. outstream.write("\n")
  223. outstream.write("%s\n" % tag.message)
  224. outstream.write("\n")
  225. def show_blob(repo, blob, outstream=sys.stdout):
  226. """Write a blob to a stream.
  227. :param repo: A `Repo` object
  228. :param blob: A `Blob` object
  229. :param outstream: A stream file to write to
  230. """
  231. outstream.write(blob.data)
  232. def show_commit(repo, commit, outstream=sys.stdout):
  233. """Show a commit to a stream.
  234. :param repo: A `Repo` object
  235. :param commit: A `Commit` object
  236. :param outstream: Stream to write to
  237. """
  238. print_commit(commit, outstream)
  239. parent_commit = repo[commit.parents[0]]
  240. write_tree_diff(outstream, repo.object_store, parent_commit.tree, commit.tree)
  241. def show_tree(repo, tree, outstream=sys.stdout):
  242. """Print a tree to a stream.
  243. :param repo: A `Repo` object
  244. :param tree: A `Tree` object
  245. :param outstream: Stream to write to
  246. """
  247. for n in tree:
  248. outstream.write("%s\n" % n)
  249. def show_tag(repo, tag, outstream=sys.stdout):
  250. """Print a tag to a stream.
  251. :param repo: A `Repo` object
  252. :param tag: A `Tag` object
  253. :param outstream: Stream to write to
  254. """
  255. print_tag(tag, outstream)
  256. show_object(repo, repo[tag.object[1]], outstream)
  257. def show_object(repo, obj, outstream):
  258. return {
  259. "tree": show_tree,
  260. "blob": show_blob,
  261. "commit": show_commit,
  262. "tag": show_tag,
  263. }[obj.type_name](repo, obj, outstream)
  264. def log(repo=".", outstream=sys.stdout, max_entries=None):
  265. """Write commit logs.
  266. :param repo: Path to repository
  267. :param outstream: Stream to write log output to
  268. :param max_entries: Optional maximum number of entries to display
  269. """
  270. r = open_repo(repo)
  271. walker = r.get_walker(max_entries=max_entries)
  272. for entry in walker:
  273. print_commit(entry.commit, outstream)
  274. def show(repo=".", objects=None, outstream=sys.stdout):
  275. """Print the changes in a commit.
  276. :param repo: Path to repository
  277. :param objects: Objects to show (defaults to [HEAD])
  278. :param outstream: Stream to write to
  279. """
  280. if objects is None:
  281. objects = ["HEAD"]
  282. if not isinstance(objects, list):
  283. objects = [objects]
  284. r = open_repo(repo)
  285. for objectish in objects:
  286. show_object(r, parse_object(r, objectish), outstream)
  287. def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
  288. """Compares the content and mode of blobs found via two tree objects.
  289. :param repo: Path to repository
  290. :param old_tree: Id of old tree
  291. :param new_tree: Id of new tree
  292. :param outstream: Stream to write to
  293. """
  294. r = open_repo(repo)
  295. write_tree_diff(outstream, r.object_store, old_tree, new_tree)
  296. def rev_list(repo, commits, outstream=sys.stdout):
  297. """Lists commit objects in reverse chronological order.
  298. :param repo: Path to repository
  299. :param commits: Commits over which to iterate
  300. :param outstream: Stream to write to
  301. """
  302. r = open_repo(repo)
  303. for entry in r.get_walker(include=[r[c].id for c in commits]):
  304. outstream.write("%s\n" % entry.commit.id)
  305. def tag(*args, **kwargs):
  306. import warnings
  307. warnings.warn(DeprecationWarning, "tag has been deprecated in favour of tag_create.")
  308. return tag_create(*args, **kwargs)
  309. def tag_create(repo, tag, author=None, message=None, annotated=False,
  310. objectish="HEAD", tag_time=None, tag_timezone=None):
  311. """Creates a tag in git via dulwich calls:
  312. :param repo: Path to repository
  313. :param tag: tag string
  314. :param author: tag author (optional, if annotated is set)
  315. :param message: tag message (optional)
  316. :param annotated: whether to create an annotated tag
  317. :param objectish: object the tag should point at, defaults to HEAD
  318. :param tag_time: Optional time for annotated tag
  319. :param tag_timezone: Optional timezone for annotated tag
  320. """
  321. r = open_repo(repo)
  322. object = parse_object(r, objectish)
  323. if annotated:
  324. # Create the tag object
  325. tag_obj = Tag()
  326. if author is None:
  327. # TODO(jelmer): Don't use repo private method.
  328. author = r._get_user_identity()
  329. tag_obj.tagger = author
  330. tag_obj.message = message
  331. tag_obj.name = tag
  332. tag_obj.object = (type(object), object.id)
  333. tag_obj.tag_time = tag_time
  334. if tag_time is None:
  335. tag_time = int(time.time())
  336. if tag_timezone is None:
  337. # TODO(jelmer) Use current user timezone rather than UTC
  338. tag_timezone = 0
  339. elif isinstance(tag_timezone, str):
  340. tag_timezone = parse_timezone(tag_timezone)
  341. tag_obj.tag_timezone = tag_timezone
  342. r.object_store.add_object(tag_obj)
  343. tag_id = tag_obj.id
  344. else:
  345. tag_id = object.id
  346. r.refs['refs/tags/' + tag] = tag_id
  347. def list_tags(*args, **kwargs):
  348. import warnings
  349. warnings.warn(DeprecationWarning, "list_tags has been deprecated in favour of tag_list.")
  350. return tag_list(*args, **kwargs)
  351. def tag_list(repo, outstream=sys.stdout):
  352. """List all tags.
  353. :param repo: Path to repository
  354. :param outstream: Stream to write tags to
  355. """
  356. r = open_repo(repo)
  357. tags = list(r.refs.as_dict("refs/tags"))
  358. tags.sort()
  359. return tags
  360. def tag_delete(repo, name):
  361. """Remove a tag.
  362. :param repo: Path to repository
  363. :param name: Name of tag to remove
  364. """
  365. r = open_repo(repo)
  366. if isinstance(name, str):
  367. names = [name]
  368. elif isinstance(name, list):
  369. names = name
  370. else:
  371. raise TypeError("Unexpected tag name type %r" % name)
  372. for name in names:
  373. del r.refs["refs/tags/" + name]
  374. def reset(repo, mode, committish="HEAD"):
  375. """Reset current HEAD to the specified state.
  376. :param repo: Path to repository
  377. :param mode: Mode ("hard", "soft", "mixed")
  378. """
  379. if mode != "hard":
  380. raise ValueError("hard is the only mode currently supported")
  381. r = open_repo(repo)
  382. tree = r[committish].tree
  383. r.reset_index()
  384. def push(repo, remote_location, refs_path,
  385. outstream=sys.stdout, errstream=sys.stderr):
  386. """Remote push with dulwich via dulwich.client
  387. :param repo: Path to repository
  388. :param remote_location: Location of the remote
  389. :param refs_path: relative path to the refs to push to remote
  390. :param outstream: A stream file to write output
  391. :param errstream: A stream file to write errors
  392. """
  393. # Open the repo
  394. r = open_repo(repo)
  395. # Get the client and path
  396. client, path = get_transport_and_path(remote_location)
  397. def update_refs(refs):
  398. new_refs = r.get_refs()
  399. refs[refs_path] = new_refs['HEAD']
  400. del new_refs['HEAD']
  401. return refs
  402. try:
  403. client.send_pack(path, update_refs,
  404. r.object_store.generate_pack_contents, progress=errstream.write)
  405. outstream.write("Push to %s successful.\n" % remote_location)
  406. except (UpdateRefsError, SendPackError) as e:
  407. outstream.write("Push to %s failed.\n" % remote_location)
  408. errstream.write("Push to %s failed -> '%s'\n" % e.message)
  409. def pull(repo, remote_location, refs_path,
  410. outstream=sys.stdout, errstream=sys.stderr):
  411. """Pull from remote via dulwich.client
  412. :param repo: Path to repository
  413. :param remote_location: Location of the remote
  414. :param refs_path: relative path to the fetched refs
  415. :param outstream: A stream file to write to output
  416. :param errstream: A stream file to write to errors
  417. """
  418. # Open the repo
  419. r = open_repo(repo)
  420. client, path = get_transport_and_path(remote_location)
  421. remote_refs = client.fetch(path, r, progress=errstream.write)
  422. r['HEAD'] = remote_refs[refs_path]
  423. # Perform 'git checkout .' - syncs staged changes
  424. tree = r["HEAD"].tree
  425. r.reset_index()
  426. def status(repo="."):
  427. """Returns staged, unstaged, and untracked changes relative to the HEAD.
  428. :param repo: Path to repository or repository object
  429. :return: GitStatus tuple,
  430. staged - list of staged paths (diff index/HEAD)
  431. unstaged - list of unstaged paths (diff index/working-tree)
  432. untracked - list of untracked, un-ignored & non-.git paths
  433. """
  434. r = open_repo(repo)
  435. # 1. Get status of staged
  436. tracked_changes = get_tree_changes(r)
  437. # 2. Get status of unstaged
  438. unstaged_changes = list(get_unstaged_changes(r.open_index(), r.path))
  439. # TODO - Status of untracked - add untracked changes, need gitignore.
  440. untracked_changes = []
  441. return GitStatus(tracked_changes, unstaged_changes, untracked_changes)
  442. def get_tree_changes(repo):
  443. """Return add/delete/modify changes to tree by comparing index to HEAD.
  444. :param repo: repo path or object
  445. :return: dict with lists for each type of change
  446. """
  447. r = open_repo(repo)
  448. index = r.open_index()
  449. # Compares the Index to the HEAD & determines changes
  450. # Iterate through the changes and report add/delete/modify
  451. # TODO: call out to dulwich.diff_tree somehow.
  452. tracked_changes = {
  453. 'add': [],
  454. 'delete': [],
  455. 'modify': [],
  456. }
  457. for change in index.changes_from_tree(r.object_store, r['HEAD'].tree):
  458. if not change[0][0]:
  459. tracked_changes['add'].append(change[0][1])
  460. elif not change[0][1]:
  461. tracked_changes['delete'].append(change[0][0])
  462. elif change[0][0] == change[0][1]:
  463. tracked_changes['modify'].append(change[0][0])
  464. else:
  465. raise AssertionError('git mv ops not yet supported')
  466. return tracked_changes
  467. def daemon(path=".", address=None, port=None):
  468. """Run a daemon serving Git requests over TCP/IP.
  469. :param path: Path to the directory to serve.
  470. :param address: Optional address to listen on (defaults to ::)
  471. :param port: Optional port to listen on (defaults to TCP_GIT_PORT)
  472. """
  473. # TODO(jelmer): Support git-daemon-export-ok and --export-all.
  474. backend = FileSystemBackend(path)
  475. server = TCPGitServer(backend, address, port)
  476. server.serve_forever()
  477. def web_daemon(path=".", address=None, port=None):
  478. """Run a daemon serving Git requests over HTTP.
  479. :param path: Path to the directory to serve
  480. :param address: Optional address to listen on (defaults to ::)
  481. :param port: Optional port to listen on (defaults to 80)
  482. """
  483. from dulwich.web import (
  484. make_wsgi_chain,
  485. make_server,
  486. WSGIRequestHandlerLogger,
  487. WSGIServerLogger)
  488. backend = FileSystemBackend(path)
  489. app = make_wsgi_chain(backend)
  490. server = make_server(address, port, app,
  491. handler_class=WSGIRequestHandlerLogger,
  492. server_class=WSGIServerLogger)
  493. server.serve_forever()
  494. def upload_pack(path=".", inf=sys.stdin, outf=sys.stdout):
  495. """Upload a pack file after negotiating its contents using smart protocol.
  496. :param path: Path to the repository
  497. :param inf: Input stream to communicate with client
  498. :param outf: Output stream to communicate with client
  499. """
  500. backend = FileSystemBackend()
  501. def send_fn(data):
  502. outf.write(data)
  503. outf.flush()
  504. proto = Protocol(inf.read, send_fn)
  505. handler = UploadPackHandler(backend, [path], proto)
  506. # FIXME: Catch exceptions and write a single-line summary to outf.
  507. handler.handle()
  508. return 0
  509. def receive_pack(path=".", inf=sys.stdin, outf=sys.stdout):
  510. """Receive a pack file after negotiating its contents using smart protocol.
  511. :param path: Path to the repository
  512. :param inf: Input stream to communicate with client
  513. :param outf: Output stream to communicate with client
  514. """
  515. backend = FileSystemBackend()
  516. def send_fn(data):
  517. outf.write(data)
  518. outf.flush()
  519. proto = Protocol(inf.read, send_fn)
  520. handler = ReceivePackHandler(backend, [path], proto)
  521. # FIXME: Catch exceptions and write a single-line summary to outf.
  522. handler.handle()
  523. return 0
  524. def branch_delete(repo, name):
  525. """Delete a branch.
  526. :param repo: Path to the repository
  527. :param name: Name of the branch
  528. """
  529. r = open_repo(repo)
  530. if isinstance(name, str):
  531. names = [name]
  532. elif isinstance(name, list):
  533. names = name
  534. else:
  535. raise TypeError("Unexpected branch name type %r" % name)
  536. for name in names:
  537. del r.refs["refs/heads/" + name]
  538. def branch_create(repo, name, objectish=None, force=False):
  539. """Create a branch.
  540. :param repo: Path to the repository
  541. :param name: Name of the new branch
  542. :param objectish: Target object to point new branch at (defaults to HEAD)
  543. :param force: Force creation of branch, even if it already exists
  544. """
  545. r = open_repo(repo)
  546. if isinstance(name, str):
  547. names = [name]
  548. elif isinstance(name, list):
  549. names = name
  550. else:
  551. raise TypeError("Unexpected branch name type %r" % name)
  552. if objectish is None:
  553. objectish = "HEAD"
  554. object = parse_object(r, objectish)
  555. refname = "refs/heads/" + name
  556. if refname in r.refs and not force:
  557. raise KeyError("Branch with name %s already exists." % name)
  558. r.refs[refname] = object.id
  559. def branch_list(repo):
  560. """List all branches.
  561. :param repo: Path to the repository
  562. """
  563. r = open_repo(repo)
  564. return r.refs.keys(base="refs/heads/")
  565. def fetch(repo, remote_location, outstream=sys.stdout, errstream=sys.stderr):
  566. """Fetch objects from a remote server.
  567. :param repo: Path to the repository
  568. :param remote_location: String identifying a remote server
  569. :param outstream: Output stream (defaults to stdout)
  570. :param errstream: Error stream (defaults to stderr)
  571. :return: Dictionary with refs on the remote
  572. """
  573. r = open_repo(repo)
  574. client, path = get_transport_and_path(remote_location)
  575. remote_refs = client.fetch(path, r, progress=errstream.write)
  576. return remote_refs