{"record":{"id":"4c7f50e75b471948","repo":"ThreeMammals/Ocelot","slug":"failed-to-execute-git-command","errorCode":null,"errorMessage":"Failed to execute Git command: ","messagePattern":"Failed to execute Git command: ","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"build.cake","lineNumber":504,"sourceCode":"\tpublic int Count;\r\n\tpublic FilesChangedItem[] Contributors;\r\n}\r\nstruct InsertionsGroupingItem\r\n{\r\n\tpublic int Insertions;\r\n\tpublic int Count;\r\n\tpublic FilesChangedItem[] Contributors;\r\n}\r\n\r\nprivate List<string> GitHelper(string command)\r\n{\r\n\tIEnumerable<string> output;\r\n\tvar exitCode = StartProcess(\r\n\t\t\"git\",\r\n\t\tnew ProcessSettings { Arguments = command, RedirectStandardOutput = true },\r\n\t\tout output);\r\n\tif (exitCode != 0)\r\n\t\tthrow new Exception(\"Failed to execute Git command: \" + command);\r\n\treturn output.ToList();\r\n}\r\n\r\nprivate void WriteReleaseNotes()\r\n{\r\n\tInformation($\"RUN {nameof(WriteReleaseNotes)} ...\");\r\n\tEnsureDirectoryExists(packagesDir);\r\n\t_File_.WriteAllLines(releaseNotesFile, releaseNotes, Encoding.UTF8);\r\n\tvar content = _File_.ReadAllText(releaseNotesFile, Encoding.UTF8);\r\n\tif (string.IsNullOrEmpty(content))\r\n\t{\r\n\t\t_File_.WriteAllText(releaseNotesFile, \"No commits since last release\", System.Text.Encoding.UTF8);\r\n\t}\r\n\tInformation(\"Release notes are >>>{0}<<<\", NL + content);\r\n}\r\n\r\nprivate List<string> GetTFMs()\r\n{\r","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/ThreeMammals/Ocelot/blob/d1f22d930430410bfd0233f5e9e4f92980cf7df0/build.cake#L486-L522","documentation":"This error is thrown by the Git helper in build.cake when a 'git' subprocess started via Cake's StartProcess returns a non-zero exit code. The actual git stderr is not captured (only stdout is redirected), so the message appends only the command string. It signals that a required git operation (e.g. rev-list, tag, log) failed during the build.","triggerScenarios":"Running any build.cake task that calls the Git(...) helper with a command the local git cannot execute: invalid arguments, running outside a git repository, missing git binary, or commands requiring auth/network (e.g. ls-remote against GitHub).","commonSituations":"CI agent without git installed; executing the Cake script from a non-repo directory; git version too old for the flags used; private repo access without credentials; detached/bare checkout missing refs.","solutions":["Run the same git command manually in the working directory to see the real error (stderr is swallowed by the helper).","Verify git is installed and on PATH: git --version.","Verify the working directory is inside the Ocelot git repository with expected refs/tags.","If the command needs network/auth (e.g. ls-remote), configure credentials or a token first.","Improve the helper to redirect stderr and include it in the exception message for diagnosability."],"exampleFix":"// before\nnew ProcessSettings { Arguments = command, RedirectStandardOutput = true },\n// after\nnew ProcessSettings { Arguments = command, RedirectStandardOutput = true, RedirectStandardError = true },\n// and include stderr in the thrown message","handlingStrategy":"validation","validationCode":"bool CanRunGit() => IsRunningOnWindows() || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(\"PATH\"));\n// plus: run 'git --version' and verify exitCode == 0 before depending on Git(...) helper","typeGuard":null,"tryCatchPattern":"try { var commits = Git(\"rev-list --count HEAD\"); }\ncatch (Exception ex) { Error($\"git step failed: {ex.Message}; run the command manually to see stderr\"); throw; }","preventionTips":["Run the failing git command manually to see stderr the helper hides","Ensure git is installed and on PATH in CI images","Always execute build.cake from the repository root","Enhance the helper to capture and include stderr"],"tags":["git","build-script","process-exit-code"],"backgroundTag":"git-command-failed","analyzedSha":"d1f22d930430410bfd0233f5e9e4f92980cf7df0","analyzedAt":"2026-09-12T13:50:06.067Z","contentChangedAt":"2026-09-12T13:50:06.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}