/**
  * Do the best we can to prevent PEBKAC and id10t issues.
  */
 private function sanityCheck(ArcanistBundle $bundle)
 {
     $repository_api = $this->getRepositoryAPI();
     // Check to see if the bundle's base revision matches the working copy
     // base revision
     if ($repository_api->supportsLocalCommits()) {
         $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;
             if ($repository_api instanceof ArcanistGitAPI) {
                 $hash_type = ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT;
             } else {
                 if ($repository_api instanceof ArcanistMercurialAPI) {
                     $hash_type = ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT;
                 } else {
                     $hash_type = null;
                 }
             }
             if ($hash_type) {
                 // 2 round trips because even though we could send off one query
                 // we wouldn't be able to tell which revisions were for which hash
                 $hash = array($hash_type, $bundle_base_rev);
                 $bundle_revision = $this->loadRevisionFromHash($hash);
                 $hash = array($hash_type, $source_base_rev);
                 $source_revision = $this->loadRevisionFromHash($hash);
                 if ($bundle_revision) {
                     $bundle_base_rev_str = $bundle_base_rev . ' \\ D' . $bundle_revision['id'];
                 }
                 if ($source_revision) {
                     $source_base_rev_str = $source_base_rev . ' \\ D' . $source_revision['id'];
                 }
             }
             $bundle_base_rev_str = nonempty($bundle_base_rev_str, $bundle_base_rev);
             $source_base_rev_str = nonempty($source_base_rev_str, $source_base_rev);
             $ok = phutil_console_confirm(pht('This diff is against commit %s, but the commit is nowhere ' . 'in the working copy. Try to apply it against the current ' . 'working copy state? (%s)', $bundle_base_rev_str, $source_base_rev_str), $default_no = false);
             if (!$ok) {
                 throw new ArcanistUserAbortException();
             }
         }
     }
 }
 /**
  * Do the best we can to prevent PEBKAC and id10t issues.
  */
 private function sanityCheck(ArcanistBundle $bundle)
 {
     $repository_api = $this->getRepositoryAPI();
     // Require clean working copy
     $this->requireCleanWorkingCopy();
     // Check to see if the bundle's project id matches the working copy
     // project id
     $bundle_project_id = $bundle->getProjectID();
     $working_copy_project_id = $this->getWorkingCopy()->getProjectID();
     if (empty($bundle_project_id)) {
         // this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version = 0
         // they don't come with a project id so just do nothing
     } else {
         if ($bundle_project_id != $working_copy_project_id) {
             if ($working_copy_project_id) {
                 $issue = "This patch is for the '{$bundle_project_id}' project,  but the " . "working copy belongs to the '{$working_copy_project_id}' project.";
             } else {
                 $issue = "This patch is for the '{$bundle_project_id}' project, but the " . "working copy does not have an '.arcconfig' file to identify which " . "project it belongs to.";
             }
             $ok = phutil_console_confirm("{$issue} Still try to apply the patch?", $default_no = false);
             if (!$ok) {
                 throw new ArcanistUserAbortException();
             }
         }
     }
     // Check to see if the bundle's base revision matches the working copy
     // base revision
     if ($repository_api->supportsLocalCommits()) {
         $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;
             if ($repository_api instanceof ArcanistGitAPI) {
                 $hash_type = ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT;
             } else {
                 if ($repository_api instanceof ArcanistMercurialAPI) {
                     $hash_type = ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT;
                 } else {
                     $hash_type = null;
                 }
             }
             if ($hash_type) {
                 // 2 round trips because even though we could send off one query
                 // we wouldn't be able to tell which revisions were for which hash
                 $hash = array($hash_type, $bundle_base_rev);
                 $bundle_revision = $this->loadRevisionFromHash($hash);
                 $hash = array($hash_type, $source_base_rev);
                 $source_revision = $this->loadRevisionFromHash($hash);
                 if ($bundle_revision) {
                     $bundle_base_rev_str = $bundle_base_rev . ' \\ D' . $bundle_revision['id'];
                 }
                 if ($source_revision) {
                     $source_base_rev_str = $source_base_rev . ' \\ D' . $source_revision['id'];
                 }
             }
             $bundle_base_rev_str = nonempty($bundle_base_rev_str, $bundle_base_rev);
             $source_base_rev_str = nonempty($source_base_rev_str, $source_base_rev);
             $ok = phutil_console_confirm("This diff is against commit {$bundle_base_rev_str}, but the " . "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) {
                 throw new ArcanistUserAbortException();
             }
         }
     }
     // TODO -- more sanity checks here
 }