{"record":{"id":"afa19eaf9579a85a","repo":"FuelLabs/sway","slug":"cannot-get-commit-from","errorCode":null,"errorMessage":"Cannot get commit from {}","messagePattern":"Cannot get commit from (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-pkg/src/source/git/mod.rs","lineNumber":541,"sourceCode":"        repo.set_head_detached(id)?;\n\n        // If the directory exists, remove it. Note that we already check for an existing,\n        // cached checkout directory for re-use prior to reaching the `fetch` function.\n        if path.exists() {\n            let _ = fs::remove_dir_all(&path);\n        }\n        fs::create_dir_all(&path)?;\n\n        // Checkout HEAD to the target directory.\n        let mut checkout = git2::build::CheckoutBuilder::new();\n        checkout.force().target_dir(&path);\n        repo.checkout_head(Some(&mut checkout))?;\n\n        // Fetch HEAD time and create an index\n        let current_head = repo.revparse_single(\"HEAD\")?;\n        let head_commit = current_head\n            .as_commit()\n            .ok_or_else(|| anyhow!(\"Cannot get commit from {}\", current_head.id()))?;\n        let head_time = head_commit.time().seconds();\n        let source_index = SourceIndex::new(\n            head_time,\n            pinned.source.reference.clone(),\n            pinned.commit_hash.clone(),\n        );\n\n        // Write the index file\n        fs::write(\n            path.join(\".forc_index\"),\n            serde_json::to_string(&source_index)?,\n        )?;\n        Ok(())\n    })?;\n    Ok(path)\n}\n\n/// Search local checkout dir for git sources, for non-branch git references tries to find the","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/source/git/mod.rs#L523-L559","documentation":"After fetching and checking out a git dependency, forc resolves HEAD via revparse_single and expects a commit object to timestamp the SourceIndex. If HEAD does not point at a commit (or the fetch produced an empty/detached repository), the object id is reported with this error.","triggerScenarios":"A corrupted or truncated fetch leaving HEAD dangling; a cached repo directory tampered with; stale checkouts from incompatible forc versions.","commonSituations":"An interrupted forc build during fetch; third-party tools manipulating ~/.forc/git; disk corruption in the cache.","solutions":["Delete the cached repo/checkout directories for that dependency under ~/.forc/git and rebuild to re-fetch","Verify the ref actually points to a commit: `git ls-remote <url> <branch-or-tag>`","If it persists on stock forc, report it with the dependency declaration"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match fetch_git_dep(&source) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"Cannot get commit from\") => {\n        // corrupt cached HEAD: purge this repo's cache entries and retry once\n        std::fs::remove_dir_all(&repo_cache_dir)?;\n        fetch_git_dep(&source)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat caches left by interrupted builds as suspect; clean on odd git errors","Pin to explicit tags or revs rather than moving branches","Avoid third-party tools mutating ~/.forc/git"],"tags":["git","cache","corruption","internal"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}