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 init
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     HgInitTask.php
22
 */
23
class HgInitTask 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 0
    public function setTargetPath($targetPath)
40
    {
41 0
        $this->targetPath = $targetPath;
42
    }
43

44
    /**
45
     * Main entry point for this task.
46
     *
47
     * @return void
48
     */
49 1
    public function main()
50
    {
51 1
        $clone = $this->getFactoryInstance('init');
52 1
        $this->log('Initializing', Project::MSG_INFO);
53 1
        $clone->setQuiet($this->getQuiet());
54 1
        $clone->setInsecure($this->getInsecure());
55 1
        $cwd = getcwd();
56 1
        if ($this->repository === '') {
57 0
            $project = $this->getProject();
58 0
            $dir = $project->getProperty('application.startdir');
59
        } else {
60 1
            $dir = $this->repository;
61
        }
62 1
        if (!is_dir($dir)) {
63 1
            throw new BuildException("$dir is not a directory.");
64
        }
65 1
        chdir($dir);
66
        try {
67 1
            $this->log("Executing: " . $clone->asString(), Project::MSG_INFO);
68 1
            $output = $clone->execute();
69 1
            if ($output !== '') {
70 0
                $this->log($output);
71
            }
72 0
        } catch (Exception $ex) {
73 0
            $msg = $ex->getMessage();
74 0
            $p = strpos($msg, 'hg returned:');
75 0
            if ($p !== false) {
76 0
                $msg = substr($msg, $p + 13);
77
            }
78 0
            chdir($cwd);
79 0
            throw new BuildException($msg);
80
        }
81 1
        chdir($cwd);
82
    }
83
}

Read our documentation on viewing source code .

Loading