<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$repoDir = '/home/junaidzoom/public_html/graduation.zoomarts.com'; // Replace with your actual repository path

// Check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Execute the git pull command using exec
    $output = [];
    $return_var = 0;

    exec('cd ' . escapeshellarg($repoDir) . ' && git pull 2>&1', $output, $return_var);

    if ($return_var === 0) {
        echo json_encode(['status' => 'success', 'message' => 'Pulled latest changes.', 'output' => implode("\n", $output)]);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Failed to pull changes.', 'output' => implode("\n", $output)]);
    }
} else {
    // If the request method is not POST
    http_response_code(405); // Method Not Allowed
    echo json_encode(['status' => 'error', 'message' => 'Only POST requests are allowed.']);
}
?>
