{"record":{"id":"f2ea401997e93ebf","repo":"jdx/mise","slug":"could-not-snapshot-the-local-history-repository-fo","errorCode":null,"errorMessage":"could not snapshot the local history repository for preview","messagePattern":"could not snapshot the local history repository for preview","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/sync/onboard.rs","lineNumber":75,"sourceCode":"/// All fetches, reconciliation, and preview status writes then target this\n/// private store, so cancellation never needs to roll back live bookkeeping.\nfn preview_store(store: &Store) -> Result<(tempfile::TempDir, Store)> {\n    let _sync = run::lock(store)?;\n    let _capture = store.lock()?;\n    let temp = tempfile::tempdir()?;\n    hstore::ensure_store_dir_in(temp.path())?;\n    let preview = Store::open_in(temp.path())?;\n    let source = store\n        .repo()\n        .ok_or_else(|| eyre::eyre!(\"preview requires git\"))?;\n    let destination = preview\n        .repo()\n        .ok_or_else(|| eyre::eyre!(\"preview requires git\"))?;\n    let url = url::Url::from_file_path(source.dir())\n        .map_err(|_| eyre::eyre!(\"cannot address the local history repository\"))?;\n    let copied = destination.network([\"fetch\", \"--no-tags\", url.as_str(), \"+refs/*:refs/*\"])?;\n    if !copied.status.success() {\n        bail!(\"could not snapshot the local history repository for preview\");\n    }\n    run::write_status(temp.path(), &run::read_status(store.state_dir())?)?;\n    // Reopen to rebuild the derived history index from the copied commits.\n    let preview = Store::open_in(temp.path())?;\n    Ok((temp, preview))\n}\n\nfn preview_configuration(store: &Store) -> Result<tempfile::TempDir> {\n    let temp = tempfile::tempdir()?;\n    let repo = store\n        .repo()\n        .ok_or_else(|| eyre::eyre!(\"preview requires git\"))?;\n    let head = repo\n        .ref_oid(UPSTREAM_REF)?\n        .ok_or_else(|| eyre::eyre!(\"setup preview has no fetched branch\"))?;\n    let encrypted = super::files::encrypted_paths(repo, Some(&head))?;\n    let tracked = crate::system::history::manifest::Manifest::read(repo, &head)?\n        .ok_or_else(|| eyre::eyre!(\"setup repository has no enrollment metadata\"))?","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/sync/onboard.rs#L57-L93","documentation":"preview_store builds a throwaway preview of the history repository by fetching all refs from the local source repository into a temp store via a git network fetch. If the underlying git fetch exits nonzero, the library cannot produce a preview snapshot and bails with this message. The real git stderr is handled by the network layer; this error marks the preview step as failed.","triggerScenarios":"Calling preview_store (via run during onboarding) when the `git fetch --no-tags <file-url> +refs/*:refs/*` into the temp store fails — e.g. git is unavailable (already handled earlier), the source repo path can't be addressed, refspec conflicts, or a corrupted source repository.","commonSituations":"Source history repository with corrupted or locked object files; a destination store already containing conflicting refs; filesystem/permission problems in the temp directory; git fetch rejecting the +refs/*:refs/* mapping due to an unexpected ref layout.","solutions":["Run `git fsck` in the source history repository to detect corruption and repair or reinstall its history","Retry the onboarding preview after clearing locks (remove stale .lock files) and confirming disk space/permissions","Inspect git output by running the equivalent fetch manually to see the underlying failure, then address that specific cause"],"exampleFix":"// preview_store does:\nlet copied = destination.network([\"fetch\", \"--no-tags\", url.as_str(), \"+refs/*:refs/*\"])?;\nif !copied.status.success() {\n    bail!(\"could not snapshot the local history repository for preview\");\n}\n// manual diagnosis:\n// git -C <source> fsck && git -C <probe-store> fetch --no-tags <source-path> '+refs/*:refs/*'","handlingStrategy":"fallback","validationCode":"// preflight: source repo must be a healthy git repo\nif !source.dir().join(\".git\").exists() && !run_git(&[\"-C\", source, \"rev-parse\", \"--git-dir\"]).success() {\n    return Err(\"source history repository is not a valid git repo\");\n}","typeGuard":null,"tryCatchPattern":"match preview_store(&source) {\n    Ok((temp, preview)) => preview,\n    Err(e) if e.to_string().contains(\"could not snapshot\") => {\n        repair_source_repo(&source)?; // fsck, clear locks\n        preview_store(&source)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run `git fsck` periodically on history repositories","Avoid concurrent writes/reads of the source repo while previewing","Ensure adequate disk space and permissions in the temp directory used for previews"],"tags":["git","history-sync","snapshot"],"backgroundTag":"git-command-failed","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}