Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check-added-large-files doesn't work with --all-files #560

Closed
jeremy-coulon opened this issue Feb 18, 2021 · 9 comments · Fixed by #674
Closed

check-added-large-files doesn't work with --all-files #560

jeremy-coulon opened this issue Feb 18, 2021 · 9 comments · Fixed by #674

Comments

@jeremy-coulon
Copy link

check-added-large-files hook doesn't correctly detect files in LFS when running with option --all-files

Using git cat-file -s :$file would be a better implementation in order to get size of a blob.

For example:

$ grep gif .gitattributes 
*.gif filter=lfs diff=lfs merge=lfs -text
$ pre-commit run check-added-large-files --all-files
Check for added large files..............................................Failed
- hook id: check-added-large-files
- exit code: 1
avatar1.gif (1770 KB) exceeds 1024 KB.
$ git cat-file blob :avatar1.gif
version https://git-lfs.github.com/spec/v1
oid sha256:b506867cbae90bcb984fbdfdbfd06ac15b2f1bb2077741d2100552de2c0859b7
size 1812444
$ git cat-file -s :avatar1.gif
132
@asottile
Copy link
Member

there's no change in the logic between --all-files and not -- what does this command return for you?

filenames_filtered = set(filenames) - lfs_files()

git cat-file -s :filename is not really an option as it'd have to be invoked potentially thousands of times which would be extremely slow

@asottile
Copy link
Member

errr this is the command:

lfs_ret = cmd_output('git', 'lfs', 'status', '--json')

@jeremy-coulon
Copy link
Author

$ git lfs status --json
{"files":{}}

This is normal because I don't have any change.

I want to be able to execute this hook in CI. Thus executing without any pending change with option --all-files.

@asottile
Copy link
Member

ah, is there a better argument for lfs status? we can probably hook this into the --enforce-all command

@JulianVolodia
Copy link

I want to be able to execute this hook in CI.

I will try to make PR @jeremy-coulon but tell me what is desired. If there is no pendin change but file was not commited correctly to LFS but was in repo yup?

@jeremy-coulon
Copy link
Author

Yes that's the kind of problem that I want to spot in the CI.

@JulianVolodia
Copy link

Btw. Jeremy, as the git-lfs is supposed to be low level feature (it is not automagically pruned, needs to filter files and so on) maybe filtering pulled changes and seeing if files except lfs files are ok with this hook?

What is the workflow on Developers' localhost?

@nabobalis

This comment has been minimized.

@asottile
Copy link
Member

asottile commented Apr 9, 2021

@nabobalis for non-lfs, check the README -- this issue is specific to lfs so commenting about non-lfs is off topic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants