From ca570d63663ac15542132bb6daceba84efc953ec Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 4 Aug 2026 02:59:42 +0530 Subject: [PATCH] fix: resolve git command not found by checking common installation paths - Added findGitCommand() method to check for git in common locations: * /usr/bin/git (standard Linux) * /bin/git (alternative location) * /usr/local/bin/git (compiled from source) * Falls back to 'which git' and 'command -v git' - Uses absolute git path in all shell commands - Fixes 'Git command not found' error on systems where git is not in PATH - No dependencies added, uses PHP file_exists() + is_executable() checks --- app/Libraries/SystemOperations.php | 39 +++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/app/Libraries/SystemOperations.php b/app/Libraries/SystemOperations.php index 059c5e3..9a8403b 100644 --- a/app/Libraries/SystemOperations.php +++ b/app/Libraries/SystemOperations.php @@ -69,10 +69,10 @@ class SystemOperations return ['ok' => false, 'message' => $errorMsg]; } - // Pre-check: Verify git is accessible - $gitCheck = $this->safeCommand('which git 2>/dev/null || command -v git 2>/dev/null'); - if ($gitCheck === 'Unavailable' || trim($gitCheck) === '') { - $errorMsg = 'Git command not found on system. Cannot execute git pull.'; + // Find git command location (try common paths) + $gitPath = $this->findGitCommand(); + if (!$gitPath) { + $errorMsg = 'Git command not found. Tried: /usr/bin/git, /bin/git, /usr/local/bin/git. Ensure git is installed on the system.'; $this->appendHistory([ 'timestamp' => date('Y-m-d H:i:s'), 'type' => 'update', @@ -85,7 +85,7 @@ class SystemOperations } // Run git status first to check connectivity and permissions - $statusCmd = 'cd ' . escapeshellarg($repoPath) . ' && git status 2>&1'; + $statusCmd = 'cd ' . escapeshellarg($repoPath) . ' && ' . escapeshellarg($gitPath) . ' status 2>&1'; $statusResult = $this->runCommand($statusCmd); if ($statusResult['exit_code'] !== 0) { $statusError = $statusResult['output']; @@ -108,7 +108,7 @@ class SystemOperations } // Run git pull with timeout protection - $command = 'cd ' . escapeshellarg($repoPath) . ' && timeout 60 git pull origin main 2>&1'; + $command = 'cd ' . escapeshellarg($repoPath) . ' && timeout 60 ' . escapeshellarg($gitPath) . ' pull origin main 2>&1'; $result = $this->runCommand($command); $output = $result['output']; @@ -164,6 +164,33 @@ class SystemOperations return ['ok' => true, 'message' => 'HMS update completed successfully', 'output' => $output]; } + private function findGitCommand(): ?string + { + // Try common git installation paths + $gitPaths = [ + '/usr/bin/git', + '/bin/git', + '/usr/local/bin/git', + ]; + + foreach ($gitPaths as $path) { + if (file_exists($path) && is_executable($path)) { + return $path; + } + } + + // Try to find git in PATH using shell + $result = $this->runCommand('which git 2>/dev/null || command -v git 2>/dev/null'); + if ($result['exit_code'] === 0 && trim($result['output']) !== '') { + $gitPath = trim($result['output']); + if (file_exists($gitPath)) { + return $gitPath; + } + } + + return null; + } + public function runServerAction(string $action): array { $commands = [