Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
<?php
|
|
2 |
/**
|
|
3 |
* Utilise Mercurial from within Phing.
|
|
4 |
*
|
|
5 |
* PHP Version 5.4
|
|
6 |
*
|
|
7 |
* @category Tasks
|
|
8 |
* @package phing.tasks.ext
|
|
9 |
* @author Ken Guest <kguest@php.net>
|
|
10 |
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html)
|
|
11 |
* @link https://github.com/kenguest/Phing-HG
|
|
12 |
*/
|
|
13 |
|
|
14 |
/**
|
|
15 |
* Integration/Wrapper for hg clone
|
|
16 |
*
|
|
17 |
* @category Tasks
|
|
18 |
* @package phing.tasks.ext.hg
|
|
19 |
* @author Ken Guest <kguest@php.net>
|
|
20 |
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html)
|
|
21 |
* @link HgCloneTask.php
|
|
22 |
*/
|
|
23 |
class HgCloneTask extends HgBaseTask |
|
24 |
{
|
|
25 |
/**
|
|
26 |
* Path to target directory
|
|
27 |
*
|
|
28 |
* @var string
|
|
29 |
*/
|
|
30 |
protected $targetPath = ''; |
|
31 |
|
|
32 |
/**
|
|
33 |
* Set path to source repo
|
|
34 |
*
|
|
35 |
* @param string $targetPath Path to repository used as source
|
|
36 |
*
|
|
37 |
* @return void
|
|
38 |
*/
|
|
39 | 1 |
public function setTargetPath($targetPath) |
40 |
{
|
|
41 | 1 |
$this->targetPath = $targetPath; |
42 |
}
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Get path to the target directory/repo.
|
|
46 |
*
|
|
47 |
* @return string
|
|
48 |
*/
|
|
49 | 1 |
public function getTargetPath() |
50 |
{
|
|
51 | 1 |
return $this->targetPath; |
52 |
}
|
|
53 |
|
|
54 |
/**
|
|
55 |
* The main entry point.
|
|
56 |
*
|
|
57 |
* @return void
|
|
58 |
* @throws BuildException
|
|
59 |
*/
|
|
60 | 1 |
public function main() |
61 |
{
|
|
62 | 1 |
$clone = $this->getFactoryInstance('clone'); |
63 | 1 |
$repository = $this->getRepository(); |
64 | 1 |
if ($repository === '') { |
65 | 1 |
throw new BuildException('"repository" is a required parameter'); |
66 |
}
|
|
67 | 1 |
$target = $this->getTargetPath(); |
68 | 1 |
if ($target === '') { |
69 | 1 |
throw new BuildException('"targetPath" is a required parameter'); |
70 |
}
|
|
71 |
// Is target path empty?
|
|
72 | 1 |
if (file_exists($target)) { |
73 |
$files = scandir($target); |
|
74 |
if (is_array($files) && count($files) > 2) { |
|
75 |
throw new BuildException("Directory \"$target\" is not empty"); |
|
76 |
}
|
|
77 |
if (!is_dir($target)) { |
|
78 |
throw new BuildException("\"$target\" is not a directory"); |
|
79 |
}
|
|
80 |
}
|
|
81 | 1 |
$msg = sprintf('hg cloning %s to %s', $repository, $target); |
82 | 1 |
$this->log($msg, Project::MSG_INFO); |
83 | 1 |
$clone->setSource($repository); |
84 | 1 |
$clone->setDestination($target); |
85 | 1 |
$clone->setInsecure($this->getInsecure()); |
86 | 1 |
$clone->setQuiet($this->getQuiet()); |
87 |
try {
|
|
88 | 1 |
$this->log("Executing: " . $clone->asString(), Project::MSG_INFO); |
89 | 1 |
$output = $clone->execute(); |
90 |
if ($output !== '') { |
|
91 |
$this->log($output); |
|
92 |
}
|
|
93 | 1 |
} catch (Exception $ex) { |
94 | 1 |
$msg = $ex->getMessage(); |
95 | 1 |
$p = strpos($msg, 'hg returned:'); |
96 | 1 |
if ($p !== false) { |
97 | 1 |
$msg = substr($msg, $p + 13); |
98 |
}
|
|
99 | 1 |
throw new BuildException($msg); |
100 |
}
|
|
101 |
}
|
|
102 |
}
|
Read our documentation on viewing source code .