Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F103784539
PhabricatorDifferentialAttachCommitWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Mar 4, 18:17
Size
2 KB
Mime Type
text/x-php
Expires
Thu, Mar 6, 18:17 (2 d)
Engine
blob
Format
Raw Data
Handle
24651010
Attached To
rPH Phabricator
PhabricatorDifferentialAttachCommitWorkflow.php
View Options
<?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
()));
}
}
Event Timeline
Log In to Comment