diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index 545a3d0b..5c6d1fe9 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -30,8 +30,8 @@ def _update_repository(repo_config, runner): repo = Repository.create(repo_config, runner.store) with local.cwd(repo.repo_path_getter.repo_path): - local['git']['fetch']() - head_sha = local['git']['rev-parse', 'origin/master']().strip() + local['git']('fetch') + head_sha = local['git']('rev-parse', 'origin/master').strip() # Don't bother trying to update if our sha is the same if head_sha == repo_config['sha']: diff --git a/pre_commit/git.py b/pre_commit/git.py index bfaabd98..382daa86 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -49,21 +49,21 @@ def get_conflicted_files(): # This will get the rest of the changes made after the merge. # If they resolved the merge conflict by choosing a mesh of both sides # this will also include the conflicted files - tree_hash = local['git']['write-tree']().strip() - merge_diff_filenames = local['git'][ + tree_hash = local['git']('write-tree').strip() + merge_diff_filenames = local['git']( 'diff', '-m', tree_hash, 'HEAD', 'MERGE_HEAD', '--name-only', - ]().splitlines() + ).splitlines() return set(merge_conflict_filenames) | set(merge_diff_filenames) @memoize_by_cwd def get_staged_files(): - return local['git']['diff', '--staged', '--name-only']().splitlines() + return local['git']('diff', '--staged', '--name-only').splitlines() @memoize_by_cwd def get_all_files(): - return local['git']['ls-files']().splitlines() + return local['git']('ls-files').splitlines() def get_files_matching(all_file_list_strategy): diff --git a/testing/util.py b/testing/util.py index 009b9eb5..7b1bc7d1 100644 --- a/testing/util.py +++ b/testing/util.py @@ -33,7 +33,7 @@ def copy_tree_to_path(src_dir, dest_dir): def get_head_sha(dir): with local.cwd(dir): - return local['git']['rev-parse', 'HEAD']().strip() + return local['git']('rev-parse', 'HEAD').strip() def is_valid_according_to_schema(obj, schema): diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py index 03da32a3..39d1b335 100644 --- a/tests/commands/autoupdate_test.py +++ b/tests/commands/autoupdate_test.py @@ -75,7 +75,7 @@ def out_of_date_repo(python_hooks_repo): config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA) validate_config_extra(config_wrapped) config = config_wrapped[0] - local['git']['commit', '--allow-empty', '-m', 'foo']() + local['git']('commit', '--allow-empty', '-m', 'foo') head_sha = get_head_sha(python_hooks_repo) with open(os.path.join(python_hooks_repo, C.CONFIG_FILE), 'w') as file_obj: @@ -125,8 +125,8 @@ def hook_disappearing_repo(python_hooks_repo): get_resource_path('manifest_without_foo.yaml'), C.MANIFEST_FILE, ) - local['git']['add', '.']() - local['git']['commit', '-m', 'Remove foo']() + local['git']('add', '.') + local['git']('commit', '-m', 'Remove foo') with open(os.path.join(python_hooks_repo, C.CONFIG_FILE), 'w') as file_obj: file_obj.write( diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py index 5813ec03..261c2a11 100644 --- a/tests/commands/run_test.py +++ b/tests/commands/run_test.py @@ -14,8 +14,8 @@ from testing.auto_namedtuple import auto_namedtuple def stage_a_file(): - local['touch']['foo.py']() - local['git']['add', 'foo.py']() + local['touch']('foo.py') + local['git']('add', 'foo.py') def get_write_mock_output(write_mock): @@ -153,7 +153,7 @@ def test_merge_conflict_modified(in_merge_conflict, mock_out_store_directory): def test_merge_conflict_resolved(in_merge_conflict, mock_out_store_directory): - local['git']['add', '.']() + local['git']('add', '.') ret, printed = _do_run(in_merge_conflict, _get_opts()) for msg in ('Checking merge-conflict files only.', 'Bash hook', 'Passed'): assert msg in printed diff --git a/tests/conftest.py b/tests/conftest.py index 4f0a381d..665d34ec 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,19 +45,19 @@ def in_tmpdir(tmpdir_factory): @pytest.yield_fixture def empty_git_dir(in_tmpdir): - local['git']['init']() + local['git']('init') yield in_tmpdir def add_and_commit(): - local['git']['add', '.']() - local['git']['commit', '-m', 'random commit {0}'.format(time.time())]() + local['git']('add', '.') + local['git']('commit', '-m', 'random commit {0}'.format(time.time())) @pytest.yield_fixture def dummy_git_repo(empty_git_dir): # This is needed otherwise there is no `HEAD` - local['touch']['dummy']() + local['touch']('dummy') add_and_commit() yield empty_git_dir @@ -205,27 +205,27 @@ def repo_with_failing_hook(failing_hook_repo, empty_git_dir): @pytest.yield_fixture def in_merge_conflict(repo_with_passing_hook): - local['git']['add', C.CONFIG_FILE]() - local['git']['commit', '-m' 'add hooks file']() - local['git']['clone', '.', 'foo']() + local['git']('add', C.CONFIG_FILE) + local['git']('commit', '-m' 'add hooks file') + local['git']('clone', '.', 'foo') with local.cwd('foo'): - local['git']['checkout', 'origin/master', '-b', 'foo']() + local['git']('checkout', 'origin/master', '-b', 'foo') with open('conflict_file', 'w') as conflict_file: conflict_file.write('herp\nderp\n') - local['git']['add', 'conflict_file']() + local['git']('add', 'conflict_file') with open('foo_only_file', 'w') as foo_only_file: foo_only_file.write('foo') - local['git']['add', 'foo_only_file']() - local['git']['commit', '-m', 'conflict_file']() - local['git']['checkout', 'origin/master', '-b', 'bar']() + local['git']('add', 'foo_only_file') + local['git']('commit', '-m', 'conflict_file') + local['git']('checkout', 'origin/master', '-b', 'bar') with open('conflict_file', 'w') as conflict_file: conflict_file.write('harp\nddrp\n') - local['git']['add', 'conflict_file']() + local['git']('add', 'conflict_file') with open('bar_only_file', 'w') as bar_only_file: bar_only_file.write('bar') - local['git']['add', 'bar_only_file']() - local['git']['commit', '-m', 'conflict_file']() - local['git']['merge', 'foo'](retcode=None) + local['git']('add', 'bar_only_file') + local['git']('commit', '-m', 'conflict_file') + local['git']('merge', 'foo', retcode=None) yield os.path.join(repo_with_passing_hook, 'foo') diff --git a/tests/git_test.py b/tests/git_test.py index dff80e91..a86383dc 100644 --- a/tests/git_test.py +++ b/tests/git_test.py @@ -77,14 +77,14 @@ def test_exclude_removes_files(get_files_matching_func): def resolve_conflict(): with open('conflict_file', 'w') as conflicted_file: conflicted_file.write('herp\nderp\n') - local['git']['add', 'conflict_file']() + local['git']('add', 'conflict_file') def test_get_conflicted_files(in_merge_conflict): resolve_conflict() with open('other_file', 'w') as other_file: other_file.write('oh hai') - local['git']['add', 'other_file']() + local['git']('add', 'other_file') ret = set(git.get_conflicted_files()) assert ret == set(('conflict_file', 'other_file')) diff --git a/tests/repository_test.py b/tests/repository_test.py index cd52f0b9..5150832d 100644 --- a/tests/repository_test.py +++ b/tests/repository_test.py @@ -149,7 +149,7 @@ def test_reinstall(config_for_python_hooks_repo, store): @pytest.mark.integration def test_really_long_file_paths(config_for_python_hooks_repo, store): path = 'really_long' * 10 - local['git']['init', path]() + local['git']('init', path) with local.cwd(path): repo = Repository.create(config_for_python_hooks_repo, store) repo.require_installed() diff --git a/tests/staged_files_only_test.py b/tests/staged_files_only_test.py index a70c6447..79830ae4 100644 --- a/tests/staged_files_only_test.py +++ b/tests/staged_files_only_test.py @@ -17,7 +17,7 @@ FOO_CONTENTS = '\n'.join(('1', '2', '3', '4', '5', '6', '7', '8', '')) def get_short_git_status(): - git_status = local['git']['status', '-s']() + git_status = local['git']('status', '-s') return dict(reversed(line.split()) for line in git_status.splitlines()) @@ -25,7 +25,7 @@ def get_short_git_status(): def foo_staged(empty_git_dir): with io.open('foo', 'w') as foo_file: foo_file.write(FOO_CONTENTS) - local['git']['add', 'foo']() + local['git']('add', 'foo') foo_filename = os.path.join(empty_git_dir, 'foo') yield auto_namedtuple(path=empty_git_dir, foo_filename=foo_filename) @@ -99,7 +99,7 @@ def test_foo_both_modify_conflicting(foo_staged, cmd_runner): def img_staged(empty_git_dir): img_filename = os.path.join(empty_git_dir, 'img.jpg') shutil.copy(get_resource_path('img1.jpg'), img_filename) - local['git']['add', 'img.jpg']() + local['git']('add', 'img.jpg') yield auto_namedtuple(path=empty_git_dir, img_filename=img_filename) @@ -150,23 +150,23 @@ def test_img_conflict(img_staged, cmd_runner): @pytest.yield_fixture def submodule_with_commits(empty_git_dir): - local['git']['commit', '--allow-empty', '-m', 'foo']() - sha1 = local['git']['rev-parse', 'HEAD']().strip() - local['git']['commit', '--allow-empty', '-m', 'bar']() - sha2 = local['git']['rev-parse', 'HEAD']().strip() + local['git']('commit', '--allow-empty', '-m', 'foo') + sha1 = local['git']('rev-parse', 'HEAD').strip() + local['git']('commit', '--allow-empty', '-m', 'bar') + sha2 = local['git']('rev-parse', 'HEAD').strip() yield auto_namedtuple(path=empty_git_dir, sha1=sha1, sha2=sha2) def checkout_submodule(sha): with local.cwd('sub'): - local['git']['checkout', sha]() + local['git']('checkout', sha) @pytest.yield_fixture def sub_staged(submodule_with_commits, empty_git_dir): - local['git']['submodule', 'add', submodule_with_commits.path, 'sub']() + local['git']('submodule', 'add', submodule_with_commits.path, 'sub') checkout_submodule(submodule_with_commits.sha1) - local['git']['add', 'sub']() + local['git']('add', 'sub') yield auto_namedtuple( path=empty_git_dir, sub_path=os.path.join(empty_git_dir, 'sub'), @@ -177,7 +177,7 @@ def sub_staged(submodule_with_commits, empty_git_dir): def _test_sub_state(path, sha='sha1', status='A'): assert os.path.exists(path.sub_path) with local.cwd(path.sub_path): - actual_sha = local['git']['rev-parse', 'HEAD']().strip() + actual_sha = local['git']('rev-parse', 'HEAD').strip() assert actual_sha == getattr(path.submodule, sha) actual_status = get_short_git_status()['sub'] assert actual_status == status