ThreeMammals/Ocelot · error · Exception
Failed to execute Git command:
Error message
Failed to execute Git command:
What it means
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.
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.
Example fix
// before
new ProcessSettings { Arguments = command, RedirectStandardOutput = true },
// after
new ProcessSettings { Arguments = command, RedirectStandardOutput = true, RedirectStandardError = true },
// and include stderr in the thrown message Defensive patterns
Strategy: validation
Validate before calling
bool CanRunGit() => IsRunningOnWindows() || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PATH"));
// plus: run 'git --version' and verify exitCode == 0 before depending on Git(...) helper Try / catch
try { var commits = Git("rev-list --count HEAD"); }
catch (Exception ex) { Error($"git step failed: {ex.Message}; run the command manually to see stderr"); throw; } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
AI-assisted analysis of ThreeMammals/Ocelot@d1f22d9304 (2026-09-12).
Data as JSON: /api/errors/4c7f50e75b471948.
Report an issue: GitHub.
Appendix: source
Thrown at build.cake:504
public int Count;
public FilesChangedItem[] Contributors;
}
struct InsertionsGroupingItem
{
public int Insertions;
public int Count;
public FilesChangedItem[] Contributors;
}
private List<string> GitHelper(string command)
{
IEnumerable<string> output;
var exitCode = StartProcess(
"git",
new ProcessSettings { Arguments = command, RedirectStandardOutput = true },
out output);
if (exitCode != 0)
throw new Exception("Failed to execute Git command: " + command);
return output.ToList();
}
private void WriteReleaseNotes()
{
Information($"RUN {nameof(WriteReleaseNotes)} ...");
EnsureDirectoryExists(packagesDir);
_File_.WriteAllLines(releaseNotesFile, releaseNotes, Encoding.UTF8);
var content = _File_.ReadAllText(releaseNotesFile, Encoding.UTF8);
if (string.IsNullOrEmpty(content))
{
_File_.WriteAllText(releaseNotesFile, "No commits since last release", System.Text.Encoding.UTF8);
}
Information("Release notes are >>>{0}<<<", NL + content);
}
private List<string> GetTFMs()
{
View on GitHub (pinned to d1f22d9304)