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