}
public function setRelativeCommit($commit) {
- list($err) = $this->execManualLocal('id -ir %s', $commit);
- if ($err) {
+ if (!$this->hasLocalCommit($commit)) {
throw new ArcanistUsageException(
"Commit '{$commit}' is not a valid Mercurial commit identifier.");
}
-
$this->relativeCommit = $commit;
return $this;
}
return true;
}
+ public function hasLocalCommit($commit) {
+ list($err) = $this->execManualLocal('id -ir %s', $commit);
+ return !$err;
+ }
+
public function parseRelativeLocalCommit(array $argv) {
if (count($argv) == 0) {
return;
// Check to see if the bundle's base revision matches the working copy
// base revision
- $bundle_base_rev = $bundle->getBaseRevision();
- if (empty($bundle_base_rev)) {
- // this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version < 2
- // they don't have a base rev so just do nothing
- } else {
- $repository_api = $this->getRepositoryAPI();
- $source_base_rev = $repository_api->getWorkingCopyRevision();
-
- if ($source_base_rev != $bundle_base_rev) {
+ $repository_api = $this->getRepositoryAPI();
+ if ($repository_api->supportsRelativeLocalCommits()) {
+ $bundle_base_rev = $bundle->getBaseRevision();
+ if (empty($bundle_base_rev)) {
+ // this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version < 2
+ // they don't have a base rev so just do nothing
+ $commit_exists = true;
+ } else {
+ $commit_exists =
+ $repository_api->hasLocalCommit($bundle_base_rev);
+ }
+ if (!$commit_exists) {
// we have a problem...! lots of work because we need to ask
// differential for revision information for these base revisions
// to improve our error message.
$bundle_base_rev_str = null;
+ $source_base_rev = $repository_api->getWorkingCopyRevision();
$source_base_rev_str = null;
- // SVN doesn't store these hashes, so we're basically done already
- // and will have a relatively "lame" error message
- if ($repository_api instanceof ArcanistSubversionAPI) {
- $hash_type = null;
- } else if ($repository_api instanceof ArcanistGitAPI) {
+ if ($repository_api instanceof ArcanistGitAPI) {
$hash_type = ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT;
} else if ($repository_api instanceof ArcanistMercurialAPI) {
$hash_type = ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT;
$ok = phutil_console_confirm(
"This diff is against commit {$bundle_base_rev_str}, but the ".
- "working copy is at {$source_base_rev_str}. ".
- "Still try to apply it?",
+ "commit is nowhere in the working copy. Try to apply it against ".
+ "the current working copy state? ({$source_base_rev_str})",
$default_no = false
);
if (!$ok) {