{"record":{"id":"2f608199d524e9dc","repo":"gastownhall/beads","slug":"dolt-clone-failed-w-output-s-clone-target-q-a","errorCode":null,"errorMessage":"dolt clone failed: %w\nOutput: %s\nClone target %q already existed before this attempt; left untouched to avoid deleting a pre-existing Dolt repo","messagePattern":"dolt clone failed: %w\nOutput: (.+?)\nClone target %q already existed before this attempt; left untouched to avoid deleting a pre-existing Dolt repo","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/bootstrap.go","lineNumber":84,"sourceCode":"\n\t// Create the parent dolt directory\n\tif err := os.MkdirAll(doltDir, 0o750); err != nil {\n\t\treturn false, fmt.Errorf(\"failed to create dolt directory: %w\", err)\n\t}\n\n\t// Clone into <doltDir>/<database>/ so the embedded driver can find it.\n\t// `dolt clone <url> <target>` creates <target>/.dolt/ directly.\n\tcloneTarget := filepath.Join(doltDir, database)\n\t// Record whether the target already existed before this clone attempt.\n\t// If it did, the failed-clone cleanup below must never touch it: it\n\t// wasn't created by us, so it could be a pre-existing Dolt repo (e.g.\n\t// from an earlier bootstrap that a stale/empty doltExists() check\n\t// missed) that we must not delete.\n\ttargetPreExisted := pathExists(cloneTarget)\n\tcmd := bootstrapCloneCmd(ctx, remoteURL, cloneTarget)\n\tif output, err := cmd.CombinedOutput(); err != nil {\n\t\tif targetPreExisted {\n\t\t\treturn false, fmt.Errorf(\"dolt clone failed: %w\\nOutput: %s\\nClone target %q already existed before this attempt; left untouched to avoid deleting a pre-existing Dolt repo\", err, output, cloneTarget)\n\t\t}\n\t\tcleaned, cleanupErr := removeFailedCloneTargetWithRetry(cloneTarget)\n\t\treturn false, formatFailedCloneTargetError(err, output, cloneTarget, cleaned, cleanupErr)\n\t}\n\n\tfmt.Fprintf(os.Stderr, \"Bootstrapped from remote: %s\\n\", remoteURL)\n\treturn true, nil\n}\n\n// bootstrapCloneCmd builds the `dolt clone` for remote bootstrap. It does not\n// route through prepareDoltCLITransferCommand, so it applies the remote env\n// guards itself (see internal/gittraceenv and internal/githooksenv).\nfunc bootstrapCloneCmd(ctx context.Context, remoteURL, cloneTarget string) *exec.Cmd {\n\tcmd := exec.CommandContext(ctx, \"dolt\", doltCloneArgs(remoteURL, cloneTarget)...)\n\tcmd.Env = githooksenv.DisabledEnv(gittraceenv.ScrubEnv(os.Environ()))\n\treturn cmd\n}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/bootstrap.go#L66-L102","documentation":"When `dolt clone <remote> <target>` fails and the clone target directory already existed before the attempt, bootstrap deliberately does NOT delete it — it might be a pre-existing Dolt repo that a stale doltExists() check missed. Instead it reports the clone failure plus the raw dolt output and notes the pre-existing target was left untouched. This is the safety-preserving branch of the clone error path.","triggerScenarios":"BootstrapFromRemoteWithDB runs `dolt clone` into <doltDir>/<database> and the command exits non-zero, while pathExists(cloneTarget) was true before the run — e.g. a partially-populated or non-Dolt directory sits at the target, or doltExists() returned false because no .dolt subdirectory was present yet.","commonSituations":"A previous bootstrap crashed leaving an incomplete clone without .dolt at a detectable level; the target path was created by something else (git checkout of files under .beads/dolt/beads); the remote requires auth so clone fails while a stale directory blocks retry.","solutions":["Read the Output section of the error: it contains dolt's own failure reason (auth failure, unknown remote, network error) and fix that underlying cause first.","Inspect the target directory (`ls -la .beads/dolt/<db>`); if it is leftover debris and not a valid Dolt repo, remove it manually and retry `bd bootstrap`.","If it is a valid pre-existing repo you want to keep, skip bootstrap — point the embedded driver at it or run `bd dolt pull` inside it instead of cloning.","For auth failures, set DOLT_REMOTE_USER or configure dolt credentials (`dolt login`) so the clone can succeed.","Verify network/VPN access to the remote (DoltHub, S3, GCS, git host) and retry."],"exampleFix":"# before: stale partial clone blocks bootstrap\n$ ls .beads/dolt/beads      # leftover junk, no .dolt\n$ bd bootstrap              # clone failed... target already existed\n# after: confirm it's not a real repo, then remove it\n$ rm -rf .beads/dolt/beads\n$ bd bootstrap","handlingStrategy":"fallback","validationCode":"if target := filepath.Join(doltDir, db); pathExists(target) && !hasDoltDir(target) {\n    // stale partial clone: remove it or resolve it before bootstrapping\n}","typeGuard":null,"tryCatchPattern":"ok, err := dolt.BootstrapFromRemote(ctx, doltDir, remote)\nif err != nil && strings.Contains(err.Error(), \"already existed before this attempt\") {\n    // inspect the target: clean it manually if debris, or adopt it via `bd dolt pull`\n}","preventionTips":["Verify the target directory contents (a real repo has .dolt/) before bootstrapping.","Configure dolt credentials (dolt login / DOLT_REMOTE_USER) so clones don't fail on auth.","Check network/VPN to the remote host before cold-start bootstrap."],"tags":["dolt","clone","network","bootstrap"],"backgroundTag":"clone-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}