mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
Merge pull request #224 from pre-commit/use_new_git_lfs
Use new git lfs
This commit is contained in:
commit
f233e2fc6f
4 changed files with 9 additions and 21 deletions
|
|
@ -8,6 +8,7 @@ matrix:
|
||||||
- env: TOXENV=py36
|
- env: TOXENV=py36
|
||||||
python: 3.6
|
python: 3.6
|
||||||
- env: TOXENV=pypy
|
- env: TOXENV=pypy
|
||||||
|
python: pypy-5.7.1
|
||||||
install: pip install coveralls tox
|
install: pip install coveralls tox
|
||||||
script: tox
|
script: tox
|
||||||
before_install:
|
before_install:
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ from urllib.request import urlopen
|
||||||
|
|
||||||
DOWNLOAD_PATH = (
|
DOWNLOAD_PATH = (
|
||||||
'https://github.com/github/git-lfs/releases/download/'
|
'https://github.com/github/git-lfs/releases/download/'
|
||||||
'v1.1.0/git-lfs-linux-amd64-1.1.0.tar.gz'
|
'v2.2.1/git-lfs-linux-amd64-2.2.1.tar.gz'
|
||||||
)
|
)
|
||||||
PATH_IN_TAR = 'git-lfs-1.1.0/git-lfs'
|
PATH_IN_TAR = 'git-lfs-2.2.1/git-lfs'
|
||||||
DEST_PATH = '/tmp/git-lfs/git-lfs'
|
DEST_PATH = '/tmp/git-lfs/git-lfs'
|
||||||
DEST_DIR = os.path.dirname(DEST_PATH)
|
DEST_DIR = os.path.dirname(DEST_PATH)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
@ -13,23 +14,13 @@ from pre_commit_hooks.util import cmd_output
|
||||||
|
|
||||||
|
|
||||||
def lfs_files():
|
def lfs_files():
|
||||||
try: # pragma: no cover (no git-lfs)
|
try:
|
||||||
lines = cmd_output('git', 'lfs', 'status', '--porcelain').splitlines()
|
# Introduced in git-lfs 2.2.0, first working in 2.2.1
|
||||||
|
lfs_ret = cmd_output('git', 'lfs', 'status', '--json')
|
||||||
except CalledProcessError: # pragma: no cover (with git-lfs)
|
except CalledProcessError: # pragma: no cover (with git-lfs)
|
||||||
lines = []
|
lfs_ret = '{"files":{}}'
|
||||||
|
|
||||||
modes_and_fileparts = [
|
return set(json.loads(lfs_ret)['files'])
|
||||||
(line[:3].strip(), line[3:].rpartition(' ')[0]) for line in lines
|
|
||||||
]
|
|
||||||
|
|
||||||
def to_file_part(mode, filepart): # pragma: no cover (no git-lfs)
|
|
||||||
assert mode in ('A', 'R')
|
|
||||||
return filepart if mode == 'A' else filepart.split(' -> ')[1]
|
|
||||||
|
|
||||||
return {
|
|
||||||
to_file_part(mode, filepart) for mode, filepart in modes_and_fileparts
|
|
||||||
if mode in ('A', 'R')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def find_large_added_files(filenames, maxkb):
|
def find_large_added_files(filenames, maxkb):
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,6 @@ xfailif_no_gitlfs = pytest.mark.xfail(
|
||||||
@xfailif_no_gitlfs
|
@xfailif_no_gitlfs
|
||||||
def test_allows_gitlfs(temp_git_dir): # pragma: no cover
|
def test_allows_gitlfs(temp_git_dir): # pragma: no cover
|
||||||
with temp_git_dir.as_cwd():
|
with temp_git_dir.as_cwd():
|
||||||
# Work around https://github.com/github/git-lfs/issues/913
|
|
||||||
cmd_output(
|
|
||||||
'git', 'commit', '--no-gpg-sign', '--allow-empty', '-m', 'foo',
|
|
||||||
)
|
|
||||||
cmd_output('git', 'lfs', 'install')
|
cmd_output('git', 'lfs', 'install')
|
||||||
temp_git_dir.join('f.py').write('a' * 10000)
|
temp_git_dir.join('f.py').write('a' * 10000)
|
||||||
cmd_output('git', 'lfs', 'track', 'f.py')
|
cmd_output('git', 'lfs', 'track', 'f.py')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue