diff --git a/demisto_sdk/commands/content_graph/commands/update.py b/demisto_sdk/commands/content_graph/commands/update.py index f4440715901..177659803e4 100644 --- a/demisto_sdk/commands/content_graph/commands/update.py +++ b/demisto_sdk/commands/content_graph/commands/update.py @@ -30,11 +30,11 @@ def should_update_graph( content_graph_interface: ContentGraphInterface, use_git: bool, - git_util: GitUtil, + git_util: Optional[GitUtil], imported_path: Optional[Path] = None, packs_to_update: Optional[List[str]] = None, ): - if content_graph_interface.commit: + if content_graph_interface.commit and git_util: try: changed_pack_ids = git_util.get_all_changed_pack_ids( content_graph_interface.commit @@ -97,14 +97,25 @@ def update_content_graph( logger.info("A path to import the graph from was not provided, using git") use_git = True - git_util = GitUtil() - is_external_repo = is_external_repository() + try: + git_util = GitUtil() + is_external_repo = is_external_repository() + except Exception as e: + logger.debug( + f"Could not initialize GitUtil: {e}. Assuming external repo and skipping git operations." + ) + # If git is not available, we can't use git-based updates + # This can happen in CI/CD environments where the working directory is not a git repo + use_git = False + git_util = None # type: ignore[assignment] + is_external_repo = True if is_external_repo: packs_to_update = get_all_repo_pack_ids() packs_to_update = list(packs_to_update) if packs_to_update else [] builder = ContentGraphBuilder(content_graph_interface) - if not should_update_graph( + # If git_util is None, we can't check if we should update, so assume we should not + if git_util and not should_update_graph( content_graph_interface, use_git, git_util, imported_path, packs_to_update ): logger.info( @@ -145,7 +156,12 @@ def update_content_graph( content_graph_interface, marketplace, dependencies, output_path ) return - if use_git and (commit := content_graph_interface.commit) and not is_external_repo: + if ( + use_git + and git_util + and (commit := content_graph_interface.commit) + and not is_external_repo + ): try: git_util.get_all_changed_pack_ids(commit) except Exception as e: diff --git a/demisto_sdk/commands/validate/initializer.py b/demisto_sdk/commands/validate/initializer.py index c7a58eda924..6be0b24a757 100644 --- a/demisto_sdk/commands/validate/initializer.py +++ b/demisto_sdk/commands/validate/initializer.py @@ -743,7 +743,9 @@ def git_paths_to_basecontent_set( old_path = file_path if isinstance(file_path, tuple): file_path, old_path = file_path - obj = BaseContent.from_path(file_path, raise_on_exception=True) + obj = BaseContent.from_path( + file_path, git_sha=None, raise_on_exception=True + ) if obj: obj.git_sha = current_git_sha obj.git_status = git_status diff --git a/demisto_sdk/commands/validate/validators/base_validator.py b/demisto_sdk/commands/validate/validators/base_validator.py index 9b29d60293b..4c155fbe833 100644 --- a/demisto_sdk/commands/validate/validators/base_validator.py +++ b/demisto_sdk/commands/validate/validators/base_validator.py @@ -176,10 +176,13 @@ def graph(self) -> ContentGraphInterface: if not self.graph_interface: logger.info("Graph validations were selected, will init graph") BaseValidator.graph_interface = ContentGraphInterface() - update_content_graph( - BaseValidator.graph_interface, - use_git=True, - ) + # Only update the graph if it's not already alive/initialized + # This prevents re-running git operations that may fail in CI/CD environments + if not BaseValidator.graph_interface.is_alive(): + update_content_graph( + BaseValidator.graph_interface, + use_git=True, + ) return self.graph_interface def __dir__(self):