<commit_before><?php namespace Fadion\Maneuver;

use Banago\Bridge\Bridge;
use Exception;

/**
 * Class Deploy
 *
 * Handles remote server operations.
 */
class Deploy {

    /**
     * @var \Fadion\Maneuver\Git
     */
    protected $git;

    /**
     * @var \Banago\Bridge\Bridge
     */
    protected $bridge;

    /**
     * @var string Server credentials
     */
    protected $server;

    /**
     * @var string Revision filename
     */
    protected $revisionFile = '.revision';

    /**
     * @var string Commit to sync revision file to
     */
    protected $syncCommit;

    /**
     * @var bool
     */
    protected $isSubmodule = false;

    /**
     * @var array List of ignored files
     */
    protected $ignoredFiles;

    /**
     * @var array List of files to upload
     */
    protected $filesToUpload;

    /**
     * @var array List of files to delete
     */
    protected $filesToDelete;

    /**
     * Constructor
     *
     * @param \Fadion\Maneuver\Git $git
     * @param \Banago\Bridge\Bridge $bridge
     * @param array $server
     */
    public function __construct(Git $git, Bridge $bridge, $server)
    {
        $this->git = $git;
        $this->bridge = $bridge;
        $this->ignoredFiles = $git->getIgnored();
        $this->server = $server;
    }

    /**
     * Compares local revision to the remote one and
     * builds files to upload and delete
     *
     * @throws Exception if unknown git diff status
     * @return string
     */
    public function compare()
    {
        $remoteRevision = null;
        $filesToUpload = array();
        $filesToDelete = array();

        // The revision file goes inside the submodule.
        if ($this->isSubmodule) {
            $this->revisionFile = $this->isSubmodule . '/' . $this->revisionFile;
        }

        if ($this->bridge->exists($this->revisionFile)) {
            $remoteRevision = $this->bridge->get($this->revisionFile);

            $message = "\r\n» Taking it from '" . substr($remoteRevision, 0, 7) . "'";
        } else {
            $message = "\r\n» Fresh deployment - grab a coffee";
        }

        // A remote version exists.
        if ($remoteRevision) {
            // Get the files from the diff.
            $output = $this->git->diff($remoteRevision);

            foreach ($output as $line) {
                // Added, changed or modified.
                if ($line[0] == 'A' or $line[0] == 'C' or $line[0] == 'M') {
                    $filesToUpload[] = trim(substr($line, 1));
                }
                // Deleted.
                elseif ($line[0] == 'D') {
                    $filesToDelete[] = trim(substr($line, 1));
                }
                // Unknown status.
                else {
                    throw new Exception("Unknown git-diff status: {$line[0]}");
                }
            }
        }
        // No remote version. Get all files.
        else {
            $filesToUpload = $this->git->files();
        }

        // Remove ignored files from the list of uploads.
        $filesToUpload = array_diff($filesToUpload, $this->ignoredFiles);

        $this->filesToUpload = $filesToUpload;
        $this->filesToDelete = $filesToDelete;

        return $message;
    }

    /**
     * Getter for $this->filesToUpload
     *
     * @return array
     */
    public function getFilesToUpload()<commit_msg>add to deploy vendor files<commit_after><?php namespace Fadion\Maneuver;

use Banago\Bridge\Bridge;
use Exception;

/**
 * Class Deploy
 *
 * Handles remote server operations.
 */
class Deploy {

    /**
     * @var \Fadion\Maneuver\Git
     */
    protected $git;

    /**
     * @var \Banago\Bridge\Bridge
     */
    protected $bridge;

    /**
     * @var string Server credentials
     */
    protected $server;

    /**
     * @var string Revision filename
     */
    protected $revisionFile = '.revision';

    /**
     * @var string Commit to sync revision file to
     */
    protected $syncCommit;

    /**
     * @var bool
     */
    protected $isSubmodule = false;

    /**
     * @var array List of ignored files
     */
    protected $ignoredFiles;

    /**
     * @var array List of files to upload
     */
    protected $filesToUpload;

    /**
     * @var array List of files to delete
     */
    protected $filesToDelete;

    /**
     * Constructor
     *
     * @param \Fadion\Maneuver\Git $git
     * @param \Banago\Bridge\Bridge $bridge
     * @param array $server
     */
    public function __construct(Git $git, Bridge $bridge, $server)
    {
        $this->git = $git;
        $this->bridge = $bridge;
        $this->ignoredFiles = $git->getIgnored();
        $this->server = $server;
    }

    /**
     * Compares local revision to the remote one and
     * builds files to upload and delete
     *
     * @throws Exception if unknown git diff status
     * @return string
     */
    public function compare()
    {
        $remoteRevision = null;
        $filesToUpload = array();
        $filesToDelete = array();

        // The revision file goes inside the submodule.
        if ($this->isSubmodule) {
            $this->revisionFile = $this->isSubmodule . '/' . $this->revisionFile;
        }

        if ($this->bridge->exists($this->revisionFile)) {
            $remoteRevision = $this->bridge->get($this->revisionFile);

            $message = "\r\n» Taking it from '" . substr($remoteRevision, 0, 7) . "'";
        } else {
            $message = "\r\n» Fresh deployment - grab a coffee";
        }

        // A remote version exists.
        if ($remoteRevision) {
            // Get the files from the diff.
            $output = $this->git->diff($remoteRevision);

            foreach ($output as $line) {
                // Added, changed or modified.
                if ($line[0] == 'A' or $line[0] == 'C' or $line[0] == 'M') {
                    $filesToUpload[] = trim(substr($line, 1));
                }
                // Deleted.
                elseif ($line[0] == 'D') {
                    $filesToDelete[] = trim(substr($line, 1));
                }
                // Unknown status.
                else {
                    throw new Exception("Unknown git-diff status: {$line[0]}");
                }
            }
        }
        // No remote version. Get all files.
        else {
            $filesToUpload = $this->git->files();
        }

        if(config('maneuver.include_vendor')){
            $filesToUpload[] = $this->git->vendor();
        }

        // Remove ignored files from the list of uploads.
        $filesToUpload = array_diff($filesToUpload, $this->ignoredFiles);

        $this->filesToUpload = $filesToUpload;
        $this->filesToDelete = $filesToDelete;

        return $message;
    }

    /**
     * Getter for $this->filesToUpload
     *
     * @return array
     */
    public function getFilesToUpload()
{'fraction_non_alphanumeric': 0.13415697674418606, 'fraction_numerical': 0.002616279069767442, 'mean_word_length': 1.6506163328197228, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1053992', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1945, 'n_words': 510}