1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
/**
21
 * Wrapper around git-commit
22
 *
23
 * @package phing.tasks.ext.git
24
 * @author  Jonathan Creasy <jonathan.creasy@gmail.com>
25
 * @see     VersionControl_Git
26
 * @since   2.4.3
27
 */
28
class GitCommitTask extends GitBaseTask
29
{
30
    use FileSetAware;
31

32
    /**
33
     * @var boolean
34
     */
35
    private $allFiles = false;
36

37
    /**
38
     * @var string
39
     */
40
    private $message;
41

42
    /**
43
     * The main entry point for the task
44
     */
45 0
    public function main()
46
    {
47 0
        if (null === $this->getRepository()) {
48 0
            throw new BuildException('"repository" is required parameter');
49
        }
50

51 0
        if ($this->allFiles !== true && empty($this->filesets)) {
52 0
            throw new BuildException('"allFiles" cannot be false if no filesets are specified.');
53
        }
54

55 0
        $options = [];
56 0
        if ($this->allFiles === true) {
57 0
            $options['all'] = true;
58
        }
59

60 0
        $arguments = [];
61 0
        if ($this->allFiles !== true) {
62 0
            foreach ($this->filesets as $fs) {
63 0
                $ds = $fs->getDirectoryScanner($this->project);
64 0
                $srcFiles = $ds->getIncludedFiles();
65

66 0
                foreach ($srcFiles as $file) {
67 0
                    $arguments[] = $file;
68
                }
69
            }
70
        }
71

72 0
        if (!empty($this->message)) {
73 0
            $options['message'] = $this->message;
74
        } else {
75 0
            $options['allow-empty-message'] = true;
76
        }
77

78
        try {
79 0
            $client = $this->getGitClient(false, $this->getRepository());
80

81 0
            $command = $client->getCommand('commit');
82 0
            $command->setArguments($arguments);
83 0
            $command->setOptions($options);
84 0
            $command->execute();
85 0
        } catch (Exception $e) {
86 0
            throw new BuildException('The remote end hung up unexpectedly', $e);
87
        }
88

89 0
        $this->logCommand($options, $arguments);
90
    }
91

92
    /**
93
     * @param array $options
94
     * @param array $arguments
95
     */
96 0
    protected function logCommand(array $options, array $arguments)
97
    {
98 0
        $msg = 'git-commit: Executed git commit ';
99 0
        foreach ($options as $option => $value) {
100 0
            $msg .= ' --' . $option . '=' . $value;
101
        }
102

103 0
        foreach ($arguments as $argument) {
104 0
            $msg .= ' ' . $argument;
105
        }
106

107 0
        $this->log($msg, Project::MSG_INFO);
108
    }
109

110
    /**
111
     * @return bool
112
     */
113 0
    public function getAllFiles()
114
    {
115 0
        return $this->allFiles;
116
    }
117

118
    /**
119
     * @param $flag
120
     */
121 0
    public function setAllFiles(bool $flag)
122
    {
123 0
        $this->allFiles = $flag;
124
    }
125

126
    /**
127
     * @return string
128
     */
129 0
    public function getMessage()
130
    {
131 0
        return $this->message;
132
    }
133

134
    /**
135
     * @param $message
136
     */
137 0
    public function setMessage($message)
138
    {
139 0
        $this->message = $message;
140
    }
141
}

Read our documentation on viewing source code .

Loading