[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DifferentialLandingToHostedGit 4 extends DifferentialLandingStrategy { 5 6 public function processLandRequest( 7 AphrontRequest $request, 8 DifferentialRevision $revision, 9 PhabricatorRepository $repository) { 10 11 $viewer = $request->getUser(); 12 13 $workspace = $this->getGitWorkspace($repository); 14 15 try { 16 $this->commitRevisionToWorkspace( 17 $revision, 18 $workspace, 19 $viewer); 20 } catch (Exception $e) { 21 throw new PhutilProxyException( 22 'Failed to commit patch', 23 $e); 24 } 25 26 try { 27 $this->pushWorkspaceRepository( 28 $repository, 29 $workspace, 30 $viewer); 31 } catch (Exception $e) { 32 throw new PhutilProxyException( 33 'Failed to push changes upstream', 34 $e); 35 } 36 } 37 38 public function commitRevisionToWorkspace( 39 DifferentialRevision $revision, 40 ArcanistRepositoryAPI $workspace, 41 PhabricatorUser $user) { 42 43 $diff_id = $revision->loadActiveDiff()->getID(); 44 45 $call = new ConduitCall( 46 'differential.getrawdiff', 47 array( 48 'diffID' => $diff_id, 49 )); 50 51 $call->setUser($user); 52 $raw_diff = $call->execute(); 53 54 $missing_binary = 55 "\nindex " 56 ."0000000000000000000000000000000000000000.." 57 ."0000000000000000000000000000000000000000\n"; 58 if (strpos($raw_diff, $missing_binary) !== false) { 59 throw new Exception('Patch is missing content for a binary file'); 60 } 61 62 $future = $workspace->execFutureLocal('apply --index -'); 63 $future->write($raw_diff); 64 $future->resolvex(); 65 66 $workspace->reloadWorkingCopy(); 67 68 $call = new ConduitCall( 69 'differential.getcommitmessage', 70 array( 71 'revision_id' => $revision->getID(), 72 )); 73 74 $call->setUser($user); 75 $message = $call->execute(); 76 77 $author = id(new PhabricatorUser())->loadOneWhere( 78 'phid = %s', 79 $revision->getAuthorPHID()); 80 81 $author_string = sprintf( 82 '%s <%s>', 83 $author->getRealName(), 84 $author->loadPrimaryEmailAddress()); 85 $author_date = $revision->getDateCreated(); 86 87 $workspace->execxLocal( 88 '-c user.name=%s -c user.email=%s '. 89 'commit --date=%s --author=%s '. 90 '--message=%s', 91 // -c will set the 'committer' 92 $user->getRealName(), 93 $user->loadPrimaryEmailAddress(), 94 $author_date, 95 $author_string, 96 $message); 97 } 98 99 100 public function pushWorkspaceRepository( 101 PhabricatorRepository $repository, 102 ArcanistRepositoryAPI $workspace, 103 PhabricatorUser $user) { 104 105 $workspace->execxLocal('push origin HEAD:master'); 106 } 107 108 public function createMenuItem( 109 PhabricatorUser $viewer, 110 DifferentialRevision $revision, 111 PhabricatorRepository $repository) { 112 113 $vcs = $repository->getVersionControlSystem(); 114 if ($vcs !== PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) { 115 return; 116 } 117 118 if (!$repository->isHosted()) { 119 return; 120 } 121 122 if (!$repository->isWorkingCopyBare()) { 123 return; 124 } 125 126 // TODO: This temporarily disables this action, because it doesn't work 127 // and is confusing to users. If you want to use it, comment out this line 128 // for now and we'll provide real support eventually. 129 return; 130 131 return $this->createActionView( 132 $revision, 133 pht('Land to Hosted Repository')); 134 } 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |