From 8f9920e71c30c31e466ea6f877b7edf33926d8ac Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 4 Aug 2026 03:01:43 +0530 Subject: [PATCH] improve: enhanced git status error messages with full diagnostics Better error message handling: - Show actual error output from git status - Detect specific issues: missing config, SSL certs, repository corruption - Parse error patterns for user-friendly messages - Include git version, config, and remote info in error response Added getGitDiagnostics() method: - Returns git version - Checks git config user.name and user.email - Shows configured remote URL - Displays current branch - Helps diagnose setup issues Error message now includes: [git version, user name, remote URL] Helps users identify: missing user config, wrong remote, SSH vs HTTPS issues --- app/Libraries/SystemOperations.php | 62 ++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/app/Libraries/SystemOperations.php b/app/Libraries/SystemOperations.php index 9a8403b..e345640 100644 --- a/app/Libraries/SystemOperations.php +++ b/app/Libraries/SystemOperations.php @@ -88,14 +88,28 @@ class SystemOperations $statusCmd = 'cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' status 2>&1'; $statusResult = $this->runCommand($statusCmd); if ($statusResult['exit_code'] !== 0) { - $statusError = $statusResult['output']; + $statusError = trim($statusResult['output']); + $errorMsg = ''; + + // Parse error message if (strpos($statusError, 'Permission denied') !== false) { $errorMsg = 'Permission denied. Git directory may not be writable by current user.'; + } elseif (strpos($statusError, 'fatal: Not a git repository') !== false) { + $errorMsg = 'Not a git repository. Repository initialization may be corrupted.'; + } elseif (strpos($statusError, 'user.email') !== false || strpos($statusError, 'user.name') !== false) { + $errorMsg = 'Git user configuration missing. Run: git config user.name "name" && git config user.email "email@example.com"'; + } elseif (strpos($statusError, 'SSL certificate problem') !== false) { + $errorMsg = 'SSL certificate verification failed. Run: git config --global http.sslVerify false (if using HTTPS)'; } elseif (strpos($statusError, 'fatal') !== false) { - $errorMsg = 'Git fatal error: ' . $statusError; + $errorMsg = 'Git error: ' . $statusError; } else { - $errorMsg = 'Git status check failed: ' . $statusError; + $errorMsg = 'Git status failed: ' . $statusError; } + + // Add diagnostics to help user + $diagnostics = $this->getGitDiagnostics($gitPath, $repoPath); + $errorMsg .= ' [' . $diagnostics['git_version'] . ', User: ' . $diagnostics['git_config_user_name'] . ', Remote: ' . $diagnostics['remote_url'] . ']'; + $this->appendHistory([ 'timestamp' => date('Y-m-d H:i:s'), 'type' => 'update', @@ -191,6 +205,48 @@ class SystemOperations return null; } + private function getGitDiagnostics(string $gitPath, string $repoPath): array + { + $diagnostics = [ + 'git_version' => 'Unknown', + 'git_config_user_name' => 'Not set', + 'git_config_user_email' => 'Not set', + 'remote_url' => 'Not configured', + 'current_branch' => 'Unknown', + ]; + + // Get git version + $result = $this->runCommand(escapeshellarg($gitPath) . ' --version 2>&1'); + if ($result['exit_code'] === 0) { + $diagnostics['git_version'] = trim($result['output']); + } + + // Get git config + $result = $this->runCommand('cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' config user.name 2>&1'); + if ($result['exit_code'] === 0) { + $diagnostics['git_config_user_name'] = trim($result['output']); + } + + $result = $this->runCommand('cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' config user.email 2>&1'); + if ($result['exit_code'] === 0) { + $diagnostics['git_config_user_email'] = trim($result['output']); + } + + // Get remote URL + $result = $this->runCommand('cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' config --get remote.origin.url 2>&1'); + if ($result['exit_code'] === 0) { + $diagnostics['remote_url'] = trim($result['output']); + } + + // Get current branch + $result = $this->runCommand('cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' rev-parse --abbrev-ref HEAD 2>&1'); + if ($result['exit_code'] === 0) { + $diagnostics['current_branch'] = trim($result['output']); + } + + return $diagnostics; + } + public function runServerAction(string $action): array { $commands = [