Search code examples
gitsparse-checkout

How to read file content from git objects?


Having a sparsely checked out working tree, I wish to parse the full git objects, In order to be able to update sparse .git/info/sparse-checkout, based on some business logic (which should not be relevant here).

I tried to find a command to checkout "unsparsed" into a temporary folder. I wonder, if I can probably even read contents out of git objects without a checkout.

Trying to build a module graphe around

def _find_addons(dir):
    """ yield (addon_name, addon_dir, manifest) """
    for root, _, files in os.walk(dir):
        if ".git" in root:
            continue
        if any(s in root for s in SKIP_PATHS):
            continue
        if any(M in files for M in MANIFEST_NAMES):
            yield os.path.dirname(root), os.path.basename(root), _read_manifest(root)

Full code:

https://github.com/xoe-labs/odooup/blob/master/odooup/_modulegraph.py


Solution

  • Use git cat-file -p <object name> to print the content of a git object from its id.