{"record":{"id":"e0a2a00217145b28","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-get-current-git-repository","errorCode":null,"errorMessage":"Failed to get current Git repository","messagePattern":"Failed to get current Git repository","errorType":"exception","errorClass":"Trace2Exception","httpStatus":null,"severity":"error","filePath":"src/Core/Git.cs","lineNumber":170,"sourceCode":"                if (suppressStreams)\n                {\n                    git.Process.ErrorDataReceived += (_, _) => { };\n                    git.Process.BeginErrorReadLine();\n                }\n\n                string data = git.StandardOutput.ReadToEnd();\n                git.WaitForExit();\n\n                switch (git.ExitCode)\n                {\n                    case 0: // OK\n                        return data.TrimEnd();\n                    case 128: // Not inside a Git repository\n                        return null;\n                    default:\n                        var message = \"Failed to get current Git repository\";\n                        _trace.WriteLine($\"{message} (exit={git.ExitCode})\");\n                        throw CreateGitException(git, message, _trace2);\n                }\n            }\n        }\n\n        public IEnumerable<GitRemote> GetRemotes()\n        {\n            using (var git = CreateProcess(\"remote -v show\"))\n            {\n                // Redirect stderr so we can check for 'not a git repository' errors\n                git.StartInfo.RedirectStandardError = true;\n                git.Start(Trace2ProcessClass.Git);\n                // To avoid deadlocks, always read the output stream first and then wait\n                // TODO: don't read in all the data at once; stream it\n                string data = git.StandardOutput.ReadToEnd();\n                string stderr = git.StandardError.ReadToEnd();\n                git.WaitForExit();\n\n                switch (git.ExitCode)","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Git.cs#L152-L188","documentation":"Thrown by Git.GetCurrentRepositoryInternal when the `git rev-parse --show-toplevel` (or similar) process exits with an unexpected non-zero, non-128 exit code. Exit code 128 (not a repository) is handled by returning null, so this error means git failed for some other reason — a corrupted repo, a broken git installation, or an unreadable working directory. It wraps the underlying git stderr via CreateGitException.","triggerScenarios":"Calling GetCurrentRepository or IsInsideRepository when the git subprocess exits with a code other than 0 or 128 — e.g. corrupted .git directory, git not functioning, permission errors reading the repo, or a disk/IO failure during rev-parse.","commonSituations":"Running inside a partially deleted or corrupted repository; a broken or very old git binary; antivirus or indexing locking .git files; running with insufficient permissions on the working tree.","solutions":["Run `git rev-parse --show-toplevel` manually in the same directory to see the real git error","Verify the repository is not corrupted (`git status`, `git fsck`) and restore .git if needed","Check the git binary works (`git --version`) and PATH points to a valid installation","Check file/directory permissions on the working tree and .git folder"],"exampleFix":"// before\nvar repo = git.GetCurrentRepository(); // throws on exit=129\n// after\nif (!git.IsInsideRepository(path)) return;\ntry { var repo = git.GetCurrentRepository(); }\ncatch (GitException ex) { _trace.WriteLine(ex.Message); }","handlingStrategy":"try-catch","validationCode":"// before calling\ndirectory.CreateDirectoryIfNeeded();\nif (!System.IO.Directory.Exists(workingDir)) return null;\nvar probe = Process.Run(\"git\", \"rev-parse --git-dir\", workingDir);\nif (probe.ExitCode != 0) return null;","typeGuard":"bool IsUsableRepo(Git git) { try { return git.IsInsideRepository(); } catch (GitException) { return false; } }","tryCatchPattern":"try { var repo = git.GetCurrentRepository(); }\ncatch (GitException ex) { log.Warn($\"Repo detection failed: {ex.Message}\"); repo = null; }","preventionTips":["Verify the directory exists and contains a valid repository before querying","Keep git installed and on PATH; pin a known-good git version","Run `git fsck` periodically in long-lived repositories","Avoid deleting .git contents while the app is running"],"tags":["git","process","repository"],"backgroundTag":"git-command-failed","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}