X-Git-Url: http://git.scottworley.com/git-cache/blobdiff_plain/bef7ce53ce70499b4f13985cc9d4b64e2d8aace4..347be7cf3626da2bee6487ef25b2d9dc66988a43:/git_cache.py diff --git a/git_cache.py b/git_cache.py index d1923cd..594fb8a 100644 --- a/git_cache.py +++ b/git_cache.py @@ -8,6 +8,7 @@ import hashlib import logging import os import subprocess +import sys from typing import Tuple @@ -77,3 +78,16 @@ def ensure_rev_available(repo: Repo, ref: Ref, rev: Rev) -> Path: subprocess.run(['git', '-C', cachedir, 'cat-file', '-e', rev], check=True) return cachedir + + +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]))) + 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)