{"record":{"id":"9e07e8d79f5331e0","repo":"CoplayDev/unity-mcp","slug":"failed-to-resolve-branch-head-commit-sha-for-bra","errorCode":null,"errorMessage":"Failed to resolve branch head commit SHA for: {branch}","messagePattern":"Failed to resolve branch head commit SHA for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Setup/SkillSyncService.cs","lineNumber":255,"sourceCode":"            if (remoteFiles.Count == 0)\n            {\n                throw new InvalidOperationException($\"Remote directory not found: {normalizedSubdir}\");\n            }\n\n            log?.Invoke($\"Remote file count: {remoteFiles.Count}\");\n            return new RemoteSnapshot(commitSha, normalizedSubdir, remoteFiles);\n        }\n\n        private static string FetchBranchHeadCommitSha(HttpClient client, GitHubRepoInfo repoInfo, string branch, Action<string> log)\n        {\n            var branchApiUrl = BuildBranchApiUrl(repoInfo, branch);\n            log?.Invoke($\"Fetching branch head commit...\");\n            var branchJson = DownloadString(client, branchApiUrl);\n            var branchResponse = JsonUtility.FromJson<GitHubBranchResponse>(branchJson);\n            var commitSha = branchResponse?.commit?.sha?.Trim();\n            if (string.IsNullOrWhiteSpace(commitSha))\n            {\n                throw new InvalidOperationException($\"Failed to resolve branch head commit SHA for: {branch}\");\n            }\n\n            return commitSha;\n        }\n\n        private static string BuildBranchApiUrl(GitHubRepoInfo repoInfo, string branch)\n        {\n            return $\"https://api.github.com/repos/{Uri.EscapeDataString(repoInfo.Owner)}/{Uri.EscapeDataString(repoInfo.Repo)}/branches/{Uri.EscapeDataString(branch)}\";\n        }\n\n        private static string BuildTreeApiUrl(GitHubRepoInfo repoInfo, string reference)\n        {\n            return $\"https://api.github.com/repos/{Uri.EscapeDataString(repoInfo.Owner)}/{Uri.EscapeDataString(repoInfo.Repo)}/git/trees/{Uri.EscapeDataString(reference)}?recursive=1\";\n        }\n\n        private static string BuildRawFileUrl(GitHubRepoInfo repoInfo, string commitSha, string remoteFilePath)\n        {\n            var encodedPath = string.Join(\"/\",","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Setup/SkillSyncService.cs#L237-L273","documentation":"FetchBranchHeadCommitSha parses the Branches API response and expects branchResponse.commit.sha. If that field is null/empty/whitespace after parsing a 2xx response, the SHA cannot be resolved and the sync cannot proceed.","triggerScenarios":"The branch API returned 2xx but with a schema that did not deserialize commit.sha (API change, proxy-rewritten body); the response parsed into a default object because JsonUtility could not map the fields.","commonSituations":"GitHub API schema drift; an intermediary returned a 200 with a different JSON shape; extremely rare compared to the 404 path which surfaces as error 67.","solutions":["Verify the branch name is correct (case-sensitive on some repos).","Capture and inspect the raw Branches API response body.","Retry in case of a transient intermediary issue.","Confirm there is no proxy rewriting the JSON payload."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var sha = FetchBranchHeadCommitSha(client, repoInfo, branch, log);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"branch head commit SHA\"))\n{\n    log?.Invoke($\"Could not resolve SHA for branch '{branch}'. Verify the branch exists and the API response is intact.\");\n    throw;\n}","preventionTips":["Use the correct branch name (case-sensitive where relevant).","Inspect raw API responses when SHA resolution fails unexpectedly.","Prefer the default branch unless you need a specific one."],"tags":["github","branch","api","parse"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}