TQ\Svn\Repository\Repository::add PHP Method

add() public method

Adds one or more files to the staging area
public add ( array $file = null, boolean $force = false )
$file array The file(s) to be added or NULL to add all new and/or changed files to the staging area
$force boolean
    public function add(array $file = null, $force = false)
    {
        $args = array();
        if ($force) {
            $args[] = '--force';
        }
        if ($file !== null) {
            $status = $this->getStatus();
            if (empty($status)) {
                return;
            }
            $files = $this->resolveLocalGlobPath($file);
            foreach ($this->getStatus() as $status) {
                if ($status['status'] != 'unversioned' && in_array($status['file'], $files)) {
                    array_splice($files, array_search($status['file'], $files), 1);
                }
            }
            if (empty($files)) {
                return;
            }
            $args[] = '--parents';
            $args[] = '--';
            $args = array_merge($args, $files);
        } else {
            $toAdd = array();
            $toRemove = array();
            foreach ($this->getStatus() as $status) {
                if ($status['status'] == 'missing') {
                    $toRemove[] = $this->resolveLocalPath($status['file']);
                } else {
                    if ($status['status'] == 'unversioned') {
                        $toAdd[] = $this->resolveLocalPath($status['file']);
                    }
                }
            }
            if (!empty($toRemove)) {
                $this->remove($toRemove, false, $force);
            }
            if (empty($toAdd)) {
                return;
            }
            $args['--depth'] = 'infinity';
            $args[] = '--';
            $args = array_merge($args, $toAdd);
        }
        /** @var $result CallResult */
        $result = $this->getSvn()->{'add'}($this->getRepositoryPath(), $args);
        $result->assertSuccess(sprintf('Cannot add "%s" to "%s"', $file !== null ? implode(', ', $file) : '*', $this->getRepositoryPath()));
    }