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 push
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     HgPushTask.php
22
 */
23
class HgPushTask extends HgBaseTask
24
{
25
    /**
26
     * Whether the task should halt if an error occurs.
27
     *
28
     * @var bool
29
     */
30
    protected $haltonerror = false;
31

32
    /**
33
     * Set haltonerror attribute.
34
     *
35
     * @param string $halt 'yes', or '1' to halt.
36
     *
37
     * @return void
38
     */
39 0
    public function setHaltonerror($halt)
40
    {
41 0
        $this->haltonerror = StringHelper::booleanValue($halt);
42
    }
43

44
    /**
45
     * Return haltonerror value.
46
     *
47
     * @return bool
48
     */
49 0
    public function getHaltonerror()
50
    {
51 0
        return $this->haltonerror;
52
    }
53

54
    /**
55
     * The main entry point method.
56
     *
57
     * @throws BuildException
58
     * @return void
59
     */
60 0
    public function main()
61
    {
62 0
        $clone = $this->getFactoryInstance('push');
63 0
        $this->log('Pushing...', Project::MSG_INFO);
64 0
        $clone->setInsecure($this->getInsecure());
65 0
        $clone->setQuiet($this->getQuiet());
66 0
        if ($this->repository === '') {
67 0
            $project = $this->getProject();
68 0
            $dir = $project->getProperty('application.startdir');
69
        } else {
70 0
            $dir = $this->repository;
71
        }
72 0
        $cwd = getcwd();
73 0
        $this->checkRepositoryIsDirAndExists($dir);
74 0
        chdir($dir);
75
        try {
76 0
            $this->log("Executing: " . $clone->asString(), Project::MSG_INFO);
77 0
            $output = $clone->execute();
78 0
            if ($output !== '') {
79 0
                $this->log($output);
80
            }
81 0
        } catch (Exception $ex) {
82 0
            $msg = $ex->getMessage();
83 0
            $p = strpos($msg, 'hg returned:');
84 0
            if ($p !== false) {
85 0
                $msg = substr($msg, $p + 13);
86
            }
87 0
            chdir($cwd);
88 0
            if ($this->haltonerror) {
89 0
                throw new BuildException($msg);
90
            }
91 0
            $this->log($msg, Project::MSG_ERR);
92
        }
93 0
        chdir($cwd);
94
    }
95
}

Read our documentation on viewing source code .

Loading