X-Git-Url: http://git.scottworley.com/git-cache/blobdiff_plain/bef7ce53ce70499b4f13985cc9d4b64e2d8aace4..8733638171d4a6908dd4d3e2fe9d0f0a08e0d6a5:/git_cache.py?ds=sidebyside 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)