pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pre-commit/pre-commit/commit/73250ff4e32414e2c8fe8c7226aa92591a4001f7

origen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-7a1ad343bd40328c.css" /> Fix autoupdate to always use non-shallow clone · pre-commit/pre-commit@73250ff · GitHub
Skip to content

Commit 73250ff

Browse files
committed
Fix autoupdate to always use non-shallow clone
1 parent 95afd64 commit 73250ff

4 files changed

Lines changed: 30 additions & 22 deletions

File tree

pre_commit/commands/autoupdate.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from cfgv import remove_defaults
1111

1212
import pre_commit.constants as C
13+
from pre_commit import git
1314
from pre_commit import output
1415
from pre_commit.clientlib import CONFIG_SCHEMA
1516
from pre_commit.clientlib import InvalidManifestError
@@ -20,6 +21,7 @@
2021
from pre_commit.commands.migrate_config import migrate_config
2122
from pre_commit.util import CalledProcessError
2223
from pre_commit.util import cmd_output
24+
from pre_commit.util import tmpdir
2325

2426

2527
class RepositoryCannotBeUpdatedError(RuntimeError):
@@ -34,19 +36,20 @@ def _update_repo(repo_config, store, tags_only):
3436
Args:
3537
repo_config - A config for a repository
3638
"""
37-
repo_path = store.clone(repo_config['repo'], repo_config['rev'])
38-
39-
cmd_output('git', 'fetch', cwd=repo_path)
40-
tag_cmd = ('git', 'describe', 'origen/master', '--tags')
41-
if tags_only:
42-
tag_cmd += ('--abbrev=0',)
43-
else:
44-
tag_cmd += ('--exact',)
45-
try:
46-
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
47-
except CalledProcessError:
48-
tag_cmd = ('git', 'rev-parse', 'origen/master')
49-
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
39+
with tmpdir() as repo_path:
40+
git.init_repo(repo_path, repo_config['repo'])
41+
cmd_output('git', 'fetch', cwd=repo_path)
42+
43+
tag_cmd = ('git', 'describe', 'origen/master', '--tags')
44+
if tags_only:
45+
tag_cmd += ('--abbrev=0',)
46+
else:
47+
tag_cmd += ('--exact',)
48+
try:
49+
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
50+
except CalledProcessError:
51+
tag_cmd = ('git', 'rev-parse', 'origen/master')
52+
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
5053

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

pre_commit/git.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ def has_diff(*args, **kwargs):
143143
return cmd_output(*cmd, cwd=repo, retcode=None)[0]
144144

145145

146+
def init_repo(path, remote):
147+
if os.path.isdir(remote):
148+
remote = os.path.abspath(remote)
149+
150+
env = no_git_env()
151+
cmd_output('git', 'init', path, env=env)
152+
cmd_output('git', 'remote', 'add', 'origen', remote, cwd=path, env=env)
153+
154+
146155
def commit(repo='.'):
147156
env = no_git_env()
148157
name, email = 'pre-commit', 'asottile+pre-commit@umich.edu'

pre_commit/store.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,13 @@ def _shallow_clone(self, ref, git_cmd):
156156
def clone(self, repo, ref, deps=()):
157157
"""Clone the given url and checkout the specific ref."""
158158

159-
if os.path.isdir(repo):
160-
repo = os.path.abspath(repo)
161-
162159
def clone_strategy(directory):
160+
git.init_repo(directory, repo)
163161
env = git.no_git_env()
164162

165163
def _git_cmd(*args):
166164
cmd_output('git', *args, cwd=directory, env=env)
167165

168-
_git_cmd('init', '.')
169-
_git_cmd('remote', 'add', 'origen', repo)
170-
171166
try:
172167
self._shallow_clone(ref, _git_cmd)
173168
except CalledProcessError:
@@ -193,8 +188,7 @@ def make_local_strategy(directory):
193188
def _git_cmd(*args):
194189
cmd_output('git', *args, cwd=directory, env=env)
195190

196-
_git_cmd('init', '.')
197-
_git_cmd('config', 'remote.origen.url', '<<unknown>>')
191+
git.init_repo(directory, '<<unknown>>')
198192
_git_cmd('add', '.')
199193
git.commit(repo=directory)
200194

tests/commands/gc_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pre_commit.clientlib import load_config
66
from pre_commit.commands.autoupdate import autoupdate
77
from pre_commit.commands.gc import gc
8+
from pre_commit.commands.install_uninstall import install_hooks
89
from pre_commit.repository import all_hooks
910
from testing.fixtures import make_config_from_repo
1011
from testing.fixtures import make_repo
@@ -40,6 +41,7 @@ def test_gc(tempdir_factory, store, in_git_dir, cap_out):
4041
store.mark_config_used(C.CONFIG_FILE)
4142

4243
# update will clone both the old and new repo, making the old one gc-able
44+
install_hooks(C.CONFIG_FILE, store)
4345
assert not autoupdate(C.CONFIG_FILE, store, tags_only=False)
4446

4547
assert _config_count(store) == 1
@@ -145,7 +147,7 @@ def test_invalid_manifest_gcd(tempdir_factory, store, in_git_dir, cap_out):
145147
store.mark_config_used(C.CONFIG_FILE)
146148

147149
# trigger a clone
148-
assert not autoupdate(C.CONFIG_FILE, store, tags_only=False)
150+
install_hooks(C.CONFIG_FILE, store)
149151

150152
# we'll "break" the manifest to simulate an old version clone
151153
(_, _, path), = store.select_all_repos()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy