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