# implementation details for my comfort. So we re-implement here half of
# nix's builtins.fetchGit. :(
+import argparse
import functools
import hashlib
import logging
def _main() -> None:
- if len(sys.argv) == 3:
- print('{1} {0}'.format(*fetch(Repo(sys.argv[1]), Ref(sys.argv[2]))))
- elif len(sys.argv) == 4:
- print(ensure_rev_available(
- Repo(sys.argv[1]), Ref(sys.argv[2]), Rev(sys.argv[3])))
+ parser = argparse.ArgumentParser(
+ description='Cache remote git repositories locally.',
+ epilog='example usage: git-cache https://github.com/NixOS/nixpkgs.git master')
+ parser.add_argument(
+ 'repo',
+ metavar='Repo',
+ type=Repo,
+ help='Git repository URL')
+ parser.add_argument(
+ 'ref',
+ metavar='Ref',
+ type=Ref,
+ help='Ref (branch or tag) in the git repo')
+ parser.add_argument(
+ 'rev',
+ metavar='Rev',
+ type=Rev,
+ nargs='?',
+ help='Ensure that this revision is present. ' +
+ 'If this revision is already present locally, no network operations are performed.')
+ args = parser.parse_args()
+
+ if args.rev is None:
+ print('{1} {0}'.format(*fetch(args.repo, args.ref)))
else:
- usage = '''usage: git-cache repo ref [rev]
-example: git-cache https://github.com/NixOS/nixpkgs.git master'''
- print(usage, file=sys.stderr)
- sys.exit(1)
+ print(ensure_rev_available(args.repo, args.ref, args.rev))