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 commit
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     HgCommitTask.php
22
 */
23
class HgCommitTask extends HgBaseTask
24
{
25
    /**
26
     * Message to be recorded against commit.
27
     *
28
     * @var string
29
     */
30
    protected $message = '';
31

32
    /**
33
     * Set message to be used.
34
     *
35
     * @param string $message Message to use
36
     *
37
     * @return void
38
     */
39 1
    public function setMessage($message)
40
    {
41 1
        $this->message = $message;
42
    }
43

44
    /**
45
     * Get message to apply for the commit.
46
     *
47
     * @return string
48
     */
49 1
    public function getMessage()
50
    {
51 1
        return $this->message;
52
    }
53

54
    /**
55
     * The main entry point method.
56
     *
57
     * @throws BuildException If message is not set
58
     * @throws BuildException If error occurs during commit
59
     * @return void
60
     */
61 1
    public function main()
62
    {
63 1
        $message = $this->getMessage();
64 1
        if ($message === '') {
65 1
            throw new BuildException('"message" is a required parameter');
66
        }
67

68 1
        $user = $this->getUser();
69

70 1
        $clone = $this->getFactoryInstance('commit');
71 1
        $msg = sprintf("Commit: '%s'", $message);
72 1
        $this->log($msg, Project::MSG_INFO);
73 1
        $clone->setQuiet($this->getQuiet());
74 1
        $clone->setMessage($message);
75

76 1
        if (trim($user) === "") {
77 1
            throw new BuildException('"user" parameter can not be set to ""');
78
        }
79 0
        if ($user !== null) {
80 0
            $clone->setUser($user);
81 0
            $this->log("Commit: user = '$user'", Project::MSG_VERBOSE);
82
        }
83

84 0
        if ($this->repository === '') {
85 0
            $project = $this->getProject();
86 0
            $dir = $project->getProperty('application.startdir');
87
        } else {
88 0
            $dir = $this->repository;
89
        }
90 0
        $this->log('DIR:' . $dir, Project::MSG_INFO);
91 0
        $this->log('REPO: ' . $this->repository, Project::MSG_INFO);
92 0
        $cwd = getcwd();
93 0
        chdir($dir);
94

95
        try {
96 0
            $this->log("Executing: " . $clone->asString(), Project::MSG_INFO);
97 0
            $output = $clone->execute();
98 0
            if ($output !== '') {
99 0
                $this->log($output);
100
            }
101 0
        } catch (Exception $ex) {
102 0
            $msg = $ex->getMessage();
103 0
            $this->log("Exception: $msg", Project::MSG_INFO);
104 0
            $p = strpos($msg, 'hg returned:');
105 0
            if ($p !== false) {
106 0
                $msg = substr($msg, $p + 13);
107
            }
108 0
            chdir($cwd);
109 0
            throw new BuildException($msg);
110
        }
111 0
        chdir($cwd);
112
    }
113
}

Read our documentation on viewing source code .

Loading