MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _repo_ref

Function _repo_ref

pre_commit/commands/try_repo.py:21–48  ·  view source on GitHub ↗
(tmpdir: str, repo: str, ref: str | None)

Source from the content-addressed store, hash-verified

19
20
21def _repo_ref(tmpdir: str, repo: str, ref: str | None) -> tuple[str, str]:
22 # if `ref` is explicitly passed, use it
23 if ref is not None:
24 return repo, ref
25
26 ref = git.head_rev(repo)
27 # if it exists on disk, we'll try and clone it with the local changes
28 if os.path.exists(repo) and git.has_diff('HEAD', repo=repo):
29 logger.warning('Creating temporary repo with uncommitted changes...')
30
31 shadow = os.path.join(tmpdir, 'shadow-repo')
32 cmd_output_b('git', 'clone', repo, shadow)
33 cmd_output_b('git', 'checkout', ref, '-b', '_pc_tmp', cwd=shadow)
34
35 idx = git.git_path('index', repo=shadow)
36 objs = git.git_path('objects', repo=shadow)
37 env = dict(os.environ, GIT_INDEX_FILE=idx, GIT_OBJECT_DIRECTORY=objs)
38
39 staged_files = git.get_staged_files(cwd=repo)
40 if staged_files:
41 xargs(('git', 'add', '--'), staged_files, cwd=repo, env=env)
42
43 cmd_output_b('git', 'add', '-u', cwd=repo, env=env)
44 git.commit(repo=shadow)
45
46 return shadow, git.head_rev(shadow)
47 else:
48 return repo, ref
49
50
51def try_repo(args: argparse.Namespace) -> int:

Callers 1

try_repoFunction · 0.85

Calls 3

cmd_output_bFunction · 0.90
xargsFunction · 0.90
existsMethod · 0.80

Tested by

no test coverage detected