Differential D14337 Diff 34622 src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
| Show First 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | public function activateLease( | ||||
| $map = $lease->getAttribute('repositories.map'); | $map = $lease->getAttribute('repositories.map'); | ||||
| $root = $resource->getAttribute('workingcopy.root'); | $root = $resource->getAttribute('workingcopy.root'); | ||||
| $default = null; | $default = null; | ||||
| foreach ($map as $directory => $spec) { | foreach ($map as $directory => $spec) { | ||||
| $cmd = array(); | $cmd = array(); | ||||
| $arg = array(); | $arg = array(); | ||||
| $cmd[] = 'cd %s'; | $interface->pushWorkingDirectory("{$root}/repo/{$directory}/"); | ||||
| $arg[] = "{$root}/repo/{$directory}/"; | |||||
| $cmd[] = 'git clean -d --force'; | $cmd[] = 'git clean -d --force'; | ||||
| $cmd[] = 'git fetch'; | $cmd[] = 'git fetch'; | ||||
| $commit = idx($spec, 'commit'); | $commit = idx($spec, 'commit'); | ||||
| $branch = idx($spec, 'branch'); | $branch = idx($spec, 'branch'); | ||||
| $ref = idx($spec, 'ref'); | $ref = idx($spec, 'ref'); | ||||
| Show All 30 Lines | foreach ($map as $directory => $spec) { | ||||
| $result = call_user_func_array( | $result = call_user_func_array( | ||||
| array($interface, 'execx'), | array($interface, 'execx'), | ||||
| $argv); | $argv); | ||||
| if (idx($spec, 'default')) { | if (idx($spec, 'default')) { | ||||
| $default = $directory; | $default = $directory; | ||||
| } | } | ||||
| $merges = idx($spec, 'merges'); | |||||
| if ($merges) { | |||||
| foreach ($merges as $merge) { | |||||
| $this->applyMerge($interface, $merge); | |||||
| } | |||||
| } | |||||
| $interface->popWorkingDirectory(); | |||||
| } | } | ||||
| if ($default === null) { | if ($default === null) { | ||||
| $default = head_key($map); | $default = head_key($map); | ||||
| } | } | ||||
| // TODO: Use working storage? | // TODO: Use working storage? | ||||
| $lease->setAttribute('workingcopy.default', "{$root}/repo/{$default}/"); | $lease->setAttribute('workingcopy.default', "{$root}/repo/{$default}/"); | ||||
| Show All 32 Lines | public function getInterface( | ||||
| $type) { | $type) { | ||||
| switch ($type) { | switch ($type) { | ||||
| case DrydockCommandInterface::INTERFACE_TYPE: | case DrydockCommandInterface::INTERFACE_TYPE: | ||||
| $host_lease = $this->loadHostLease($resource); | $host_lease = $this->loadHostLease($resource); | ||||
| $command_interface = $host_lease->getInterface($type); | $command_interface = $host_lease->getInterface($type); | ||||
| $path = $lease->getAttribute('workingcopy.default'); | $path = $lease->getAttribute('workingcopy.default'); | ||||
| $command_interface->setWorkingDirectory($path); | $command_interface->pushWorkingDirectory($path); | ||||
| return $command_interface; | return $command_interface; | ||||
| } | } | ||||
| } | } | ||||
| private function loadRepositories(array $phids) { | private function loadRepositories(array $phids) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | return array( | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| protected function shouldUseConcurrentResourceLimit() { | protected function shouldUseConcurrentResourceLimit() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| private function applyMerge( | |||||
| DrydockCommandInterface $interface, | |||||
| array $merge) { | |||||
| $src_uri = $merge['src.uri']; | |||||
| $src_ref = $merge['src.ref']; | |||||
| $interface->execx( | |||||
| 'git fetch --no-tags -- %s +%s:%s', | |||||
| $src_uri, | |||||
| $src_ref, | |||||
| $src_ref); | |||||
| try { | |||||
| $interface->execx( | |||||
| 'git merge --no-stat --squash --ff-only -- %s', | |||||
| $src_ref); | |||||
| } catch (CommandException $ex) { | |||||
| // TODO: Specifically note this as a merge conflict. | |||||
| throw $ex; | |||||
| } | |||||
| } | |||||
| } | } | ||||