Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check that all git-lfs tracked and committed files are pointers?

As git-lfs requires some manual setup (install git-lfs, run git lfs install once) this can lead to developers not committing git-lfs tracked file types correctly. I would like to check that for pull requests on our continuous integration system.

How to check that all git-lfs tracked and committed files are pointers? There is a check which is run e.g. when rebasing but this is not available as cli-command.

I would like to have something like this:

$ git clone https://...
$ [git lfs check-for-pointers]
Encountered 35 file(s) that should have been pointers, but weren't:
    file1.png
    ...
like image 341
Lars Bilke Avatar asked Nov 02 '17 09:11

Lars Bilke


1 Answers

Git LFS doesn't have a way to do this natively, although you could open an issue on the GitHub repository if you'd like to see support for it. In the mean time, you can implement this using a technique like the following:

git ls-files | git check-attr --stdin filter | \
awk -F': ' '$3 ~ /lfs/ { print $1}' | \
xargs -L1 sh -c 'git cat-file blob "HEAD:$0" | \
    git lfs pointer --check --stdin || { echo "$0"; false; }'

If this command produces any output, then there is an invalid pointer file, and it should print which file it is. It will also exit zero if everything is okay, and nonzero if there's a broken file.

This does have the limitation that it doesn't handle file names with a colon-space or newline in them; if that matters, you'll have to use the -z option and run things through perl or ruby instead of awk.

like image 193
bk2204 Avatar answered Nov 19 '22 12:11

bk2204