forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorDifferentialAttachCommitWorkflow.php
88 lines (71 loc) · 2.35 KB
/
PhabricatorDifferentialAttachCommitWorkflow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
final class PhabricatorDifferentialAttachCommitWorkflow
extends PhabricatorDifferentialManagementWorkflow {
protected function didConstruct() {
$this
->setName('attach-commit')
->setExamples('**attach-commit** __commit__ __revision__')
->setSynopsis(pht('Forcefully attach a commit to a revision.'))
->setArguments(
array(
array(
'name' => 'argv',
'wildcard' => true,
'help' => pht('Commit, and a revision to attach it to.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$viewer = $this->getViewer();
$argv = $args->getArg('argv');
if (count($argv) !== 2) {
throw new PhutilArgumentUsageException(
pht('Specify a commit and a revision to attach it to.'));
}
$commit_name = head($argv);
$revision_name = last($argv);
$commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIdentifiers(array($commit_name))
->executeOne();
if (!$commit) {
throw new PhutilArgumentUsageException(
pht('Commit "%s" does not exist.', $commit_name));
}
$revision = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withNames(array($revision_name))
->executeOne();
if (!$revision) {
throw new PhutilArgumentUsageException(
pht('Revision "%s" does not exist.', $revision_name));
}
if (!($revision instanceof DifferentialRevision)) {
throw new PhutilArgumentUsageException(
pht('Object "%s" must be a Differential revision.', $revision_name));
}
// Reload the revision to get the active diff.
$revision = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withIDs(array($revision->getID()))
->needActiveDiffs(true)
->executeOne();
$differential_phid = id(new PhabricatorDifferentialApplication())
->getPHID();
$extraction_engine = id(new DifferentialDiffExtractionEngine())
->setViewer($viewer)
->setAuthorPHID($differential_phid);
$content_source = $this->newContentSource();
$extraction_engine->updateRevisionWithCommit(
$revision,
$commit,
array(),
$content_source);
echo tsprintf(
"%s\n",
pht(
'Attached "%s" to "%s".',
$commit->getMonogram(),
$revision->getMonogram()));
}
}