From 0c5f040a7f557df74eb7792850bde51df5b9eb3c Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 1 Jul 2017 21:24:34 -0700 Subject: [PATCH 1/2] Use new git lfs (broken due to lfs returning non-lfs files) --- get-git-lfs.py | 4 ++-- pre_commit_hooks/check_added_large_files.py | 21 ++++++--------------- tests/check_added_large_files_test.py | 4 ---- 3 files changed, 8 insertions(+), 21 deletions(-) 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 @@ 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' + '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 print_function from __future__ import unicode_literals import argparse +import json import math import os @@ -13,23 +14,13 @@ 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() + 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 = pytest.mark.xfail( @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') From 9581d50e79774678482d4fc2ee497b8d70032668 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 26 Jul 2017 03:14:40 -0700 Subject: [PATCH 2/2] Workaround https://github.com/travis-ci/travis-ci/issues/6865 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a3e5fc4..c4c3b19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ matrix: - env: TOXENV=py36 python: 3.6 - env: TOXENV=pypy + python: pypy-5.7.1 install: pip install coveralls tox script: tox before_install: