11from __future__ import unicode_literals
22
3+ import os .path
34import pipes
45import shutil
56from collections import OrderedDict
1415from pre_commit .commands .autoupdate import RepositoryCannotBeUpdatedError
1516from pre_commit .runner import Runner
1617from pre_commit .util import cmd_output
17- from pre_commit .util import cwd
1818from testing .auto_namedtuple import auto_namedtuple
1919from testing .fixtures import add_config_to_repo
2020from testing .fixtures import config_with_local_hooks
@@ -62,14 +62,13 @@ def test_autoupdate_old_revision_broken(
6262 path = make_repo (tempdir_factory , 'python_hooks_repo' )
6363 config = make_config_from_repo (path , check = False )
6464
65- with cwd (path ):
66- cmd_output ('git' , 'mv' , C .MANIFEST_FILE , 'nope.yaml' )
67- cmd_output ('git' , 'commit' , '-m' , 'simulate old repo' )
68- # Assume this is the revision the user's old repository was at
69- rev = git .head_sha (path )
70- cmd_output ('git' , 'mv' , 'nope.yaml' , C .MANIFEST_FILE )
71- cmd_output ('git' , 'commit' , '-m' , 'move hooks file' )
72- update_rev = git .head_sha (path )
65+ cmd_output ('git' , '-C' , path , 'mv' , C .MANIFEST_FILE , 'nope.yaml' )
66+ cmd_output ('git' , '-C' , path , 'commit' , '-m' , 'simulate old repo' )
67+ # Assume this is the revision the user's old repository was at
68+ rev = git .head_sha (path )
69+ cmd_output ('git' , '-C' , path , 'mv' , 'nope.yaml' , C .MANIFEST_FILE )
70+ cmd_output ('git' , '-C' , path , 'commit' , '-m' , 'move hooks file' )
71+ update_rev = git .head_sha (path )
7372
7473 config ['sha' ] = rev
7574 write_config ('.' , config )
@@ -87,8 +86,7 @@ def out_of_date_repo(tempdir_factory):
8786 original_sha = git .head_sha (path )
8887
8988 # Make a commit
90- with cwd (path ):
91- cmd_output ('git' , 'commit' , '--allow-empty' , '-m' , 'foo' )
89+ cmd_output ('git' , '-C' , path , 'commit' , '--allow-empty' , '-m' , 'foo' )
9290 head_sha = git .head_sha (path )
9391
9492 yield auto_namedtuple (
@@ -223,8 +221,7 @@ def test_loses_formatting_when_not_detectable(
223221
224222@pytest .fixture
225223def tagged_repo (out_of_date_repo ):
226- with cwd (out_of_date_repo .path ):
227- cmd_output ('git' , 'tag' , 'v1.2.3' )
224+ cmd_output ('git' , '-C' , out_of_date_repo .path , 'tag' , 'v1.2.3' )
228225 yield out_of_date_repo
229226
230227
@@ -243,8 +240,8 @@ def test_autoupdate_tagged_repo(
243240
244241@pytest .fixture
245242def tagged_repo_with_more_commits (tagged_repo ):
246- with cwd ( tagged_repo .path ):
247- cmd_output ('git' , 'commit' , '--allow-empty' , '-m' , 'commit!' )
243+ cmd = ( 'git' , '-C' , tagged_repo .path , 'commit' , '--allow-empty' , '-mfoo' )
244+ cmd_output (* cmd )
248245 yield tagged_repo
249246
250247
@@ -267,13 +264,12 @@ def hook_disappearing_repo(tempdir_factory):
267264 path = make_repo (tempdir_factory , 'python_hooks_repo' )
268265 original_sha = git .head_sha (path )
269266
270- with cwd (path ):
271- shutil .copy (
272- get_resource_path ('manifest_without_foo.yaml' ),
273- C .MANIFEST_FILE ,
274- )
275- cmd_output ('git' , 'add' , '.' )
276- cmd_output ('git' , 'commit' , '-m' , 'Remove foo' )
267+ shutil .copy (
268+ get_resource_path ('manifest_without_foo.yaml' ),
269+ os .path .join (path , C .MANIFEST_FILE ),
270+ )
271+ cmd_output ('git' , '-C' , path , 'add' , '.' )
272+ cmd_output ('git' , '-C' , path , 'commit' , '-m' , 'Remove foo' )
277273
278274 yield auto_namedtuple (path = path , original_sha = original_sha )
279275
0 commit comments