{"record":{"id":"b30e22b595146b03","repo":"gastownhall/beads","slug":"target-repo-s-is-not-initialized-refusing-to-ini","errorCode":null,"errorMessage":"target repo %s is not initialized; refusing to initialize it during dry-run","messagePattern":"target repo (.+?) is not initialized; refusing to initialize it during dry-run","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/create.go","lineNumber":988,"sourceCode":"\t\tcache, err := remotecache.DefaultCache()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to initialize remote cache: %w\", err)\n\t\t}\n\t\t// The dry-run parent lookup only reads from this cached remote store.\n\t\t// Do not add writes here; dry-runs must not mutate cached remotes.\n\t\tstore, err := cache.OpenStore(ctx, repoPath, newPreviewStoreFromConfig)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"dry-run parent lookup requires an existing cached remote store for %s: %w\", repoPath, err)\n\t\t}\n\t\treturn store, nil\n\t}\n\n\ttargetPath := routing.ExpandPath(repoPath)\n\tbeadsDir := filepath.Join(targetPath, \".beads\")\n\tmetadataPath := filepath.Join(beadsDir, \"metadata.json\")\n\tif _, err := os.Stat(metadataPath); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, fmt.Errorf(\"target repo %s is not initialized; refusing to initialize it during dry-run\", targetPath)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to inspect target repo %s: %w\", targetPath, err)\n\t}\n\n\tstore, err := newPreviewStoreFromConfig(ctx, beadsDir)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open target store for dry-run: %w\", err)\n\t}\n\treturn store, nil\n}\n\n// isAmbiguousRepoTarget reports whether an explicit --repo value is a\n// bare/relative filesystem path (not absolute, not \"~/\"-prefixed). Such a\n// value silently resolves against the current working directory (see\n// routing.ExpandPath) rather than failing, so a misresolved value (e.g. a\n// typo) previously wrote a bead into a brand-new, disconnected database\n// instead of erroring (bd-8d3f).\nfunc isAmbiguousRepoTarget(repoFlagChanged bool, repoOverride string) bool {","sourceCodeStart":970,"sourceCodeEnd":1006,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/create.go#L970-L1006","documentation":"For local filesystem targets, openDryRunTargetStore checks that <repo>/.beads/metadata.json exists before opening anything. If it is missing, the function refuses to proceed: dry-run must never initialize (create) a target repository as a side effect. The expanded absolute target path is included in the message.","triggerScenarios":"bd create --dry-run --repo /path/to/repo where /path/to/repo/.beads/metadata.json does not exist: the directory was never `bd init`ed, the .beads dir was deleted, or --repo points at the wrong (empty/new) directory.","commonSituations":"Running dry-run against a freshly cloned repo that lacks .beads (repo not initialized with bd); pointing --repo at the wrong checkout; a wiped or renamed .beads directory; testing in a scratch directory that was never initialized.","solutions":["Run `bd init` in the target repo to create .beads/metadata.json, then retry the dry-run.","Double-check the --repo path — os.Stat failed on the exact expanded path shown in the message; verify the intended checkout is used.","If .beads was deleted accidentally, restore it from git (the metadata.json is normally committed) or re-init and re-sync.","Point the dry-run at an already-initialized repo clone instead of an uninitialized one."],"exampleFix":"// before: dry-run against an uninitialized repo\nbd create --dry-run \"Task\" --repo ../new-service\n// error: target repo ../new-service is not initialized...\n// after: initialize the target repo first\ncd ../new-service && bd init\nbd create --dry-run \"Task\" --repo ../new-service","handlingStrategy":"validation","validationCode":"// Check the target is an initialized beads repo before any dry-run.\ntargetPath := routing.ExpandPath(repoPath)\nif _, err := os.Stat(filepath.Join(targetPath, \".beads\", \"metadata.json\")); os.IsNotExist(err) {\n    return fmt.Errorf(\"%s is not an initialized beads repo; run `bd init` there first\", targetPath)\n}","typeGuard":null,"tryCatchPattern":"store, err := openDryRunTargetStore(ctx, repoPath)\nif err != nil {\n    if strings.Contains(err.Error(), \"not initialized; refusing to initialize it during dry-run\") {\n        fmt.Fprintf(os.Stderr, \"Target repo is not initialized. Run `cd %s && bd init` first.\\n\", repoPath)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Verify the --repo path points at the intended checkout before running dry-runs.","Commit .beads/metadata.json so fresh clones are always initialized.","Run bd from inside the repo (omit --repo) when the current directory is the target.","Never expect dry-run to bootstrap an uninitialized repo — that refusal is intentional safety behavior."],"tags":["cli","filesystem","dry-run","repo-initialization"],"backgroundTag":"repo-not-initialized","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}