Skip to content

fix(git_repository): open repositories that have no .gitignore file - #2209

Open
DZH166 wants to merge 1 commit into
FoundationAgents:mainfrom
DZH166:fix/git-repository-without-gitignore
Open

DZH166 wants to merge 1 commit into
FoundationAgents:mainfrom
DZH166:fix/git-repository-without-gitignore

Conversation

@DZH166

@DZH166 DZH166 commented Nov 18, 2026

Copy link
Copy Markdown

Problem

GitRepository.open() parses the ignore file unconditionally:

self._gitignore_rules = parse_gitignore(full_path=self._root_path / ".gitignore")

parse_gitignore opens the file immediately, so any valid git repository without a .gitignore raises FileNotFoundError in the constructor. The same unguarded call exists in rename_root(), and filter_gitignore() then assumes self._gitignore_rules is callable, so leaving it unset would raise TypeError.

This is hit whenever MetaGPT is pointed at an existing repository (ProjectRepo(path) -> WritePRD/DesignAPI/ProjectManagement/QAEngineer/Engineer.base_env), where a missing .gitignore is perfectly normal.

before: GitRepository(local_path=repo_without_gitignore, auto_init=False)
        -> FileNotFoundError: '.../.gitignore'
after : repository opens, filter_gitignore(['main.py']) -> ['main.py']

Fix

Add a _parse_gitignore() helper that returns None when the file is absent (used by open()/_init()/rename_root()), and make filter_gitignore() skip filtering when no rules were loaded.

Tests

tests/metagpt/utils/test_git_repository.py::test_open_repo_without_gitignore:

pytest tests/metagpt/utils/test_git_repository.py::test_open_repo_without_gitignore -q -o addopts="" -o asyncio_mode=auto
# before: 1 failed   after: 1 passed

This branch is waiting to be deployed

1 waiting deployment
unittest — 9bdd86fe Waiting Nov 18, 2026 by DZH166 via build (3.9) #1775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant