public function applyOperation(DrydockRepositoryOperation $operation, DrydockInterface $interface)
 {
     $viewer = $this->getViewer();
     $repository = $operation->getRepository();
     $cmd = array();
     $arg = array();
     $object = $operation->getObject();
     if ($object instanceof DifferentialRevision) {
         $revision = $object;
         $diff = $this->loadDiff($operation);
         $dict = $diff->getDiffAuthorshipDict();
         $author_name = idx($dict, 'authorName');
         $author_email = idx($dict, 'authorEmail');
         $api_method = 'differential.getcommitmessage';
         $api_params = array('revision_id' => $revision->getID());
         $commit_message = id(new ConduitCall($api_method, $api_params))->setUser($viewer)->execute();
     } else {
         throw new Exception(pht('Invalid or unknown object ("%s") for land operation, expected ' . 'Differential Revision.', $operation->getObjectPHID()));
     }
     $target = $operation->getRepositoryTarget();
     list($type, $name) = explode(':', $target, 2);
     switch ($type) {
         case 'branch':
             $push_dst = 'refs/heads/' . $name;
             break;
         default:
             throw new Exception(pht('Unknown repository operation target type "%s" (in target "%s").', $type, $target));
     }
     $committer_info = $this->getCommitterInfo($operation);
     // NOTE: We're doing this commit with "-F -" so we don't run into trouble
     // with enormous commit messages which might otherwise exceed the maximum
     // size of a command.
     $future = $interface->getExecFuture('git -c user.name=%s -c user.email=%s commit --author %s -F - --', $committer_info['name'], $committer_info['email'], "{$author_name} <{$author_email}>");
     $future->write($commit_message);
     try {
         $future->resolvex();
     } catch (CommandException $ex) {
         $display_command = csprintf('git commit');
         // TODO: One reason this can fail is if the changes have already been
         // merged. We could try to detect that.
         $error = DrydockCommandError::newFromCommandException($ex)->setPhase(self::PHASE_COMMIT)->setDisplayCommand($display_command);
         $operation->setCommandError($error->toDictionary());
         throw $ex;
     }
     try {
         $interface->execx('git push origin -- %s:%s', 'HEAD', $push_dst);
     } catch (CommandException $ex) {
         $display_command = csprintf('git push origin %R:%R', 'HEAD', $push_dst);
         $error = DrydockCommandError::newFromCommandException($ex)->setPhase(self::PHASE_PUSH)->setDisplayCommand($display_command);
         $operation->setCommandError($error->toDictionary());
         throw $ex;
     }
 }
 private function applyMerge(DrydockLease $lease, 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);
     // NOTE: This can never actually generate a commit because we pass
     // "--squash", but git sometimes runs code to check that a username and
     // email are configured anyway.
     $real_command = csprintf('git -c user.name=%s -c user.email=%s merge --no-stat --squash -- %R', 'drydock', 'drydock@phabricator', $src_ref);
     // Show the user a simplified command if the operation fails and we need to
     // report an error.
     $show_command = csprintf('git merge --squash -- %R', $src_ref);
     try {
         $interface->execx('%C', $real_command);
     } catch (CommandException $ex) {
         $error = DrydockCommandError::newFromCommandException(self::PHASE_SQUASHMERGE, $show_command, $ex);
         $lease->setAttribute('workingcopy.vcs.error', $error);
         throw $ex;
     }
 }
 private function applyMerge(DrydockLease $lease, DrydockCommandInterface $interface, array $merge)
 {
     $src_uri = $merge['src.uri'];
     $src_ref = $merge['src.ref'];
     try {
         $interface->execx('git fetch --no-tags -- %s +%s:%s', $src_uri, $src_ref, $src_ref);
     } catch (CommandException $ex) {
         $display_command = csprintf('git fetch %R +%R:%R', $src_uri, $src_ref, $src_ref);
         $error = DrydockCommandError::newFromCommandException($ex)->setPhase(self::PHASE_MERGEFETCH)->setDisplayCommand($display_command);
         $lease->setAttribute('workingcopy.vcs.error', $error->toDictionary());
         throw $ex;
     }
     // NOTE: This can never actually generate a commit because we pass
     // "--squash", but git sometimes runs code to check that a username and
     // email are configured anyway.
     $real_command = csprintf('git -c user.name=%s -c user.email=%s merge --no-stat --squash -- %R', 'drydock', 'drydock@phabricator', $src_ref);
     try {
         $interface->execx('%C', $real_command);
     } catch (CommandException $ex) {
         $display_command = csprintf('git merge --squash %R', $src_ref);
         $error = DrydockCommandError::newFromCommandException($ex)->setPhase(self::PHASE_SQUASHMERGE)->setDisplayCommand($display_command);
         $lease->setAttribute('workingcopy.vcs.error', $error->toDictionary());
         throw $ex;
     }
 }