Search code examples
gitgit-clonegit-alias

git: determine if repo was cloned blobless or treeless


I want a programmatic way (preferably an alias) to determine whether a repository was cloned with either --filter=blob:none or --filter=tree:0, and to be able to tell which.

eg:

if git is-treeless; then echo "repo is treeless"; fi

How would I go about that?


Solution

  • In a blobless/treeless clone I see these keys in .git/config:

    [remote "origin"]
        promisor = true
        partialclonefilter = combine:blob:none+tree:0
    

    So you can try

    $ git config remote.origin.promisor
    true
    
    $ git config remote.origin.partialclonefilter
    combine:blob:none+tree:0
    

    If you have many remotes perhaps you need to loop over them until you find a promisor remote.

    The docs.

    Upd. shell code to check if the remote is promisor:

    test "`git config remote.origin.promisor`" = true
    

    Shell code to check if the clone is blobless, treeless or both:

    git config remote.origin.partialclonefilter | grep -Fq blob
    git config remote.origin.partialclonefilter | grep -Fq tree
    git config remote.origin.partialclonefilter | grep -q 'blob.*tree'