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
This commit is contained in:
parent
a024f89205
commit
ca570d6366
|
|
@ -69,10 +69,10 @@ class SystemOperations
|
||||||
return ['ok' => false, 'message' => $errorMsg];
|
return ['ok' => false, 'message' => $errorMsg];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pre-check: Verify git is accessible
|
// Find git command location (try common paths)
|
||||||
$gitCheck = $this->safeCommand('which git 2>/dev/null || command -v git 2>/dev/null');
|
$gitPath = $this->findGitCommand();
|
||||||
if ($gitCheck === 'Unavailable' || trim($gitCheck) === '') {
|
if (!$gitPath) {
|
||||||
$errorMsg = 'Git command not found on system. Cannot execute git pull.';
|
$errorMsg = 'Git command not found. Tried: /usr/bin/git, /bin/git, /usr/local/bin/git. Ensure git is installed on the system.';
|
||||||
$this->appendHistory([
|
$this->appendHistory([
|
||||||
'timestamp' => date('Y-m-d H:i:s'),
|
'timestamp' => date('Y-m-d H:i:s'),
|
||||||
'type' => 'update',
|
'type' => 'update',
|
||||||
|
|
@ -85,7 +85,7 @@ class SystemOperations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run git status first to check connectivity and permissions
|
// 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);
|
$statusResult = $this->runCommand($statusCmd);
|
||||||
if ($statusResult['exit_code'] !== 0) {
|
if ($statusResult['exit_code'] !== 0) {
|
||||||
$statusError = $statusResult['output'];
|
$statusError = $statusResult['output'];
|
||||||
|
|
@ -108,7 +108,7 @@ class SystemOperations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run git pull with timeout protection
|
// 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);
|
$result = $this->runCommand($command);
|
||||||
$output = $result['output'];
|
$output = $result['output'];
|
||||||
|
|
||||||
|
|
@ -164,6 +164,33 @@ class SystemOperations
|
||||||
return ['ok' => true, 'message' => 'HMS update completed successfully', 'output' => $output];
|
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
|
public function runServerAction(string $action): array
|
||||||
{
|
{
|
||||||
$commands = [
|
$commands = [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user