private $conduit;
private $blobs = array();
private $diskPath;
+ private $projectID;
public function setConduit(ConduitClient $conduit) {
$this->conduit = $conduit;
}
+ public function setProjectID($project_id) {
+ $this->projectID = $project_id;
+ }
+
+ public function getProjectID() {
+ return $this->projectID;
+ }
+
public static function newFromChanges(array $changes) {
$obj = new ArcanistBundle();
$obj->changes = $changes;
public static function newFromArcBundle($path) {
$path = Filesystem::resolvePath($path);
+ $future = new ExecFuture(
+ csprintf(
+ 'tar tfO %s',
+ $path));
+ list($stdout, $file_list) = $future->resolvex();
+ $file_list = explode("\n", trim($file_list));
+
+ if (in_array('meta.json', $file_list)) {
+ $future = new ExecFuture(
+ csprintf(
+ 'tar xfO %s meta.json',
+ $path));
+ $meta_info = $future->resolveJSON();
+ $version = idx($meta_info, 'version', 0);
+ $project_name = idx($meta_info, 'projectName');
+ // this arc bundle was probably made before we started storing meta info
+ } else {
+ $version = 0;
+ $project_name = null;
+ }
+
$future = new ExecFuture(
csprintf(
'tar xfO %s changes.json',
}
}
-
foreach ($changes as $change_key => $change) {
$changes[$change_key] = ArcanistDiffChange::newFromDictionary($change);
}
$obj = new ArcanistBundle();
$obj->changes = $changes;
$obj->diskPath = $path;
+ $obj->setProjectID($project_name);
return $obj;
}
$blobs[$phid] = $this->getBlob($phid);
}
+ $meta_info = array('version' => 1,
+ 'projectName' => $this->getProjectID());
+
$dir = Filesystem::createTemporaryDirectory();
Filesystem::createDirectory($dir.'/hunks');
Filesystem::createDirectory($dir.'/blobs');
Filesystem::writeFile($dir.'/changes.json', json_encode($change_list));
+ Filesystem::writeFile($dir.'/meta.json', json_encode($meta_info));
foreach ($hunks as $key => $hunk) {
Filesystem::writeFile($dir.'/hunks/'.$key, $hunk);
}
'help' =>
"Apply changes from a git patchfile or unified patchfile.",
),
+ 'force' => array(
+ 'help' =>
+ "Do not run any sanity checks.",
+ ),
'*' => 'name',
);
}
}
} catch (Exception $ex) {
if ($ex->getErrorCode() == 'ERR-INVALID-SESSION') {
- // Phabricator is not configured to allow anonymos access to
+ // Phabricator is not configured to allow anonymous access to
// Differential.
$this->authenticateConduit();
return $this->run();
}
}
+ $force = $this->getArgument('force', false);
+ if ($force) {
+ // force means don't do any sanity checks about the patch
+ } else {
+ $this->sanityCheckPatch($bundle);
+ }
+
$repository_api = $this->getRepositoryAPI();
if ($repository_api instanceof ArcanistSubversionAPI) {
$patch_err = 0;
return array('ARGUMENT');
}
+ /**
+ * Do the best we can to prevent PEBKAC and id10t issues.
+ */
+ private function sanityCheckPatch(ArcanistBundle $bundle) {
+
+ // Check to see if the bundle 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
+ // they don't come with a project id so just do nothing
+ } else if ($bundle_project_id != $working_copy_project_id) {
+ $ok = phutil_console_confirm(
+ "This diff is for the '{$bundle_project_id}' project but the working ".
+ "copy belongs to the '{$working_copy_project_id}' project. ".
+ "Still try to apply it?",
+ $default_no = false
+ );
+ if (!$ok) {
+ throw new ArcanistUserAbortException();
+ }
+ }
+
+ // TODO -- more sanity checks here
+ }
+
/**
* Create parent directories one at a time, since we need to "svn add" each
* one. (Technically we could "svn add" just the topmost new directory.)