@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DiffusionCloneController extends DiffusionController {
4
5 public function shouldAllowPublic() {
6 return true;
7 }
8
9 public function handleRequest(AphrontRequest $request) {
10 $viewer = $request->getViewer();
11 $response = $this->loadDiffusionContext();
12 if ($response) {
13 return $response;
14 }
15
16 $drequest = $this->getDiffusionRequest();
17 $repository = $drequest->getRepository();
18
19 $view = id(new PHUIPropertyListView())
20 ->setUser($viewer);
21
22 $display_never = PhabricatorRepositoryURI::DISPLAY_NEVER;
23 $warning = null;
24
25 $uris = $repository->getURIs();
26 foreach ($uris as $uri) {
27 if ($uri->getIsDisabled()) {
28 continue;
29 }
30
31 if ($uri->getEffectiveDisplayType() == $display_never) {
32 continue;
33 }
34
35 if ($repository->isSVN()) {
36 $label = phutil_tag_div('diffusion-clone-label', pht('Checkout'));
37 } else {
38 $label = phutil_tag_div('diffusion-clone-label', pht('Clone'));
39 }
40
41 $view->addProperty(
42 $label,
43 $this->renderCloneURI($repository, $uri));
44 }
45
46 if (!$view->hasAnyProperties()) {
47 $view = id(new PHUIInfoView())
48 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
49 ->appendChild(pht('Repository has no URIs set.'));
50 }
51
52 // Try to load alternatives. This may fail for repositories which have not
53 // cloned yet. If it does, just ignore it and continue.
54 try {
55 $alternatives = $drequest->getRefAlternatives();
56 } catch (ConduitClientException $ex) {
57 $alternatives = array();
58 }
59
60 if ($alternatives) {
61 $message = array(
62 pht(
63 'The ref "%s" is ambiguous in this repository.',
64 $drequest->getBranch()),
65 ' ',
66 phutil_tag(
67 'a',
68 array(
69 'href' => $drequest->generateURI(
70 array(
71 'action' => 'refs',
72 )),
73 ),
74 pht('View Alternatives')),
75 );
76
77 $messages = array($message);
78
79 $warning = id(new PHUIInfoView())
80 ->setSeverity(PHUIInfoView::SEVERITY_WARNING)
81 ->setErrors(array($message));
82 }
83
84 $cancel_uri = $drequest->generateURI(
85 array(
86 'action' => 'branch',
87 'path' => '/',
88 ));
89
90 return $this->newDialog()
91 ->setTitle(pht('Clone Repository'))
92 ->setWidth(AphrontDialogView::WIDTH_FORM)
93 ->addCancelButton($cancel_uri, pht('Close'))
94 ->appendChild(array($view, $warning));
95 }
96
97 private function renderCloneURI(
98 PhabricatorRepository $repository,
99 PhabricatorRepositoryURI $uri) {
100
101 if ($repository->isSVN()) {
102 $display = csprintf(
103 'svn checkout %R %R',
104 (string)$uri->getDisplayURI(),
105 $repository->getCloneName());
106 } else {
107 $display = csprintf('%R', (string)$uri->getDisplayURI());
108 }
109
110 $display = (string)$display;
111 $viewer = $this->getViewer();
112
113 return id(new DiffusionCloneURIView())
114 ->setViewer($viewer)
115 ->setRepository($repository)
116 ->setRepositoryURI($uri)
117 ->setDisplayURI($display);
118 }
119
120}