$config->willRunWorkflow($command, $workflow);
$workflow->willRunWorkflow();
- $err = $workflow->run();
- $config->didRunWorkflow($command, $workflow, $err);
+ try {
+ $err = $workflow->run();
+ $config->didRunWorkflow($command, $workflow, $err);
+ } catch (Exception $e) {
+ $workflow->finalize();
+ throw $e;
+ }
+ $workflow->finalize();
exit((int)$err);
} catch (ArcanistNoEffectException $ex) {
"Password to use for basic auth over http transports",
'example' => '"bobhasasecret"',
),
+ 'arc.autostash' => array(
+ 'type' => 'bool',
+ 'help' =>
+ 'Whether arc should permit the automatic stashing of changes in '.
+ 'the working directory when requiring a clean working copy. '.
+ 'This option should only be used when users understand how '.
+ 'to restore their working directory from the local stash if '.
+ 'an Arcanist operation causes an unrecoverable error.',
+ 'example' => 'false',
+ ),
);
}
return null;
}
+ public function canStashChanges() {
+ return true;
+ }
+
+ public function stashChanges() {
+ $this->execxLocal('stash');
+ $this->reloadWorkingCopy();
+ }
+
+ public function unstashChanges() {
+ $this->execxLocal('stash pop');
+ }
+
}
abstract protected function buildLocalFuture(array $argv);
+ public function canStashChanges() {
+ return false;
+ }
+
+ public function stashChanges() {
+ throw new ArcanistCapabilityNotSupportedException($this);
+ }
+
+ public function unstashChanges() {
+ throw new ArcanistCapabilityNotSupportedException($this);
+ }
/* -( Scratch Files )------------------------------------------------------ */
private $passedArguments;
private $command;
+ private $stashed;
+
private $projectInfo;
private $arcanistConfiguration;
abstract public function run();
+ /**
+ * Finalizes any cleanup operations that need to occur regardless of
+ * whether the command succeeded or failed.
+ */
+ public function finalize() {
+ $this->finalizeWorkingCopy();
+ }
+
/**
* Return the command used to invoke this workflow from the command like,
* e.g. "help" for @{class:ArcanistHelpWorkflow}.
return $this;
}
+ public function finalizeWorkingCopy() {
+ if ($this->stashed) {
+ $api = $this->getRepositoryAPI();
+ $api->unstashChanges();
+ echo "Restored stashed changes to the working directory.\n";
+ }
+ }
+
public function requireCleanWorkingCopy() {
$api = $this->getRepositoryAPI();
$api->addToCommit($unstaged);
$must_commit += array_flip($unstaged);
} else {
- throw new ArcanistUsageException(
- "Stage and commit (or revert) them before proceeding.");
+ $permit_autostash = $this->getWorkingCopy()->getConfigFromAnySource(
+ 'arc.autostash',
+ false);
+ if ($permit_autostash && $api->canStashChanges()) {
+ echo "Stashing uncommitted changes. (You can restore them with ".
+ "`git stash pop`.)\n";
+ $api->stashChanges();
+ $this->stashed = true;
+ } else {
+ throw new ArcanistUsageException(
+ "Stage and commit (or revert) them before proceeding.");
+ }
}
}