stride3d/stride · error · Exception

git exited with

Error message

git {args} exited with {p.ExitCode}

What it means

StrideVersionTasks.Git runs an external `git` process with redirected output and throws this generic Exception when the process exits with a non-zero exit code. The message embeds the exact git arguments and exit code so you can reproduce the failing command. It signals that a required git operation during version stamping failed.

Solutions

  1. Run the exact `git <args>` from the message manually to see git's real stderr
  2. Ensure the build runs inside a full git clone (not a source tarball)
  3. In CI, set git config --global --add safe.directory <repo> and configure user identity
  4. Catch the exception around the Git call and surface git's stderr for diagnosis

Example fix

// before
string version = tasks.Git("describe --tags --exact-match");
// after
try { string version = tasks.Git("describe --tags --exact-match"); }
catch (Exception ex) { Console.Error.WriteLine($"git failed: {ex.Message}"); throw; }
Defensive patterns

Strategy: try-catch

Validate before calling

// before invoking the build task
var psi = new ProcessStartInfo("git", "--version") { RedirectStandardError = true };
using var p = Process.Start(psi);
p.WaitForExit();
if (p.ExitCode != 0) throw new InvalidOperationException("git is not available/configured in this environment");

Try / catch

try { string v = tasks.Git("describe --tags"); }
catch (Exception ex) when (ex.Message.Contains("exited with")) { throw new InvalidOperationException($"git operation failed: {ex.Message}. Ensure a full git clone and configured identity.", ex); }

Prevention

When it happens

Trigger: Calling any Git(...) helper path (e.g. during build/version tasks) where the spawned `git <args>` command fails: bad revision spec, git not configured, not a git repository, or network fetch failure.

Common situations: Running build scripts outside a git checkout (shallow/tarball source drop); git identity or safe.directory not configured in CI containers; requesting a tag/commit that does not exist locally after shallow clone.

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 stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/19ac0c31858fa38b. Report an issue: GitHub.

Appendix: source

Thrown at sources/targets/StrideVersionTasks.cs:55

        version = majorMinor + "." + patch;
    }

    private static string Field(string data, string name)
        => Regex.Match(data, name + " = \"([^\"]*)\";").Groups[1].Value;

    public static string Git(string workingDir, string args)
    {
        var psi = new ProcessStartInfo("git", args)
        {
            WorkingDirectory = workingDir,
            RedirectStandardOutput = true,
            UseShellExecute = false
        };
        using (var p = Process.Start(psi))
        {
            string output = p.StandardOutput.ReadToEnd().Trim();
            p.WaitForExit();
            if (p.ExitCode != 0) throw new Exception("git " + args + " exited with " + p.ExitCode);
            return output;
        }
    }

    // Overlay the version + suffix (+ optional build metadata) into a copy of the source version file. Rewrites
    // Patch (read back by the package producers) and PublicVersion (the sentinel in the template -> the real
    // version, read by the compiled consts).
    public static string Overlay(string source, string majorMinor, string version, string suffix, string buildMetadata)
    {
        string patch = version.StartsWith(majorMinor + ".", StringComparison.Ordinal)
            ? version.Substring(majorMinor.Length + 1)
            : version;
        string patched = Regex.Replace(source, "Patch = \"[^\"]*\";", "Patch = \"" + patch + "\";");
        patched = Regex.Replace(patched, "const string PublicVersion = [^;]*;", "const string PublicVersion = \"" + version + "\";");
        patched = Regex.Replace(patched, "NuGetVersionSuffix = \"[^\"]*\";", "NuGetVersionSuffix = \"" + suffix + "\";");
        if (buildMetadata != null)
            patched = Regex.Replace(patched, "BuildMetadata = \"[^\"]*\";", "BuildMetadata = \"" + buildMetadata + "\";");
        return patched;

View on GitHub (pinned to 96fad776d2)