Skip to content

[BUG] crewai tool publish --force still runs git checks and fails outside a repository #9721

Done

Description

@Kiko0301

Description

crewai tool publish --force is documented as "Bypasses Git remote validations", but ToolCommand.publish() builds git.Repository() before it looks at force:

  • lib/cli/src/crewai_cli/tools/main.py:103-104
def publish(self, is_public: bool, force: bool = False) -> None:
    if not git.Repository().is_synced() and not force:

The Repository constructor (lib/cli/src/crewai_cli/git.py:28-38) checks that git is installed, that the current directory is a git repository, and then runs git fetch. All of that happens before not force is evaluated, so with --force:

  • publishing outside a git repository raises an uncaught ValueError: . is not a Git repository. instead of publishing;
  • publishing without a reachable remote raises ValueError: Git fetch failed ... instead of publishing.

The sibling crewai skill publish --force path already puts the whole validation block behind if not force: (lib/cli/src/crewai_cli/skills/main.py:238-272), so the two publish commands behave differently.

Steps to Reproduce

from unittest.mock import patch

from crewai_cli.tools.main import ToolCommand

tool = object.__new__(ToolCommand)  # bypass login/telemetry setup
with patch("crewai_cli.tools.main.git.Repository", side_effect=ValueError("not a Git repository")):
    try:
        tool.publish(is_public=True, force=True)
    except ValueError as exc:
        print("raised:", exc)

Output on current main (after the project-metadata reads):

raised: not a Git repository

Expected Behavior

--force skips the git validation entirely, so the repository is never constructed and publishing continues. The test suite already asserts the force=True + out-of-sync case succeeds (lib/cli/tests/tools/test_main.py::test_publish_when_not_in_sync_and_force), but it mocks the constructor away and does not cover a repository that cannot be checked at all.

AI assistance

I used an AI coding agent to investigate, reproduce, and prepare this report, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions