clone.py 741 B

12345678910111213141516171819202122232425262728293031
  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(f"usage: {args[0]} host:path path")
  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)