clone.py 867 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python
  2. # This trivial script demonstrates how to clone a remote repository.
  3. #
  4. # Example usage:
  5. # python examples/clone.py git://github.com/jelmer/dulwich dulwich-clone
  6. import sys
  7. from getopt import getopt
  8. from dulwich.repo import Repo
  9. from dulwich.client import get_transport_and_path
  10. opts, args = getopt(sys.argv, "", [])
  11. opts = dict(opts)
  12. if len(args) < 2:
  13. print("usage: %s host:path path" % (args[0], ))
  14. sys.exit(1)
  15. # Connect to the remote repository
  16. client, host_path = get_transport_and_path(args[1])
  17. path = args[2]
  18. # Create the local repository
  19. r = Repo.init(path, mkdir=True)
  20. # Fetch the remote objects
  21. remote_refs = client.fetch(host_path, r,
  22. determine_wants=r.object_store.determine_wants_all,
  23. progress=sys.stdout.write)
  24. # Update the local head to point at the right object
  25. r["HEAD"] = remote_refs["HEAD"]
  26. r._build_tree()