Changeset View
Changeset View
Standalone View
Standalone View
src/repository/state/ArcanistGitLocalState.php
<?php | <?php | ||||
final class ArcanistGitLocalState | final class ArcanistGitLocalState | ||||
extends ArcanistRepositoryLocalState { | extends ArcanistRepositoryLocalState { | ||||
private $localCommit; | private $localCommit; | ||||
private $localRef; | private $localRef; | ||||
private $localPath; | private $localPath; | ||||
private $stashStack = array(); | |||||
public function getLocalRef() { | public function getLocalRef() { | ||||
return $this->localRef; | return $this->localRef; | ||||
} | } | ||||
public function getLocalPath() { | public function getLocalPath() { | ||||
return $this->localPath; | return $this->localPath; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | protected function saveStash() { | ||||
// NOTE: We'd prefer to "git stash create" here, because using "push" | // NOTE: We'd prefer to "git stash create" here, because using "push" | ||||
// and "pop" means we're affecting the stash list as a side effect. | // and "pop" means we're affecting the stash list as a side effect. | ||||
// However, under Git 2.21.1, "git stash create" exits with no output, | // However, under Git 2.21.1, "git stash create" exits with no output, | ||||
// no error, and no effect if the working copy contains only untracked | // no error, and no effect if the working copy contains only untracked | ||||
// files. For now, accept mutations to the stash list. | // files. For now, accept mutations to the stash list. | ||||
// Generate a random stash reference and place on the stash stack, so it | |||||
// can be verified when restoring stashes that it happens in appropriate | |||||
// order. | |||||
$stash_ref = sprintf( | |||||
'arc-%s', | |||||
Filesystem::readRandomCharacters(12)); | |||||
$this->stashStack[] = $stash_ref; | |||||
$api->execxLocal('stash push --include-untracked --'); | $api->execxLocal('stash push --include-untracked --'); | ||||
$log = $this->getWorkflow()->getLogEngine(); | $log = $this->getWorkflow()->getLogEngine(); | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('SAVE STASH'), | pht('SAVE STASH'), | ||||
pht('Saved uncommitted changes from working copy.')); | pht('Saved uncommitted changes from working copy.')); | ||||
return true; | return $stash_ref; | ||||
} | } | ||||
protected function restoreStash($stash_ref) { | protected function restoreStash($stash_ref) { | ||||
$current_stash_ref = array_pop($this->stashStack); | |||||
if ($stash_ref !== $current_stash_ref) { | |||||
throw new Exception(pht( | |||||
'Unexpected stash reference for restoring stash: %s, but expected: %s', | |||||
$stash_ref, | |||||
$current_stash_ref)); | |||||
} | |||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
$log = $this->getWorkflow()->getLogEngine(); | $log = $this->getWorkflow()->getLogEngine(); | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('LOAD STASH'), | pht('LOAD STASH'), | ||||
pht('Restoring uncommitted changes to working copy.')); | pht('Restoring uncommitted changes to working copy.')); | ||||
// NOTE: Under Git 2.21.1, "git stash apply" does not accept "--". | // NOTE: Under Git 2.21.1, "git stash apply" does not accept "--". | ||||
Show All 15 Lines |