Conversation
Wrap get_default_branch in try/except so workspace creation remains robust when the default branch cannot be resolved (network issues, misconfigured repos). Falls back to "HEAD" on error or empty return. Also tighten test_branch_custom_start_point to assert no remote push occurs when create_remote=False.
Reviewer's GuideAdds robust handling around default-branch resolution in workspace cloning by falling back to HEAD when the default branch cannot be determined, and strengthens branch manager tests to verify no remote push occurs when create_remote is False. Sequence diagram for ensure_branch default_branch fallback handlingsequenceDiagram
participant WorkspaceClone
participant RepoManager
participant WorktreeBranchManager
WorkspaceClone->>RepoManager: get_default_branch(owner, repo)
alt get_default_branch succeeds with non_empty_branch
RepoManager-->>WorkspaceClone: default_branch
WorkspaceClone->>WorktreeBranchManager: ensure_branch_exists(bare_path, branch, create_remote=False, start_point=default_branch, use_local_refs=True)
else get_default_branch raises_exception
RepoManager--xWorkspaceClone: Exception
WorkspaceClone->>WorkspaceClone: log warning Failed to resolve default branch
WorkspaceClone->>WorktreeBranchManager: ensure_branch_exists(bare_path, branch, create_remote=False, start_point="HEAD", use_local_refs=True)
else get_default_branch returns_empty_or_falsy
RepoManager-->>WorkspaceClone: ""
WorkspaceClone->>WorktreeBranchManager: ensure_branch_exists(bare_path, branch, create_remote=False, start_point="HEAD", use_local_refs=True)
end
Class diagram for WorkspaceClone ensure_branch collaboratorsclassDiagram
class WorkspaceClone {
repo_manager
branch_manager
ensure_branch(owner, repo, branch) void
}
class RepoManager {
get_default_branch(owner, repo) str
}
class WorktreeBranchManager {
ensure_branch_exists(bare_path, branch, create_remote, start_point, use_local_refs) void
}
WorkspaceClone --> RepoManager : uses
WorkspaceClone --> WorktreeBranchManager : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
ensure_branch, consider narrowing theexcept Exceptionaroundget_default_branchto the specific error types you expect (or at least repository-related ones) so that unexpected failures don’t get silently masked with a fallback toHEAD. - When logging
Failed to resolve default branch, it may be useful to includeowner/repoin the log message to make troubleshooting easier when multiple repositories are being managed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ensure_branch`, consider narrowing the `except Exception` around `get_default_branch` to the specific error types you expect (or at least repository-related ones) so that unexpected failures don’t get silently masked with a fallback to `HEAD`.
- When logging `Failed to resolve default branch`, it may be useful to include `owner`/`repo` in the log message to make troubleshooting easier when multiple repositories are being managed.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
==========================================
+ Coverage 83.04% 83.09% +0.05%
==========================================
Files 9 9
Lines 1197 1201 +4
==========================================
+ Hits 994 998 +4
Misses 203 203
🚀 New features to boost your workflow:
|
- Catch (OSError, subprocess.SubprocessError) instead of bare Exception so programming bugs propagate instead of being silently swallowed - Include owner/repo in the warning log message for easier debugging - Add tests for None return and unexpected exception propagation
|
Closing as superseded — the fallback landed, in a better place. This PR wraps the call site so a raising Different design from the one proposed, and strictly better: one fallback inside the function rather than one per caller, so a new caller cannot forget it. Mechanically it also cannot merge — 209 commits behind main, conflicting, and its CI predates the |
Summary
get_default_branch()in try/except inensure_branch()so workspace creation remains robust when the default branch cannot be resolved (network issues, misconfigured repos)"HEAD"on error or empty/falsy return valuetest_branch_custom_start_pointto assert no remote push occurs whencreate_remote=FalseAddresses review feedback from #31:
get_default_branchTest plan
get_default_branchraising an exception → falls back to"HEAD"get_default_branchreturning empty string → falls back to"HEAD"mock_push.assert_not_called()totest_branch_custom_start_point🤖 Generated with Claude Code
Summary by Sourcery
Handle failures when resolving a repository’s default branch during workspace branch setup and tighten test coverage around branch creation behavior.
Bug Fixes:
Tests: