Skip to content
New issue

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

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

Already on GitHub? # to your account

Proposal: new hook to detect LFS attribute inconsistencies #1020

Open
klimkin opened this issue Mar 1, 2024 · 8 comments
Open

Proposal: new hook to detect LFS attribute inconsistencies #1020

klimkin opened this issue Mar 1, 2024 · 8 comments

Comments

@klimkin
Copy link

klimkin commented Mar 1, 2024

There are two common errors when working with LFS:

  • Keeping files as general objects after setting LFS attributes (LFS produces a warnings like "Encountered 1 file(s) that should have been pointers, but weren't")
  • Keeping LFS pointers after removing the attributes.

Proposed implementation of a check-lfs-attributes hook: https://github.com/klimkin/pre-commit-hooks/tree/feature/check-lfs-attributes

@asottile
Copy link
Member

asottile commented Mar 2, 2024

doesn't lfs already have things in place to prevent this?

@klimkin
Copy link
Author

klimkin commented Mar 4, 2024

Below, after tracking the file you must add it again to create proper commit. I don't think LFS can prevent this kind of escape unless we use some kind of Git hook.

@xfailif_no_gitlfs
def test_regular_object_but_tracked_by_lfs(temp_git_dir_as_cwd, capsys):  # pragma: no cover
    temp_git_dir_as_cwd.join('a.bin').write('a')
    cmd_output('git', 'lfs', 'install', '--local')
    cmd_output('git', 'add', 'a.bin')
    cmd_output('git', 'lfs', 'track', '*.bin')
    assert main(('a.bin',)) == 1
    out, _ = capsys.readouterr()
    assert 'a.bin is tracked by LFS but added as a regular object' in out

@asottile
Copy link
Member

asottile commented Mar 4, 2024

right but when a push is executed lfs checks this right?

@klimkin
Copy link
Author

klimkin commented Mar 5, 2024

It doesn't seem LFS is checking for inconsistencies. You can push .gitattributes without converting to pointers.

Looking at the LFS pre-push hook https://github.com/git-lfs/git-lfs/blob/b96d77b9563a8fd10c4e03f8f8898a0777ead9a6/commands/command_pre_push.go#L19, it only handles the logic of pushing the content for the pointers.

@asottile
Copy link
Member

asottile commented Mar 5, 2024

that really feels like something lfs should just fix -- I thought their pre-push did more validation than that?

@asottile
Copy link
Member

asottile commented Mar 5, 2024

I also think that check-added-large-files is sufficient to catch this case already

@klimkin
Copy link
Author

klimkin commented Mar 5, 2024

There are two cases to catch:

  1. Files with lfs attribute, but committed as general objects
  2. Files without lfs attribute, but committed as LFS pointers

@asottile Are you suggesting adding the checks to check-added-large-files?

@klimkin
Copy link
Author

klimkin commented Mar 5, 2024

that really feels like something lfs should just fix -- I thought their pre-push did more validation than that?

Did it?

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

No branches or pull requests

2 participants