(
local_sources: list[dict[str, str]],
scope_mode: str,
diff_base: str | None,
non_interactive: bool,
env: dict[str, str] | None = None,
)
| 963 | |
| 964 | |
| 965 | def resolve_diff_scope_context( |
| 966 | local_sources: list[dict[str, str]], |
| 967 | scope_mode: str, |
| 968 | diff_base: str | None, |
| 969 | non_interactive: bool, |
| 970 | env: dict[str, str] | None = None, |
| 971 | ) -> DiffScopeResult: |
| 972 | if scope_mode not in _SUPPORTED_SCOPE_MODES: |
| 973 | raise ValueError(f"Unsupported scope mode: {scope_mode}") |
| 974 | |
| 975 | env_map = dict(os.environ if env is None else env) |
| 976 | |
| 977 | if scope_mode == "full": |
| 978 | return DiffScopeResult( |
| 979 | active=False, |
| 980 | mode=scope_mode, |
| 981 | metadata={"active": False, "mode": scope_mode}, |
| 982 | ) |
| 983 | |
| 984 | if scope_mode == "auto": |
| 985 | should_activate = _should_activate_auto_scope(local_sources, non_interactive, env_map) |
| 986 | if not should_activate: |
| 987 | return DiffScopeResult( |
| 988 | active=False, |
| 989 | mode=scope_mode, |
| 990 | metadata={"active": False, "mode": scope_mode}, |
| 991 | ) |
| 992 | |
| 993 | if not local_sources: |
| 994 | raise ValueError("Diff-scope is active, but no local repository targets were provided.") |
| 995 | |
| 996 | repo_scopes: list[RepoDiffScope] = [] |
| 997 | skipped_non_git: list[str] = [] |
| 998 | skipped_diff_scope: list[str] = [] |
| 999 | for source in local_sources: |
| 1000 | source_path = source.get("source_path") |
| 1001 | if not source_path: |
| 1002 | continue |
| 1003 | if not _is_git_repo(Path(source_path)): |
| 1004 | skipped_non_git.append(source_path) |
| 1005 | continue |
| 1006 | try: |
| 1007 | repo_scopes.append(_resolve_repo_diff_scope(source, diff_base, env_map)) |
| 1008 | except ValueError as e: |
| 1009 | if scope_mode == "auto": |
| 1010 | skipped_diff_scope.append(f"{source_path} (diff-scope skipped: {e})") |
| 1011 | continue |
| 1012 | raise |
| 1013 | |
| 1014 | if not repo_scopes: |
| 1015 | if scope_mode == "auto": |
| 1016 | metadata: dict[str, Any] = {"active": False, "mode": scope_mode} |
| 1017 | if skipped_non_git: |
| 1018 | metadata["skipped_non_git_sources"] = skipped_non_git |
| 1019 | if skipped_diff_scope: |
| 1020 | metadata["skipped_diff_scope_sources"] = skipped_diff_scope |
| 1021 | return DiffScopeResult(active=False, mode=scope_mode, metadata=metadata) |
| 1022 |
no test coverage detected