-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Fix git worktree detection for dda env dev start #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
misteriaud
commented
Jan 28, 2026
Comment on lines
474
to
479
| # Strategy 2: Check parent directory (existing behavior, backward compatible) | ||
| parent_repo_path = cwd.parent / repo_name | ||
| if parent_repo_path.is_dir(): | ||
| if self._is_matching_repository(parent_repo_path, repo_name): | ||
| return parent_repo_path | ||
| # Fallback: If not a git repo but directory exists, use it for backward compat | ||
| return parent_repo_path |
Member
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought: I'm not sure if we want to keep this behavior. In which case we would like to cover this ?
b2c2717 to
78ce6fe
Compare
Previously, `dda env dev start` failed when run from git worktrees with arbitrary directory names because it assumed repository directories were named exactly as the repository (e.g., "datadog-agent"). This commit adds git-aware repository resolution that: - Detects git repositories using remote URL, working for both regular repos and worktrees regardless of directory name - Maintains full backward compatibility with non-git directory lookup - Handles edge cases: missing git, no remote, nested structures Implementation: - Added `_resolve_repository_path()` with multi-strategy resolution - Added `_is_matching_repository()` using git remote URL detection - Updated repository mounting to use new git-aware resolver - Added comprehensive tests for worktree scenarios Fixes issue where worktrees like `.worktrees/my_feature` would fail with "Local repository not found: datadog-agent" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
78ce6fe to
68a1c74
Compare
When running from a git worktree, the worktree's .git file points to the main repository's .git/worktrees/ directory. If we only mount the worktree directory, git commands fail inside the container because the referenced .git directory doesn't exist. This change detects worktrees by checking if .git is a file (not a directory), reads the gitdir path, and resolves to the main repository root. The main repository is then mounted instead, ensuring git commands work correctly inside the container. Updated test to verify worktrees resolve to main repo path.
- repo_path() now detects if running from a worktree and returns the correct working directory path (e.g., /root/repos/repo/.worktrees/branch) - Mount destination is always the base repo path without worktree subdirectory - Detects external worktrees and shows helpful error message - Working directory correctly points to worktree subdirectory when running commands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
dda env dev startto work from git worktrees with arbitrary directory names instead of requiring the directory to be named exactly as the repository.Problem
The command failed when run from worktrees like
/path/to/datadog-agent/.worktrees/my_feature_branchwith error:The code assumed repository directories were named exactly as the repository (e.g., "datadog-agent"), which breaks with worktrees that have arbitrary directory names.
Solution
Added git-aware repository resolution that uses
git config --get remote.origin.urlto identify repositories by their remote URL rather than directory name. This works for:Testing
/tmp/datadog-agent/.worktrees/test_observer_feature