Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91270343
DifferentialGetWorkingCopy.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
Sat, Nov 9, 13:06
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Nov 11, 13:06 (2 d)
Engine
blob
Format
Raw Data
Handle
22233566
Attached To
rPH Phabricator
DifferentialGetWorkingCopy.php
View Options
<?php
/**
* Can't find a good place for this, so I'm putting it in the most notably
* wrong place.
*/
final
class
DifferentialGetWorkingCopy
{
/**
* Creates and/or cleans a workspace for the requested repo.
*
* return ArcanistGitAPI
*/
public
static
function
getCleanGitWorkspace
(
PhabricatorRepository
$repo
)
{
$origin_path
=
$repo
->
getLocalPath
();
$path
=
rtrim
(
$origin_path
,
'/'
);
$path
=
$path
.
'__workspace'
;
if
(!
Filesystem
::
pathExists
(
$path
))
{
$repo
->
execxLocalCommand
(
'clone -- file://%s %s'
,
$origin_path
,
$path
);
if
(!
$repo
->
isHosted
())
{
id
(
new
ArcanistGitAPI
(
$path
))->
execxLocal
(
'remote set-url origin %s'
,
$repo
->
getRemoteURI
());
}
}
$workspace
=
new
ArcanistGitAPI
(
$path
);
$workspace
->
execxLocal
(
'clean -f -d'
);
$workspace
->
execxLocal
(
'checkout master'
);
$workspace
->
execxLocal
(
'fetch'
);
$workspace
->
execxLocal
(
'reset --hard origin/master'
);
$workspace
->
reloadWorkingCopy
();
return
$workspace
;
}
/**
* Creates and/or cleans a workspace for the requested repo.
*
* return ArcanistMercurialAPI
*/
public
static
function
getCleanMercurialWorkspace
(
PhabricatorRepository
$repo
)
{
$origin_path
=
$repo
->
getLocalPath
();
$path
=
rtrim
(
$origin_path
,
'/'
);
$path
=
$path
.
'__workspace'
;
if
(!
Filesystem
::
pathExists
(
$path
))
{
$repo
->
execxLocalCommand
(
'clone -- file://%s %s'
,
$origin_path
,
$path
);
}
$workspace
=
new
ArcanistMercurialAPI
(
$path
);
$workspace
->
execxLocal
(
'pull'
);
$workspace
->
execxLocal
(
'update --clean default'
);
$workspace
->
reloadWorkingCopy
();
return
$workspace
;
}
}
Event Timeline
Log In to Comment