mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2860 from pre-commit/autoupdate-dash-C
use -C for git commands in autoupdate
This commit is contained in:
commit
27d77fc8bc
1 changed files with 13 additions and 24 deletions
|
|
@ -34,44 +34,33 @@ class RevInfo(NamedTuple):
|
||||||
return cls(config['repo'], config['rev'], None)
|
return cls(config['repo'], config['rev'], None)
|
||||||
|
|
||||||
def update(self, tags_only: bool, freeze: bool) -> RevInfo:
|
def update(self, tags_only: bool, freeze: bool) -> RevInfo:
|
||||||
git_cmd = ('git', *git.NO_FS_MONITOR)
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
_git = ('git', *git.NO_FS_MONITOR, '-C', tmp)
|
||||||
|
|
||||||
if tags_only:
|
if tags_only:
|
||||||
tag_cmd = (
|
tag_opt = '--abbrev=0'
|
||||||
*git_cmd, 'describe',
|
|
||||||
'FETCH_HEAD', '--tags', '--abbrev=0',
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
tag_cmd = (
|
tag_opt = '--exact'
|
||||||
*git_cmd, 'describe',
|
tag_cmd = (*_git, 'describe', 'FETCH_HEAD', '--tags', tag_opt)
|
||||||
'FETCH_HEAD', '--tags', '--exact',
|
|
||||||
)
|
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
|
||||||
git.init_repo(tmp, self.repo)
|
git.init_repo(tmp, self.repo)
|
||||||
|
cmd_output_b(*_git, 'config', 'extensions.partialClone', 'true')
|
||||||
cmd_output_b(
|
cmd_output_b(
|
||||||
*git_cmd, 'config', 'extensions.partialClone', 'true',
|
*_git, 'fetch', 'origin', 'HEAD',
|
||||||
cwd=tmp,
|
|
||||||
)
|
|
||||||
cmd_output_b(
|
|
||||||
*git_cmd, 'fetch', 'origin', 'HEAD',
|
|
||||||
'--quiet', '--filter=blob:none', '--tags',
|
'--quiet', '--filter=blob:none', '--tags',
|
||||||
cwd=tmp,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rev = cmd_output(*tag_cmd, cwd=tmp)[1].strip()
|
rev = cmd_output(*tag_cmd)[1].strip()
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
cmd = (*git_cmd, 'rev-parse', 'FETCH_HEAD')
|
rev = cmd_output(*_git, 'rev-parse', 'FETCH_HEAD')[1].strip()
|
||||||
rev = cmd_output(*cmd, cwd=tmp)[1].strip()
|
|
||||||
else:
|
else:
|
||||||
if tags_only:
|
if tags_only:
|
||||||
rev = git.get_best_candidate_tag(rev, tmp)
|
rev = git.get_best_candidate_tag(rev, tmp)
|
||||||
|
|
||||||
frozen = None
|
frozen = None
|
||||||
if freeze:
|
if freeze:
|
||||||
exact_rev_cmd = (*git_cmd, 'rev-parse', rev)
|
exact = cmd_output(*_git, 'rev-parse', rev)[1].strip()
|
||||||
exact = cmd_output(*exact_rev_cmd, cwd=tmp)[1].strip()
|
|
||||||
if exact != rev:
|
if exact != rev:
|
||||||
rev, frozen = exact, rev
|
rev, frozen = exact, rev
|
||||||
return self._replace(rev=rev, frozen=frozen)
|
return self._replace(rev=rev, frozen=frozen)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue