MCPcopy Index your code
hub / github.com/usestrix/strix / _resolve_repo_diff_scope

Function _resolve_repo_diff_scope

strix/interface/utils.py:898–962  ·  view source on GitHub ↗
(
    source: dict[str, str], diff_base: str | None, env: dict[str, str]
)

Source from the content-addressed store, hash-verified

896
897
898def _resolve_repo_diff_scope(
899 source: dict[str, str], diff_base: str | None, env: dict[str, str]
900) -> RepoDiffScope:
901 source_path = source.get("source_path", "")
902 workspace_subdir = source.get("workspace_subdir")
903 repo_path = Path(source_path)
904
905 if not _is_git_repo(repo_path):
906 raise ValueError(f"Source is not a git repository: {source_path}")
907
908 if _is_repo_shallow(repo_path):
909 raise ValueError(
910 "Strix requires full git history for diff-scope. Please set fetch-depth: 0 "
911 "in your CI config."
912 )
913
914 base_ref = _resolve_base_ref(repo_path, diff_base, env)
915 merge_base_result = _run_git_command(repo_path, ["merge-base", base_ref, "HEAD"], check=False)
916 if merge_base_result.returncode != 0:
917 stderr = merge_base_result.stderr.strip()
918 raise ValueError(
919 f"Unable to compute merge-base against '{base_ref}' for '{source_path}'. "
920 f"{stderr or 'Ensure the base branch history is fetched and reachable.'}"
921 )
922
923 merge_base = merge_base_result.stdout.strip()
924 if not merge_base:
925 raise ValueError(
926 f"Unable to compute merge-base against '{base_ref}' for '{source_path}'. "
927 "Ensure the base branch history is fetched and reachable."
928 )
929
930 diff_result = _run_git_command_raw(
931 repo_path,
932 [
933 "diff",
934 "--name-status",
935 "-z",
936 "--find-renames",
937 "--find-copies",
938 f"{merge_base}...HEAD",
939 ],
940 check=False,
941 )
942 if diff_result.returncode != 0:
943 stderr = diff_result.stderr.decode("utf-8", errors="replace").strip()
944 raise ValueError(
945 f"Unable to resolve changed files for '{source_path}'. "
946 f"{stderr or 'Ensure the repository has enough history for diff-scope.'}"
947 )
948
949 entries = _parse_name_status_z(diff_result.stdout)
950 classified = _classify_diff_entries(entries)
951
952 return RepoDiffScope(
953 source_path=source_path,
954 workspace_subdir=workspace_subdir,
955 base_ref=base_ref,

Callers 1

Calls 8

_is_git_repoFunction · 0.85
_is_repo_shallowFunction · 0.85
_resolve_base_refFunction · 0.85
_run_git_commandFunction · 0.85
_run_git_command_rawFunction · 0.85
_parse_name_status_zFunction · 0.85
_classify_diff_entriesFunction · 0.85
RepoDiffScopeClass · 0.85

Tested by

no test coverage detected