Passed
Push — master ( eabf33...342b63 )
by Michiel
05:53
created

HgPullTask::setTargetPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 <[email protected]>
10
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
11
 * @link     https://github.com/kenguest/Phing-HG
12
 */
13
14
use Phing\Exception\BuildException;
15
use Phing\Project;
16
17
/**
18
 * Integration/Wrapper for hg update
19
 *
20
 * @category Tasks
21
 * @package  phing.tasks.ext.hg
22
 * @author   Ken Guest <[email protected]>
23
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
24
 * @link     HgPullTask.php
25
 */
26
class HgPullTask extends HgBaseTask
27
{
28
    /**
29
     * Path to target directory
30
     *
31
     * @var string
32
     */
33
    protected $targetPath;
34
35
    /**
36
     * Set path to source repo
37
     *
38
     * @param string $targetPath Path to repository used as source
39
     *
40
     * @return void
41
     */
42
    public function setTargetPath($targetPath)
43
    {
44
        $this->targetPath = $targetPath;
45
    }
46
47
    /**
48
     * The main entry point method.
49
     *
50
     * @throws BuildException
51
     * @return void
52
     */
53 4
    public function main()
54
    {
55 4
        $clone = $this->getFactoryInstance('pull');
56 4
        $clone->setInsecure($this->getInsecure());
57 4
        $clone->setQuiet($this->getQuiet());
58
59 4
        $cwd = getcwd();
60
61 4
        if ($this->repository === '') {
62 2
            $project = $this->getProject();
63 2
            $dir = $project->getProperty('application.startdir');
64
        } else {
65 2
            $dir = $this->repository;
66
        }
67 4
        $this->checkRepositoryIsDirAndExists($dir);
68 2
        chdir($dir);
69
70
        try {
71 2
            $this->log("Executing: " . $clone->asString(), Project::MSG_INFO);
72 2
            $output = $clone->execute();
73
            if ($output !== '') {
74
                $this->log($output);
75
            }
76 2
        } catch (Exception $ex) {
77 2
            $msg = $ex->getMessage();
78 2
            $p = strpos($msg, 'hg returned:');
79 2
            if ($p !== false) {
80 2
                $msg = substr($msg, $p + 13);
81
            }
82 2
            chdir($cwd);
83 2
            throw new BuildException($msg);
84
        }
85
        chdir($cwd);
86
    }
87
}
88