public function activateLease(DrydockBlueprint $blueprint, DrydockResource $resource, DrydockLease $lease)
 {
     $host_lease = $this->loadHostLease($resource);
     $command_type = DrydockCommandInterface::INTERFACE_TYPE;
     $interface = $host_lease->getInterface($command_type);
     $map = $lease->getAttribute('repositories.map');
     $root = $resource->getAttribute('workingcopy.root');
     $default = null;
     foreach ($map as $directory => $spec) {
         $cmd = array();
         $arg = array();
         $cmd[] = 'cd %s';
         $arg[] = "{$root}/repo/{$directory}/";
         $cmd[] = 'git clean -d --force';
         $cmd[] = 'git fetch';
         $commit = idx($spec, 'commit');
         $branch = idx($spec, 'branch');
         $ref = idx($spec, 'ref');
         if ($commit !== null) {
             $cmd[] = 'git reset --hard %s';
             $arg[] = $commit;
         } else {
             if ($branch !== null) {
                 $cmd[] = 'git checkout %s';
                 $arg[] = $branch;
                 $cmd[] = 'git reset --hard origin/%s';
                 $arg[] = $branch;
             } else {
                 if ($ref) {
                     $ref_uri = $ref['uri'];
                     $ref_ref = $ref['ref'];
                     $cmd[] = 'git fetch --no-tags -- %s +%s:%s';
                     $arg[] = $ref_uri;
                     $arg[] = $ref_ref;
                     $arg[] = $ref_ref;
                     $cmd[] = 'git checkout %s';
                     $arg[] = $ref_ref;
                     $cmd[] = 'git reset --hard %s';
                     $arg[] = $ref_ref;
                 } else {
                     $cmd[] = 'git reset --hard HEAD';
                 }
             }
         }
         $cmd = implode(' && ', $cmd);
         $argv = array_merge(array($cmd), $arg);
         $result = call_user_func_array(array($interface, 'execx'), $argv);
         if (idx($spec, 'default')) {
             $default = $directory;
         }
     }
     if ($default === null) {
         $default = head_key($map);
     }
     // TODO: Use working storage?
     $lease->setAttribute('workingcopy.default', "{$root}/repo/{$default}/");
     $lease->activateOnResource($resource);
 }
 public function activateLease(DrydockBlueprint $blueprint, DrydockResource $resource, DrydockLease $lease)
 {
     $command_type = DrydockCommandInterface::INTERFACE_TYPE;
     $interface = $lease->getInterface($command_type);
     $cmd = array();
     $arg = array();
     $cmd[] = 'git clean -d --force';
     $cmd[] = 'git reset --hard HEAD';
     $cmd[] = 'git fetch';
     $commit = $lease->getAttribute('commit');
     $branch = $lease->getAttribute('branch');
     if ($commit !== null) {
         $cmd[] = 'git reset --hard %s';
         $arg[] = $commit;
     } else {
         if ($branch !== null) {
             $cmd[] = 'git reset --hard %s';
             $arg[] = $branch;
         }
     }
     $cmd = implode(' && ', $cmd);
     $argv = array_merge(array($cmd), $arg);
     $result = call_user_func_array(array($interface, 'execx'), $argv);
     $lease->activateOnResource($resource);
 }