Make local path argument to clone.py optional.
Jelmer Vernooij
a month ago
0 | #!/usr/bin/python | |
1 | # This trivial script demonstrates how to clone a remote repository. | |
2 | # | |
3 | # Example usage: | |
4 | # python examples/clone.py git://github.com/jelmer/dulwich dulwich-clone | |
0 | """Clone. | |
1 | ||
2 | This trivial script demonstrates how to clone or lock a remote repository. | |
3 | ||
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 dulwich | |
7 | """ | |
8 | ||
5 | 9 | |
6 | 10 | import sys |
11 | ||
12 | from os.path import basename | |
13 | ||
7 | 14 | from getopt import getopt |
15 | ||
8 | 16 | from dulwich import porcelain |
9 | 17 | |
10 | opts, args = getopt(sys.argv, "", []) | |
11 | opts = dict(opts) | |
18 | ||
19 | _, args = getopt(sys.argv, "", []) | |
20 | ||
12 | 21 | |
13 | 22 | if len(args) < 2: |
14 | 23 | print("usage: %s host:path path" % (args[0], )) |
15 | 24 | sys.exit(1) |
16 | 25 | |
17 | porcelain.clone(args[1], args[2]) | |
26 | elif len(args) < 3: | |
27 | target_path = basename(args[1].split(":")[-1]) | |
28 | if target_path[-4:] == ".git": | |
29 | target_path = target_path[:-4] | |
30 | else: | |
31 | target_path = args[2] | |
32 | ||
33 | porcelain.clone(args[1], target_path) |