MCPcopy Index your code
hub / github.com/openai/plugins / git_target_metadata

Function git_target_metadata

plugins/codex-security/scripts/workbench_target.py:416–446  ·  view source on GitHub ↗
(target: Path)

Source from the content-addressed store, hash-verified

414
415
416def git_target_metadata(target: Path) -> dict[str, Any]:
417 is_git = git_output(target, "rev-parse", "--git-dir") is not None
418 is_worktree = git_output(target, "rev-parse", "--is-inside-work-tree") == "true"
419 revision = git_output(target, "rev-parse", "--verify", "HEAD")
420 repository_root = git_output(target, "rev-parse", "--show-toplevel") if is_worktree else None
421 supported = (
422 is_git
423 and is_worktree
424 and revision is not None
425 and repository_root is not None
426 and Path(repository_root).resolve() == target
427 )
428 metadata: dict[str, Any] = {
429 "hasHead": revision is not None,
430 "isGit": is_git,
431 "isWorktree": is_worktree,
432 "reviewChangesSupported": supported,
433 }
434 if not is_git:
435 return metadata
436 branch = git_output(target, "symbolic-ref", "--quiet", "--short", "HEAD")
437 metadata.update({"branch": branch, "detachedHead": revision is not None and branch is None})
438 if revision is not None:
439 metadata.update(
440 {
441 "commitSubject": git_output(target, "show", "-s", "--format=%s", "HEAD"),
442 "revision": revision,
443 "shortRevision": revision[:7],
444 }
445 )
446 return metadata
447
448
449def main() -> None:

Callers 4

inspect_targetFunction · 0.90
require_scannable_targetFunction · 0.90
workspace_stateFunction · 0.90

Calls 1

git_outputFunction · 0.85

Tested by

no test coverage detected