fix(repos create): default new repos to main, not master
`git init` without `-b` inherits the ambient `init.defaultBranch` config, which is `master` unless the host has configured otherwise, so `pkgmgr repos create` produced master-based repositories. On top of that, the push fallback renamed an already-correct `main` branch back to `master` whenever the initial push failed (missing remote, auth error). `init()` now requires an explicit `initial_branch` and runs `git init -b <branch>`; the bootstrapper passes `main` and no longer falls back to `master` on push failure. `resolve_base_branch()` keeps its main -> master fallback, since it reads existing repositories that may legitimately use master. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from pkgmgr.actions.repository.create.git_bootstrap import GitBootstrapper
|
||||
from pkgmgr.core.git.commands import GitPushUpstreamError
|
||||
|
||||
|
||||
class TestGitBootstrapperDefaultBranch(unittest.TestCase):
|
||||
def test_init_repo_uses_main_as_initial_branch(self):
|
||||
with (
|
||||
patch("pkgmgr.actions.repository.create.git_bootstrap.init") as init,
|
||||
patch("pkgmgr.actions.repository.create.git_bootstrap.add_all"),
|
||||
patch("pkgmgr.actions.repository.create.git_bootstrap.commit"),
|
||||
):
|
||||
GitBootstrapper().init_repo("/repo", preview=False)
|
||||
|
||||
init.assert_called_once_with(
|
||||
initial_branch="main", cwd="/repo", preview=False
|
||||
)
|
||||
|
||||
def test_push_default_branch_pushes_main(self):
|
||||
with (
|
||||
patch(
|
||||
"pkgmgr.actions.repository.create.git_bootstrap.branch_move"
|
||||
) as branch_move,
|
||||
patch(
|
||||
"pkgmgr.actions.repository.create.git_bootstrap.push_upstream"
|
||||
) as push_upstream,
|
||||
):
|
||||
GitBootstrapper().push_default_branch("/repo", preview=False)
|
||||
|
||||
branch_move.assert_called_once_with("main", cwd="/repo", preview=False)
|
||||
push_upstream.assert_called_once_with(
|
||||
"origin", "main", cwd="/repo", preview=False
|
||||
)
|
||||
|
||||
def test_failed_push_does_not_fall_back_to_master(self):
|
||||
with (
|
||||
patch(
|
||||
"pkgmgr.actions.repository.create.git_bootstrap.branch_move"
|
||||
) as branch_move,
|
||||
patch(
|
||||
"pkgmgr.actions.repository.create.git_bootstrap.push_upstream",
|
||||
side_effect=GitPushUpstreamError("boom"),
|
||||
) as push_upstream,
|
||||
):
|
||||
GitBootstrapper().push_default_branch("/repo", preview=False)
|
||||
|
||||
self.assertEqual(
|
||||
[call.args[0] for call in branch_move.call_args_list], ["main"]
|
||||
)
|
||||
self.assertEqual(
|
||||
[call.args[1] for call in push_upstream.call_args_list], ["main"]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user