Repository navigation
Base new branches on repo's default branch #31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| """Tests for worktree branch manager.""" | ||
| # pylint: disable=redefined-outer-name | ||
| # pylint: disable=redefined-outer-name,unused-argument | ||
|
|
||
| import subprocess | ||
| import tempfile | ||
|
|
@@ -312,7 +312,7 @@ def test_branch_does_not_exist( | |
|
|
||
| branch_manager.ensure_branch_exists(temp_repo, "new-branch") | ||
|
|
||
| mock_create.assert_called_once_with(temp_repo, "new-branch") | ||
| mock_create.assert_called_once_with(temp_repo, "new-branch", "HEAD") | ||
| mock_push.assert_called_once() | ||
| mock_track.assert_called_once() | ||
|
|
||
|
|
@@ -328,7 +328,93 @@ def test_branch_no_create_remote( | |
|
|
||
| branch_manager.ensure_branch_exists(temp_repo, "new-branch", create_remote=False) | ||
|
|
||
| mock_create.assert_called_once() | ||
| mock_create.assert_called_once_with(temp_repo, "new-branch", "HEAD") | ||
|
|
||
| @patch.object(BranchManager, "local_branch_exists") | ||
| @patch.object(BranchManager, "remote_branch_exists") | ||
| @patch.object(BranchManager, "create_local_branch") | ||
| @patch.object(BranchManager, "track_remote_branch") | ||
| def test_branch_custom_start_point( | ||
| self, | ||
| mock_track, | ||
| mock_create, | ||
| mock_remote_exists, | ||
| mock_local_exists, | ||
| branch_manager, | ||
| temp_repo, | ||
| ): | ||
| """Test ensure_branch_exists passes custom start_point to create_local_branch.""" | ||
| mock_local_exists.return_value = False | ||
| mock_remote_exists.return_value = False | ||
|
|
||
| branch_manager.ensure_branch_exists( | ||
| temp_repo, "new-branch", create_remote=False, start_point="origin/main" | ||
| ) | ||
|
|
||
| mock_create.assert_called_once_with(temp_repo, "new-branch", "origin/main") | ||
|
Comment on lines
+350
to
+354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Tighten the custom start_point test by asserting no remote operations occur when create_remote=False In Suggested implementation: mock_push.assert_called_once()
mock_track.assert_called_once()
# Reset mocks before exercising create_remote=False path to ensure no remote operations occur
mock_push.reset_mock()
mock_track.reset_mock()
branch_manager.ensure_branch_exists(temp_repo, "new-branch", create_remote=False)
mock_push.assert_not_called()
mock_track.assert_not_called()In the |
||
|
|
||
|
|
||
| class TestEnsureBranchExistsUseLocalRefs: | ||
| """Tests for ensure_branch_exists with use_local_refs=True.""" | ||
|
|
||
| @patch.object(BranchManager, "local_branch_exists") | ||
| @patch.object(BranchManager, "remote_branch_exists") | ||
| def test_use_local_refs_skips_ls_remote_when_branch_exists( | ||
| self, mock_remote_exists, mock_local_exists, branch_manager, temp_repo | ||
| ): | ||
| """When use_local_refs=True and branch exists locally, remote_branch_exists is not called.""" | ||
| mock_local_exists.return_value = True | ||
|
|
||
| branch_manager.ensure_branch_exists(temp_repo, "main", use_local_refs=True) | ||
|
|
||
| mock_local_exists.assert_called_once() | ||
| mock_remote_exists.assert_not_called() | ||
|
|
||
| @patch.object(BranchManager, "local_branch_exists") | ||
| @patch.object(BranchManager, "remote_branch_exists") | ||
| @patch.object(BranchManager, "create_local_branch") | ||
| @patch.object(BranchManager, "track_remote_branch") | ||
| def test_use_local_refs_creates_branch_when_missing( | ||
| self, | ||
| mock_track, | ||
| mock_create, | ||
| mock_remote_exists, | ||
| mock_local_exists, | ||
| branch_manager, | ||
| temp_repo, | ||
| ): | ||
| """When use_local_refs=True and branch missing locally, it is created without ls-remote.""" | ||
| mock_local_exists.return_value = False | ||
|
|
||
| branch_manager.ensure_branch_exists( | ||
| temp_repo, "new-branch", create_remote=False, use_local_refs=True | ||
| ) | ||
|
|
||
| mock_remote_exists.assert_not_called() | ||
| mock_create.assert_called_once_with(temp_repo, "new-branch", "HEAD") | ||
|
|
||
| @patch.object(BranchManager, "local_branch_exists") | ||
| @patch.object(BranchManager, "remote_branch_exists") | ||
| @patch.object(BranchManager, "create_local_branch") | ||
| @patch.object(BranchManager, "push_branch_to_remote") | ||
| @patch.object(BranchManager, "track_remote_branch") | ||
| def test_use_local_refs_false_still_calls_ls_remote( | ||
| self, | ||
| mock_track, | ||
| mock_push, | ||
| mock_create, | ||
| mock_remote_exists, | ||
| mock_local_exists, | ||
| branch_manager, | ||
| temp_repo, | ||
| ): | ||
| """Default use_local_refs=False still calls remote_branch_exists.""" | ||
| mock_local_exists.return_value = False | ||
| mock_remote_exists.return_value = False | ||
|
|
||
| branch_manager.ensure_branch_exists(temp_repo, "new-branch") | ||
|
|
||
| mock_remote_exists.assert_called_once() | ||
|
|
||
|
|
||
| class TestCreateRemoteBranchViaSSH: | ||
|
|
||
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.
issue (bug_risk): Handle failures or unexpected values from get_default_branch to avoid breaking workspace creation.
If
get_default_branchraises (e.g., no default branch, network/permissions issues) or returns an empty/invalid value, passing it asstart_pointwill causeensure_branch_existsto fail. Previously this defaulted to the underlyingHEAD. Please handle failures fromget_default_branch(e.g.,try/exceptlikefetch_repo) and fall back to a safe default such asHEADwhen the default branch is unavailable or falsy, so workspace creation remains robust in misconfigured repos.