From 5807a4c74355af526fc872c4e692c7c8b4c3f424 Mon Sep 17 00:00:00 2001 From: Willie Date: Fri, 29 May 2026 16:50:01 +0800 Subject: [PATCH] feat(init): set remote during headless git_root scope switch Combining --git-root with --remote on an already-initialized setup now switches the scope and wires the remote onto the new scope's repo in one command, instead of warning and ignoring --git-root. Reuses the existing scope-switch and remote-configuration paths back to back. --- cmd/skillshare/init.go | 18 ++++++++--------- tests/integration/git_root_test.go | 31 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cmd/skillshare/init.go b/cmd/skillshare/init.go index 82db54c00..acfc564b0 100644 --- a/cmd/skillshare/init.go +++ b/cmd/skillshare/init.go @@ -337,13 +337,19 @@ func handleExistingInit(opts *initOptions) (bool, error) { // Headless scope switch: `skillshare init --git-root ` on an existing // setup initializes a repo at the new scope directory and persists git_root. // It does not relocate an existing repo (run `mv /.git /.git` for - // that). Combined with --remote we fall through to the remote path below. - if opts.gitRootScope != "" && opts.remoteURL == "" { + // that). With --remote also given, fall through so the remote is configured + // on the just-switched scope's repo. + if opts.gitRootScope != "" { cfg, err := config.Load() if err != nil { return true, err } - return true, switchGitRootScope(cfg, opts.gitRootScope, opts.dryRun) + if err := switchGitRootScope(cfg, opts.gitRootScope, opts.dryRun); err != nil { + return true, err + } + if opts.remoteURL == "" { + return true, nil + } } // If --remote provided, just add the remote to existing setup @@ -358,12 +364,6 @@ func handleExistingInit(opts *initOptions) (bool, error) { if scope == "" { scope = "skills" } - // Scope changes are not combined with --remote — direct the user to the - // dedicated headless form instead of silently applying it here. - if opts.gitRootScope != "" && opts.gitRootScope != scope { - ui.Warning("--git-root %q ignored when combined with --remote", opts.gitRootScope) - ui.Info(" Change the scope separately: skillshare init --git-root %s", opts.gitRootScope) - } gitRoot := cfg.EffectiveGitRoot() if opts.noGit { ui.Info("Skipped git initialization (--no-git)") diff --git a/tests/integration/git_root_test.go b/tests/integration/git_root_test.go index cd3577fdc..9e6bb8f72 100644 --- a/tests/integration/git_root_test.go +++ b/tests/integration/git_root_test.go @@ -293,6 +293,37 @@ func TestGitRoot_SwitchScopeAfterInit(t *testing.T) { } } +// init --git-root --remote switches the scope and wires the +// remote on the new scope's repo in one headless command. +func TestGitRoot_SwitchScopeWithRemote(t *testing.T) { + requireWorkingGit(t) + + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.RunCLI("init", "--no-copy", "--no-targets", "--no-skill", "--git").AssertSuccess(t) + + base := filepath.Dir(sb.ConfigPath) + bareRepo := testutil.SetupBareRemoteRepo(t, t.TempDir()) + + // Switch to root scope AND wire a remote in one command. + result := sb.RunCLI("init", "--git-root", "root", "--remote", bareRepo) + result.AssertSuccess(t) + + cfgBytes, err := os.ReadFile(sb.ConfigPath) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(cfgBytes), "git_root: root") { + t.Errorf("expected git_root: root, got:\n%s", cfgBytes) + } + // The root-scope repo must carry the configured remote. + remote := testutil.RunGit(t, base, "remote", "get-url", "origin") + if remote != bareRepo { + t.Errorf("expected origin %q at root scope, got %q", bareRepo, remote) + } +} + // requireWorkingGit skips the test when the host/container git environment // cannot init a repo and create a commit (e.g. read-only HOME, an identity that // cannot be written, or an owner/permission mismatch). Stripped one-shot