{"record":{"id":"19ac0c31858fa38b","repo":"stride3d/stride","slug":"git-args-exited-with-p-exitcode","errorCode":null,"errorMessage":"git {args} exited with {p.ExitCode}","messagePattern":"git (.+?) exited with (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/targets/StrideVersionTasks.cs","lineNumber":55,"sourceCode":"        version = majorMinor + \".\" + patch;\n    }\n\n    private static string Field(string data, string name)\n        => Regex.Match(data, name + \" = \\\"([^\\\"]*)\\\";\").Groups[1].Value;\n\n    public static string Git(string workingDir, string args)\n    {\n        var psi = new ProcessStartInfo(\"git\", args)\n        {\n            WorkingDirectory = workingDir,\n            RedirectStandardOutput = true,\n            UseShellExecute = false\n        };\n        using (var p = Process.Start(psi))\n        {\n            string output = p.StandardOutput.ReadToEnd().Trim();\n            p.WaitForExit();\n            if (p.ExitCode != 0) throw new Exception(\"git \" + args + \" exited with \" + p.ExitCode);\n            return output;\n        }\n    }\n\n    // Overlay the version + suffix (+ optional build metadata) into a copy of the source version file. Rewrites\n    // Patch (read back by the package producers) and PublicVersion (the sentinel in the template -> the real\n    // version, read by the compiled consts).\n    public static string Overlay(string source, string majorMinor, string version, string suffix, string buildMetadata)\n    {\n        string patch = version.StartsWith(majorMinor + \".\", StringComparison.Ordinal)\n            ? version.Substring(majorMinor.Length + 1)\n            : version;\n        string patched = Regex.Replace(source, \"Patch = \\\"[^\\\"]*\\\";\", \"Patch = \\\"\" + patch + \"\\\";\");\n        patched = Regex.Replace(patched, \"const string PublicVersion = [^;]*;\", \"const string PublicVersion = \\\"\" + version + \"\\\";\");\n        patched = Regex.Replace(patched, \"NuGetVersionSuffix = \\\"[^\\\"]*\\\";\", \"NuGetVersionSuffix = \\\"\" + suffix + \"\\\";\");\n        if (buildMetadata != null)\n            patched = Regex.Replace(patched, \"BuildMetadata = \\\"[^\\\"]*\\\";\", \"BuildMetadata = \\\"\" + buildMetadata + \"\\\";\");\n        return patched;","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/targets/StrideVersionTasks.cs#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the exact `git <args>` from the message manually to see git's real stderr","Ensure the build runs inside a full git clone (not a source tarball)","In CI, set git config --global --add safe.directory <repo> and configure user identity","Catch the exception around the Git call and surface git's stderr for diagnosis"],"exampleFix":"// before\nstring version = tasks.Git(\"describe --tags --exact-match\");\n// after\ntry { string version = tasks.Git(\"describe --tags --exact-match\"); }\ncatch (Exception ex) { Console.Error.WriteLine($\"git failed: {ex.Message}\"); throw; }","handlingStrategy":"try-catch","validationCode":"// before invoking the build task\nvar psi = new ProcessStartInfo(\"git\", \"--version\") { RedirectStandardError = true };\nusing var p = Process.Start(psi);\np.WaitForExit();\nif (p.ExitCode != 0) throw new InvalidOperationException(\"git is not available/configured in this environment\");","typeGuard":null,"tryCatchPattern":"try { string v = tasks.Git(\"describe --tags\"); }\ncatch (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); }","preventionTips":["Always build from a full git clone, never a source tarball","Configure git user.email/user.name and safe.directory in CI images","Run the failing git command manually using the args in the exception message"],"tags":["git","process","build"],"backgroundTag":"git-command-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}