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 update
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     HgUpdateTask.php
22
 */
23
class HgUpdateTask extends HgBaseTask
24
{
25
    /**
26
     * Branch argument
27
     *
28
     * Defaults to 'default'
29
     *
30
     * @var string
31
     */
32
    protected $branch = 'default';
33

34
    /**
35
     * Clean argument
36
     *
37
     * @var bool
38
     */
39
    protected $clean = false;
40

41
    /**
42
     * Set 'clean' attribute.
43
     *
44
     * @param string $value Clean attribute value
45
     *
46
     * @return void
47
     */
48 0
    public function setClean($value)
49
    {
50 0
        $this->clean = StringHelper::booleanValue($value);
51
    }
52

53
    /**
54
     * Get 'clean' attribute.
55
     *
56
     * @return bool
57
     */
58 1
    public function getClean()
59
    {
60 1
        return $this->clean;
61
    }
62

63
    /**
64
     * Set branch attribute
65
     *
66
     * @param string $value Branch name
67
     *
68
     * @return void
69
     */
70 0
    public function setBranch($value)
71
    {
72 0
        $this->branch = $value;
73
    }
74

75
    /**
76
     * Get branch attribute
77
     *
78
     * @return string
79
     */
80 1
    public function getBranch()
81
    {
82 1
        return $this->branch;
83
    }
84

85
    /**
86
     * The main entry point method.
87
     *
88
     * @throws BuildException
89
     * @return void
90
     */
91 1
    public function main()
92
    {
93 1
        $pull = $this->getFactoryInstance('update');
94
        try {
95 1
            $pull->setBranch($this->getBranch());
96 0
        } catch (Exception $ex) {
97 0
            $this->log("Caught: " . $ex->getMessage(), Project::MSG_DEBUG);
98
        }
99 1
        $pull->setClean($this->getClean());
100 1
        $pull->setQuiet($this->getQuiet());
101

102 1
        $cwd = getcwd();
103

104 1
        if ($this->repository === '') {
105 1
            $prog = $this->getProject();
106 1
            $dir = $prog->getProperty('application.startdir');
107
        } else {
108 1
            $dir = $this->repository;
109
        }
110

111 1
        $this->checkRepositoryIsDirAndExists($dir);
112 1
        chdir($dir);
113
        try {
114 1
            $this->log("Executing: " . $pull->asString(), Project::MSG_INFO);
115 1
            $output = $pull->execute();
116 0
            if ($output !== '') {
117 0
                $this->log($output);
118
            }
119 1
        } catch (Exception $ex) {
120 1
            $msg = $ex->getMessage();
121 1
            $p = strpos($msg, 'hg returned:');
122 1
            if ($p !== false) {
123 1
                $msg = substr($msg, $p + 13);
124
            }
125 1
            chdir($cwd);
126 1
            throw new BuildException($msg);
127
        }
128 0
        chdir($cwd);
129
    }
130
}

Read our documentation on viewing source code .

Loading