Skip to content

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

Closed

Description

@jeremy-coulon

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://github.com/proxy/git-lfs.github.com/spec/v1
oid sha256:b506867cbae90bcb984fbdfdbfd06ac15b2f1bb2077741d2100552de2c0859b7
size 1812444
$ git cat-file -s :avatar1.gif
132

Activity

  1. asottile commented on Feb 18, 2021

    @asottile
    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

  2. asottile commented on Feb 18, 2021

    @asottile
    Member

    errr this is the command:

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

  3. jeremy-coulon commented on Feb 18, 2021

    @jeremy-coulon
    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.

  4. asottile commented on Feb 18, 2021

    @asottile
    Member

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

  5. JulianVolodia commented on Mar 9, 2021

    @JulianVolodia

    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?

  6. jeremy-coulon commented on Mar 9, 2021

    @jeremy-coulon
    Author

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

  7. JulianVolodia commented on Mar 9, 2021

    @JulianVolodia

    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?

  8. nabobalis commented on Apr 9, 2021

    @nabobalis
  9. asottile commented on Apr 9, 2021

    @asottile
    Member

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions