mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 03:26: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
38
get-git-lfs.py
Executable file
38
get-git-lfs.py
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3.4
|
||||
"""This is a script to install git-lfs to a tempdir for use in tests"""
|
||||
import io
|
||||
import os.path
|
||||
import shutil
|
||||
import tarfile
|
||||
from urllib.request import urlopen
|
||||
|
||||
DOWNLOAD_PATH = (
|
||||
'https://github.com/github/git-lfs/releases/download/'
|
||||
'v1.1.0/git-lfs-linux-amd64-1.1.0.tar.gz'
|
||||
)
|
||||
PATH_IN_TAR = 'git-lfs-1.1.0/git-lfs'
|
||||
DEST_PATH = '/tmp/git-lfs/git-lfs'
|
||||
DEST_DIR = os.path.dirname(DEST_PATH)
|
||||
|
||||
|
||||
def main():
|
||||
if (
|
||||
os.path.exists(DEST_PATH) and
|
||||
os.path.isfile(DEST_PATH) and
|
||||
os.access(DEST_PATH, os.X_OK)
|
||||
):
|
||||
print('Already installed!')
|
||||
return 0
|
||||
|
||||
shutil.rmtree(DEST_DIR, ignore_errors=True)
|
||||
os.makedirs(DEST_DIR, exist_ok=True)
|
||||
|
||||
contents = io.BytesIO(urlopen(DOWNLOAD_PATH).read())
|
||||
with tarfile.open(fileobj=contents) as tar:
|
||||
with tar.extractfile(PATH_IN_TAR) as src_file:
|
||||
with open(DEST_PATH, 'wb') as dest_file:
|
||||
shutil.copyfileobj(src_file, dest_file)
|
||||
os.chmod(DEST_PATH, 0o755)
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue