clone.py 800 B

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