{"record":{"id":"186f3e21141761ec","repo":"FuelLabs/sway","slug":"failed-to-init-repo-at","errorCode":null,"errorMessage":"failed to init repo at \\\"{}\\\": {}","messagePattern":"failed to init repo at \\\\\"(.+?)\\\\\": (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-pkg/src/source/git/mod.rs","lineNumber":449,"sourceCode":"    // returning or panicking.\n    let _cleanup_guard = scopeguard::guard(&repo_dir, |dir| {\n        let _ = std::fs::remove_dir_all(dir);\n    });\n\n    let config = git2::Config::open_default().unwrap();\n\n    // Init auth manager\n    let mut auth_handler = auth::AuthHandler::default_with_config(config);\n\n    // Setup remote callbacks\n    let mut callback = git2::RemoteCallbacks::new();\n    callback.credentials(move |url, username, allowed| {\n        auth_handler.handle_callback(url, username, allowed)\n    });\n\n    // Initialise the repository.\n    let repo = git2::Repository::init(&repo_dir)\n        .map_err(|e| anyhow!(\"failed to init repo at \\\"{}\\\": {}\", repo_dir.display(), e))?;\n\n    // Fetch the necessary references.\n    let (refspecs, tags) = git_ref_to_refspecs(&source.reference);\n\n    // Fetch the refspecs.\n    let mut fetch_opts = git2::FetchOptions::new();\n    fetch_opts.remote_callbacks(callback);\n\n    if tags {\n        fetch_opts.download_tags(git2::AutotagOption::All);\n    }\n    let repo_url_string = source.repo.to_string();\n    repo.remote_anonymous(&repo_url_string)?\n        .fetch(&refspecs, Some(&mut fetch_opts), None)\n        .with_context(|| {\n            format!(\n                \"failed to fetch `{}`. Check your connection or run in `--offline` mode\",\n                &repo_url_string","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/source/git/mod.rs#L431-L467","documentation":"To fetch a git dependency, forc first creates a repository on disk with git2::Repository::init at the per-repo cache path. If the filesystem refuses - permission denied, read-only mount, disk full, invalid path - the git2 error is wrapped with the target directory path.","triggerScenarios":"The user running forc lacks write permission under the forc home git directory; the directory is on a full or read-only filesystem; FORC_HOME points somewhere unwritable.","commonSituations":"CI containers with restricted HOME; Docker volumes mounted read-only; sandboxes; FORC_HOME misconfigured to a path requiring root.","solutions":["Check write permission on the printed repo_dir and its parents; chmod/chown as needed","Free disk space or remount the filesystem writable","Unset or fix FORC_HOME so it points at a writable location","Remove the half-created repo_dir and retry so init starts clean"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"use std::{fs, path::Path};\n\nfn cache_dir_writable(dir: &Path) -> bool {\n    fs::create_dir_all(dir).is_ok()\n        && fs::write(dir.join(\".probe\"), b\"\").is_ok()\n        && fs::remove_file(dir.join(\".probe\")).is_ok()\n}\n// before building: assert cache_dir_writable(&forc_home.join(\"git\"));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure FORC_HOME is writable before builds in containers","Monitor disk space on cache volumes","Do not run forc against read-only mounts"],"tags":["git","filesystem","permissions","cache"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}