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
This commit is contained in:
DevSoftTech Server 2026-08-04 03:01:43 +05:30
parent ca570d6366
commit 8f9920e71c

View File

@ -88,14 +88,28 @@ class SystemOperations
$statusCmd = 'cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' status 2>&1'; $statusCmd = 'cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' status 2>&1';
$statusResult = $this->runCommand($statusCmd); $statusResult = $this->runCommand($statusCmd);
if ($statusResult['exit_code'] !== 0) { if ($statusResult['exit_code'] !== 0) {
$statusError = $statusResult['output']; $statusError = trim($statusResult['output']);
$errorMsg = '';
// Parse error message
if (strpos($statusError, 'Permission denied') !== false) { if (strpos($statusError, 'Permission denied') !== false) {
$errorMsg = 'Permission denied. Git directory may not be writable by current user.'; $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) { } elseif (strpos($statusError, 'fatal') !== false) {
$errorMsg = 'Git fatal error: ' . $statusError; $errorMsg = 'Git error: ' . $statusError;
} else { } 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([ $this->appendHistory([
'timestamp' => date('Y-m-d H:i:s'), 'timestamp' => date('Y-m-d H:i:s'),
'type' => 'update', 'type' => 'update',
@ -191,6 +205,48 @@ class SystemOperations
return null; 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 public function runServerAction(string $action): array
{ {
$commands = [ $commands = [