Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96e9d1b

Browse files
committed
Restore git 1.8 support
1 parent 179f11b commit 96e9d1b

10 files changed

Lines changed: 35 additions & 38 deletions

File tree

latest-git.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
set -ex
44
git clone git://github.com/git/git --depth 1 /tmp/git
55
pushd /tmp/git
6-
make prefix=/tmp/git -j 8 all
7-
make prefix=/tmp/git install
6+
make prefix=/tmp/git -j8 install
87
popd

pre_commit/commands/autoupdate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ def _update_repo(repo_config, runner, tags_only):
3434
"""
3535
repo_path = runner.store.clone(repo_config['repo'], repo_config['rev'])
3636

37-
cmd_output('git', '-C', repo_path, 'fetch')
38-
tag_cmd = ('git', '-C', repo_path, 'describe', 'origin/master', '--tags')
37+
cmd_output('git', 'fetch', cwd=repo_path)
38+
tag_cmd = ('git', 'describe', 'origin/master', '--tags')
3939
if tags_only:
4040
tag_cmd += ('--abbrev=0',)
4141
else:
4242
tag_cmd += ('--exact',)
4343
try:
44-
rev = cmd_output(*tag_cmd)[1].strip()
44+
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
4545
except CalledProcessError:
46-
tag_cmd = ('git', '-C', repo_path, 'rev-parse', 'origin/master')
47-
rev = cmd_output(*tag_cmd)[1].strip()
46+
tag_cmd = ('git', 'rev-parse', 'origin/master')
47+
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
4848

4949
# Don't bother trying to update if our rev is the same
5050
if rev == repo_config['rev']:

pre_commit/make_archives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def make_archive(name, repo, ref, destdir):
4141
with tmpdir() as tempdir:
4242
# Clone the repository to the temporary directory
4343
cmd_output('git', 'clone', repo, tempdir)
44-
cmd_output('git', '-C', tempdir, 'checkout', ref)
44+
cmd_output('git', 'checkout', ref, cwd=tempdir)
4545

4646
# We don't want the '.git' directory
4747
# It adds a bunch of size to the archive and we don't use it at

pre_commit/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def clone_strategy(directory):
144144
env = no_git_env()
145145

146146
def _git_cmd(*args):
147-
return cmd_output('git', '-C', directory, *args, env=env)
147+
return cmd_output('git', *args, cwd=directory, env=env)
148148

149149
_git_cmd('clone', '--no-checkout', repo, '.')
150150
_git_cmd('reset', ref, '--hard')
@@ -163,7 +163,7 @@ def make_local_strategy(directory):
163163

164164
# initialize the git repository so it looks more like cloned repos
165165
def _git_cmd(*args):
166-
cmd_output('git', '-C', directory, *args, env=env)
166+
cmd_output('git', *args, cwd=directory, env=env)
167167

168168
_git_cmd('init', '.')
169169
_git_cmd('config', 'remote.origin.url', '<<unknown>>')

testing/fixtures.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def git_dir(tempdir_factory):
2929
def make_repo(tempdir_factory, repo_source):
3030
path = git_dir(tempdir_factory)
3131
copy_tree_to_path(get_resource_path(repo_source), path)
32-
cmd_output('git', '-C', path, 'add', '.')
33-
cmd_output('git', '-C', path, 'commit', '-m', 'Add hooks')
32+
cmd_output('git', 'add', '.', cwd=path)
33+
cmd_output('git', 'commit', '-m', 'Add hooks', cwd=path)
3434
return path
3535

3636

@@ -114,15 +114,14 @@ def write_config(directory, config, config_file=C.CONFIG_FILE):
114114

115115
def add_config_to_repo(git_path, config, config_file=C.CONFIG_FILE):
116116
write_config(git_path, config, config_file=config_file)
117-
cmd_output('git', '-C', git_path, 'add', config_file)
118-
cmd_output('git', '-C', git_path, 'commit', '-m', 'Add hooks config')
117+
cmd_output('git', 'add', config_file, cwd=git_path)
118+
cmd_output('git', 'commit', '-m', 'Add hooks config', cwd=git_path)
119119
return git_path
120120

121121

122122
def remove_config_from_repo(git_path, config_file=C.CONFIG_FILE):
123-
os.unlink(os.path.join(git_path, config_file))
124-
cmd_output('git', '-C', git_path, 'add', config_file)
125-
cmd_output('git', '-C', git_path, 'commit', '-m', 'Remove hooks config')
123+
cmd_output('git', 'rm', config_file, cwd=git_path)
124+
cmd_output('git', 'commit', '-m', 'Remove hooks config', cwd=git_path)
126125
return git_path
127126

128127

tests/commands/autoupdate_test.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ 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-
cmd_output('git', '-C', path, 'mv', C.MANIFEST_FILE, 'nope.yaml')
66-
cmd_output('git', '-C', path, 'commit', '-m', 'simulate old repo')
65+
cmd_output('git', 'mv', C.MANIFEST_FILE, 'nope.yaml', cwd=path)
66+
cmd_output('git', 'commit', '-m', 'simulate old repo', cwd=path)
6767
# Assume this is the revision the user's old repository was at
6868
rev = git.head_rev(path)
69-
cmd_output('git', '-C', path, 'mv', 'nope.yaml', C.MANIFEST_FILE)
70-
cmd_output('git', '-C', path, 'commit', '-m', 'move hooks file')
69+
cmd_output('git', 'mv', 'nope.yaml', C.MANIFEST_FILE, cwd=path)
70+
cmd_output('git', 'commit', '-m', 'move hooks file', cwd=path)
7171
update_rev = git.head_rev(path)
7272

7373
config['rev'] = rev
@@ -86,7 +86,7 @@ def out_of_date_repo(tempdir_factory):
8686
original_rev = git.head_rev(path)
8787

8888
# Make a commit
89-
cmd_output('git', '-C', path, 'commit', '--allow-empty', '-m', 'foo')
89+
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo', cwd=path)
9090
head_rev = git.head_rev(path)
9191

9292
yield auto_namedtuple(
@@ -221,7 +221,7 @@ def test_loses_formatting_when_not_detectable(
221221

222222
@pytest.fixture
223223
def tagged_repo(out_of_date_repo):
224-
cmd_output('git', '-C', out_of_date_repo.path, 'tag', 'v1.2.3')
224+
cmd_output('git', 'tag', 'v1.2.3', cwd=out_of_date_repo.path)
225225
yield out_of_date_repo
226226

227227

@@ -240,8 +240,7 @@ def test_autoupdate_tagged_repo(
240240

241241
@pytest.fixture
242242
def tagged_repo_with_more_commits(tagged_repo):
243-
cmd = ('git', '-C', tagged_repo.path, 'commit', '--allow-empty', '-mfoo')
244-
cmd_output(*cmd)
243+
cmd_output('git', 'commit', '--allow-empty', '-mfoo', cwd=tagged_repo.path)
245244
yield tagged_repo
246245

247246

@@ -268,8 +267,8 @@ def hook_disappearing_repo(tempdir_factory):
268267
get_resource_path('manifest_without_foo.yaml'),
269268
os.path.join(path, C.MANIFEST_FILE),
270269
)
271-
cmd_output('git', '-C', path, 'add', '.')
272-
cmd_output('git', '-C', path, 'commit', '-m', 'Remove foo')
270+
cmd_output('git', 'add', '.', cwd=path)
271+
cmd_output('git', 'commit', '-m', 'Remove foo', cwd=path)
273272

274273
yield auto_namedtuple(path=path, original_rev=original_rev)
275274

tests/commands/install_uninstall_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def test_install_pre_commit_and_run_custom_path(tempdir_factory):
161161
def test_install_in_submodule_and_run(tempdir_factory):
162162
src_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
163163
parent_path = git_dir(tempdir_factory)
164-
cmd_output('git', '-C', parent_path, 'submodule', 'add', src_path, 'sub')
165-
cmd_output('git', '-C', parent_path, 'commit', '-m', 'foo')
164+
cmd_output('git', 'submodule', 'add', src_path, 'sub', cwd=parent_path)
165+
cmd_output('git', 'commit', '-m', 'foo', cwd=parent_path)
166166

167167
sub_pth = os.path.join(parent_path, 'sub')
168168
with cwd(sub_pth):

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def _make_conflict():
6969
def in_merge_conflict(tempdir_factory):
7070
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
7171
open(os.path.join(path, 'dummy'), 'a').close()
72-
cmd_output('git', '-C', path, 'add', 'dummy')
73-
cmd_output('git', '-C', path, 'commit', '-m', 'Add config.')
72+
cmd_output('git', 'add', 'dummy', cwd=path)
73+
cmd_output('git', 'commit', '-m', 'Add config.', cwd=path)
7474

7575
conflict_path = tempdir_factory.get()
7676
cmd_output('git', 'clone', path, conflict_path)
@@ -83,8 +83,8 @@ def in_merge_conflict(tempdir_factory):
8383
def in_conflicting_submodule(tempdir_factory):
8484
git_dir_1 = git_dir(tempdir_factory)
8585
git_dir_2 = git_dir(tempdir_factory)
86-
cmd_output('git', '-C', git_dir_2, 'commit', '--allow-empty', '-minit!')
87-
cmd_output('git', '-C', git_dir_1, 'submodule', 'add', git_dir_2, 'sub')
86+
cmd_output('git', 'commit', '--allow-empty', '-minit!', cwd=git_dir_2)
87+
cmd_output('git', 'submodule', 'add', git_dir_2, 'sub', cwd=git_dir_1)
8888
with cwd(os.path.join(git_dir_1, 'sub')):
8989
_make_conflict()
9090
yield

tests/make_archives_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def test_make_archive(tempdir_factory):
1717
git_path = git_dir(tempdir_factory)
1818
# Add a files to the git directory
1919
open(os.path.join(git_path, 'foo'), 'a').close()
20-
cmd_output('git', '-C', git_path, 'add', '.')
21-
cmd_output('git', '-C', git_path, 'commit', '-m', 'foo')
20+
cmd_output('git', 'add', '.', cwd=git_path)
21+
cmd_output('git', 'commit', '-m', 'foo', cwd=git_path)
2222
# We'll use this rev
2323
head_rev = git.head_rev(git_path)
2424
# And check that this file doesn't exist
2525
open(os.path.join(git_path, 'bar'), 'a').close()
26-
cmd_output('git', '-C', git_path, 'add', '.')
27-
cmd_output('git', '-C', git_path, 'commit', '-m', 'bar')
26+
cmd_output('git', 'add', '.', cwd=git_path)
27+
cmd_output('git', 'commit', '-m', 'bar', cwd=git_path)
2828

2929
# Do the thing
3030
archive_path = make_archives.make_archive(

tests/staged_files_only_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def submodule_with_commits(tempdir_factory):
199199

200200

201201
def checkout_submodule(rev):
202-
cmd_output('git', '-C', 'sub', 'checkout', rev)
202+
cmd_output('git', 'checkout', rev, cwd='sub')
203203

204204

205205
@pytest.fixture

0 commit comments

Comments
 (0)