Passed
Push — main ( 95b369...5c384e )
by Michiel
17:35 queued 12s
created

HgPushTask::setHaltonerror()   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
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Utilise Mercurial from within Phing.
5
 *
6
 * PHP Version 5.4
7
 *
8
 * @category Tasks
9
 * @package  phing.tasks.ext
10
 * @author   Ken Guest <[email protected]>
11
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
12
 * @link     https://github.com/kenguest/Phing-HG
13
 */
14
15
namespace Phing\Task\Ext;
16
17
use Phing\Exception\BuildException;
18
use Phing\Project;
19
use Phing\Util\StringHelper;
20
21
/**
22
 * Integration/Wrapper for hg push
23
 *
24
 * @category Tasks
25
 * @package  phing.tasks.ext.hg
26
 * @author   Ken Guest <[email protected]>
27
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
28
 * @link     HgPushTask.php
29
 */
30
class HgPushTask extends HgBaseTask
31
{
32
    /**
33
     * Whether the task should halt if an error occurs.
34
     *
35
     * @var bool
36
     */
37
    protected $haltonerror = false;
38
39
    /**
40
     * Set haltonerror attribute.
41
     *
42
     * @param string $halt 'yes', or '1' to halt.
43
     *
44
     * @return void
45
     */
46
    public function setHaltonerror($halt)
47
    {
48
        $this->haltonerror = StringHelper::booleanValue($halt);
49
    }
50
51
    /**
52
     * Return haltonerror value.
53
     *
54
     * @return bool
55
     */
56
    public function getHaltonerror()
57
    {
58
        return $this->haltonerror;
59
    }
60
61
    /**
62
     * The main entry point method.
63
     *
64
     * @throws BuildException
65
     * @return void
66
     */
67
    public function main()
68
    {
69
        $clone = $this->getFactoryInstance('push');
70
        $this->log('Pushing...', Project::MSG_INFO);
71
        $clone->setInsecure($this->getInsecure());
72
        $clone->setQuiet($this->getQuiet());
73
        if ($this->repository === '') {
74
            $project = $this->getProject();
75
            $dir = $project->getProperty('application.startdir');
76
        } else {
77
            $dir = $this->repository;
78
        }
79
        $cwd = getcwd();
80
        $this->checkRepositoryIsDirAndExists($dir);
81
        chdir($dir);
82
        try {
83
            $this->log("Executing: " . $clone->asString(), Project::MSG_INFO);
84
            $output = $clone->execute();
85
            if ($output !== '') {
86
                $this->log($output);
87
            }
88
        } catch (\Exception $ex) {
89
            $msg = $ex->getMessage();
90
            $p = strpos($msg, 'hg returned:');
91
            if ($p !== false) {
92
                $msg = substr($msg, $p + 13);
93
            }
94
            chdir($cwd);
95
            if ($this->haltonerror) {
96
                throw new BuildException($msg);
97
            }
98
            $this->log($msg, Project::MSG_ERR);
99
        }
100
        chdir($cwd);
101
    }
102
}
103