mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 20:16:53 +00:00
Teach check-large-files-added about git-lfs. Reslves #82.
This commit is contained in:
parent
2c62e4aafc
commit
3f6f23d73f
6 changed files with 109 additions and 2 deletions
|
|
@ -9,12 +9,34 @@ import os
|
|||
import sys
|
||||
|
||||
from pre_commit_hooks.util import added_files
|
||||
from pre_commit_hooks.util import CalledProcessError
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def lfs_files():
|
||||
try: # pragma: no cover (no git-lfs)
|
||||
lines = cmd_output('git', 'lfs', 'status', '--porcelain').splitlines()
|
||||
except CalledProcessError:
|
||||
lines = []
|
||||
|
||||
modes_and_fileparts = [
|
||||
(line[:3].strip(), line[3:].rpartition(' ')[0]) for line in lines
|
||||
]
|
||||
|
||||
def to_file_part(mode, filepart):
|
||||
assert mode in ('A', 'R')
|
||||
return filepart if mode == 'A' else filepart.split(' -> ')[1]
|
||||
|
||||
return set(
|
||||
to_file_part(mode, filepart) for mode, filepart in modes_and_fileparts
|
||||
if mode in ('A', 'R')
|
||||
)
|
||||
|
||||
|
||||
def find_large_added_files(filenames, maxkb):
|
||||
# Find all added files that are also in the list of files pre-commit tells
|
||||
# us about
|
||||
filenames = added_files() & set(filenames)
|
||||
filenames = (added_files() & set(filenames)) - lfs_files()
|
||||
|
||||
retv = 0
|
||||
for filename in filenames:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue