Repository navigation
fix(init): verify cached clone remote before reuse - #329
Merged
Merged
Conversation
teamai init reused an existing .teamai/team-repo clone whenever the path was a git repo, without checking that its origin matched the requested --repo. A leftover clone from a different team repo was served silently, surfacing the wrong roles/skills manifest. Compare the existing clone's origin against the requested repo (ignoring credentials, protocol, scp-vs-URL form, .git suffix, port, and case). On mismatch: --force replaces it, interactive prompts, otherwise abort and keep the clone. Embedded credentials are redacted from the warning.
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
teamai init reused an existing .teamai/team-repo clone whenever the path was a git repo, without checking that its origin matched the requested --repo. A leftover clone from a different team repo was served silently, surfacing the wrong roles/skills manifest. Compare the existing clone's origin against the requested repo (ignoring credentials, protocol, scp-vs-URL form, .git suffix, port, and case). On mismatch: --force replaces it, interactive prompts, otherwise abort and keep the clone. Embedded credentials are redacted from the warning.
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
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.
Problem
teamai initreused an existing.teamai/team-repoclone whenever the path was a git repo, without checking that its origin matched the requested--repo. A leftover clone from a different team repo was served silently, surfacing the wrong roles/skills manifest.Concretely: a
.teamai/team-repocloned earlier from repo A, thenteamai init --repo <repoB>, would print "Repo already exists, using existing clone" and then list repo A's roles — repo B was never cloned, and if repo B has no roles the user sees a stale role list from an unrelated repo.Fix
Before reusing an existing clone, compare its
originremote against the requested repo, ignoring differences that don't change the target: embedded credentials, http/https/ssh, scp-vs-URL form, a trailing.git, port, and case.On mismatch:
--force→ replace with a fresh clone--forceEmbedded credentials are redacted from the warning so tokens in the cached origin URL are never printed.
Changes
src/utils/git.ts: new pure helpersnormalizeRepoUrlForCompare,remotesMatch,redactGitCredentialssrc/init.ts: remote check in the clone-reuse branch ofinit()src/__tests__/git.test.ts: 16 cases covering URL-form normalization, matching, and redaction (incl. the exact bug scenario)Test Plan
npx tsc --noEmitcleannpx vitest run— 163 files / 2199 tests passdist, local bare repos):--force, non-interactive → aborts, clone preserved--force→ replaces clone