{"record":{"id":"3f5f21974e749b00","repo":"CoplayDev/unity-mcp","slug":"git-args-failed","errorCode":null,"errorMessage":"git {args} failed","messagePattern":"git (.+?) failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"mcp_source.py","lineNumber":33,"sourceCode":"\nfrom __future__ import annotations\n\nimport argparse\nimport json\nimport pathlib\nimport subprocess\nimport sys\n\nPKG_NAME = \"com.coplaydev.unity-mcp\"\nBRIDGE_SUBPATH = \"MCPForUnity\"\n\n\ndef run_git(repo: pathlib.Path, *args: str) -> str:\n    result = subprocess.run([\n        \"git\", \"-C\", str(repo), *args\n    ], capture_output=True, text=True)\n    if result.returncode != 0:\n        raise RuntimeError(result.stderr.strip()\n                           or f\"git {' '.join(args)} failed\")\n    return result.stdout.strip()\n\n\ndef normalize_origin_to_https(url: str) -> str:\n    \"\"\"Map common SSH origin forms to https for Unity's git URL scheme.\"\"\"\n    if url.startswith(\"git@github.com:\"):\n        owner_repo = url.split(\":\", 1)[1]\n        if owner_repo.endswith(\".git\"):\n            owner_repo = owner_repo[:-4]\n        return f\"https://github.com/{owner_repo}.git\"\n    # already https or file: etc.\n    return url\n\n\ndef detect_repo_root(explicit: str | None) -> pathlib.Path:\n    if explicit:\n        return pathlib.Path(explicit).resolve()","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/mcp_source.py#L15-L51","documentation":"Raised by run_git in mcp_source.py when a git subprocess (git -C <repo> <args...>) exits non-zero. The error message is the trimmed stderr, or the fallback 'git <args> failed' text when stderr was empty. mcp_source.py uses git to query and switch the Unity package source between branches/tags.","triggerScenarios":"Subprocess git invocation returns returncode != 0: bad ref name, missing remote, dirty working tree blocking checkout, no network/auth for a private remote, or the repo path does not exist.","commonSituations":"Running /mcp-source branch with a branch name that doesn't exist; switching to a tag while on detached HEAD with conflicts; corporate proxy/SSH key not set; the local Unity project is not a git repo so -C fails.","solutions":["Run the same git command manually (git -C <repo> <args>) to read the real stderr and fix the underlying cause.","For branch switches, confirm the branch exists (git branch -a) and the working tree is clean first.","For remote fetch failures, verify network, credentials, and that the remote URL is reachable."],"exampleFix":"# before\n/mcp-source branch nonexistent-branch\n# after (diagnose)\ngit -C <unity-project> fetch origin\ngit -C <unity-project> branch -a | grep <name>\n# then retry /mcp-source branch <real-branch>","handlingStrategy":"try-catch","validationCode":"def safe_run_git(repo, *args):\n    result = subprocess.run(['git','-C',str(repo),*args], capture_output=True, text=True)\n    if result.returncode != 0:\n        return None, result.stderr.strip()\n    return result.stdout.strip(), None","typeGuard":"def git_succeeds(repo, *args) -> bool:\n    return subprocess.run(['git','-C',str(repo),*args], capture_output=True).returncode == 0","tryCatchPattern":"try:\n    run_git(repo, 'checkout', branch)\nexcept RuntimeError as e:\n    print(f'git failed: {e}'); sys.exit(1)","preventionTips":["Pre-check the branch/ref exists before switching","Ensure the working tree is clean","Verify network/credentials for private remotes"],"tags":["git","subprocess","tooling","mcp-source"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}