TQ\Vcs\Repository\AbstractRepository::transactional PHP Method

transactional() public method

The closure $function will be called with a {@see \TQ\Vcs\Repository\Transaction} as its only argument
public transactional ( Closure $function ) : Transaction
$function Closure The callback used inside the transaction
return Transaction
    public function transactional(\Closure $function)
    {
        try {
            $transaction = new Transaction($this);
            $result = $function($transaction);
            $this->add(null);
            if ($this->isDirty()) {
                $commitMsg = $transaction->getCommitMsg();
                if (empty($commitMsg)) {
                    $commitMsg = sprintf('%s did a transactional commit in "%s"', __CLASS__, $this->getRepositoryPath());
                }
                $this->commit($commitMsg, null, $transaction->getAuthor());
            }
            $commitHash = $this->getCurrentCommit();
            $transaction->setCommitHash($commitHash);
            $transaction->setResult($result);
            return $transaction;
        } catch (\Exception $e) {
            $this->reset();
            throw $e;
        }
    }