clone.py 750 B

1234567891011121314151617181920212223242526272829303132
  1. """Clone.
  2. This trivial script demonstrates how to clone or lock a remote repository.
  3. Example usage:
  4. 1. python examples/clone.py git://github.com/jelmer/dulwich
  5. 2. python examples/clone.py git://github.com/jelmer/dulwich.git
  6. 3. python examples/clone.py git://github.com/jelmer/dulwich.git dulwich
  7. """
  8. import sys
  9. from getopt import getopt
  10. from os.path import basename
  11. from dulwich import porcelain
  12. _, args = getopt(sys.argv, "", [])
  13. if len(args) < 2:
  14. print("usage: {} host:path path".format(args[0]))
  15. sys.exit(1)
  16. elif len(args) < 3:
  17. target_path = basename(args[1].split(":")[-1])
  18. if target_path[-4:] == ".git":
  19. target_path = target_path[:-4]
  20. else:
  21. target_path = args[2]
  22. porcelain.clone(args[1], target_path)