Merge pull request #224 from pre-commit/use_new_git_lfs
Use new git lfs
diff --git a/.travis.yml b/.travis.yml
index a3e5fc4..c4c3b19 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@
- env: TOXENV=py36
python: 3.6
- env: TOXENV=pypy
+ python: pypy-5.7.1
install: pip install coveralls tox
script: tox
before_install:
diff --git a/get-git-lfs.py b/get-git-lfs.py
index c1f2197..48dd31e 100755
--- a/get-git-lfs.py
+++ b/get-git-lfs.py
@@ -8,9 +8,9 @@
DOWNLOAD_PATH = (
'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_DIR = os.path.dirname(DEST_PATH)
diff --git a/pre_commit_hooks/check_added_large_files.py b/pre_commit_hooks/check_added_large_files.py
index 193b910..2d06706 100644
--- a/pre_commit_hooks/check_added_large_files.py
+++ b/pre_commit_hooks/check_added_large_files.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import argparse
+import json
import math
import os
@@ -13,23 +14,13 @@
def lfs_files():
- try: # pragma: no cover (no git-lfs)
- lines = cmd_output('git', 'lfs', 'status', '--porcelain').splitlines()
+ try:
+ # 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)
- lines = []
+ lfs_ret = '{"files":{}}'
- modes_and_fileparts = [
- (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')
- }
+ return set(json.loads(lfs_ret)['files'])
def find_large_added_files(filenames, maxkb):
diff --git a/tests/check_added_large_files_test.py b/tests/check_added_large_files_test.py
index 4a84463..06671d7 100644
--- a/tests/check_added_large_files_test.py
+++ b/tests/check_added_large_files_test.py
@@ -79,10 +79,6 @@
@xfailif_no_gitlfs
def test_allows_gitlfs(temp_git_dir): # pragma: no cover
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')
temp_git_dir.join('f.py').write('a' * 10000)
cmd_output('git', 'lfs', 'track', 'f.py')