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;
}
}