]> git.scottworley.com Git - git-cache/blobdiff - git_cache.py
Simple command-line interface
[git-cache] / git_cache.py
index d1923cd5a7ee287cfbc0da2625e91b1dfa670216..594fb8a77cdad825a2783723ffc04bbd6c951b71 100644 (file)
@@ -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)