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 aroung git-log
22
 *
23
 * @author  Evan Kaufman <evan@digitalflophouse.com>
24
 * @author  Victor Farazdagi <simple.square@gmail.com>
25
 * @package phing.tasks.ext.git
26
 * @see     VersionControl_Git
27
 * @since   2.4.5
28
 */
29
class GitLogTask extends GitBaseTask
30
{
31
    /**
32
     * Generate a diffstat. See --stat of git-log
33
     *
34
     * @var string|boolean
35
     */
36
    private $stat = false;
37

38
    /**
39
     * Names + status of changed files. See --name-status of git-log
40
     *
41
     * @var boolean
42
     */
43
    private $nameStatus = false;
44

45
    /**
46
     * Number of commits to show. See -<n>|-n|--max-count of git-log
47
     *
48
     * @var integer
49
     */
50
    private $maxCount;
51

52
    /**
53
     * Don't show commits with more than one parent. See --no-merges of git-log
54
     *
55
     * @var boolean
56
     */
57
    private $noMerges = false;
58

59
    /**
60
     * Commit format. See --format of git-log
61
     *
62
     * @var string
63
     */
64
    private $format = 'medium';
65

66
    /**
67
     * Date format. See --date of git-log
68
     *
69
     * @var string
70
     */
71
    private $date;
72

73
    /**
74
     * <since> argument to git-log
75
     *
76
     * @var string
77
     */
78
    private $since;
79

80
    /**
81
     * <until> argument to git-log
82
     *
83
     * @var string
84
     */
85
    private $until;
86

87
    /**
88
     * <path> arguments to git-log
89
     * Accepts one or more paths delimited by PATH_SEPARATOR
90
     *
91
     * @var string
92
     */
93
    private $paths;
94

95
    /**
96
     * Property name to set with output value from git-log
97
     *
98
     * @var string
99
     */
100
    private $outputProperty;
101

102
    /**
103
     * The main entry point for the task
104
     */
105 1
    public function main()
106
    {
107 1
        if (null === $this->getRepository()) {
108 1
            throw new BuildException('"repository" is required parameter');
109
        }
110

111 1
        $client = $this->getGitClient(false, $this->getRepository());
112 1
        $command = $client->getCommand('log');
113
        $command
114 1
            ->setOption('stat', $this->getStat())
115 1
            ->setOption('name-status', $this->isNameStatus())
116 1
            ->setOption('no-merges', $this->isNoMerges())
117 1
            ->setOption('format', $this->getFormat());
118

119 1
        if (null !== $this->getMaxCount()) {
120 1
            $command->setOption('max-count', $this->getMaxCount());
121
        }
122

123 1
        if (null !== $this->getDate()) {
124 0
            $command->setOption('date', $this->getDate());
125
        }
126

127 1
        if (null !== $this->getSince()) {
128 1
            $command->setOption('since', $this->getSince());
129
        }
130

131 1
        if (null !== $this->getUntil()) {
132 1
            $command->setOption('until', $this->getUntil());
133
        }
134

135 1
        $command->addDoubleDash(true);
136 1
        if (null !== $this->getPaths()) {
137 1
            $command->addDoubleDash(false);
138 1
            $paths = explode(PATH_SEPARATOR, $this->getPaths());
139 1
            foreach ($paths as $path) {
140 1
                $command->addArgument($path);
141
            }
142
        }
143

144 1
        $this->log('git-log command: ' . $command->createCommandString(), Project::MSG_INFO);
145

146
        try {
147 1
            $output = $command->execute();
148 0
        } catch (Exception $e) {
149 0
            throw new BuildException('Task execution failed', $e);
150
        }
151

152 1
        if (null !== $this->outputProperty) {
153 1
            $this->project->setProperty($this->outputProperty, trim($output));
154
        }
155

156 1
        $this->log(
157 1
            sprintf('git-log: commit log for "%s" repository', $this->getRepository()),
158 1
            Project::MSG_INFO
159
        );
160 1
        $this->log('git-log output: ' . trim($output), Project::MSG_INFO);
161
    }
162

163
    /**
164
     * @param $stat
165
     */
166 1
    public function setStat($stat)
167
    {
168 1
        $this->stat = $stat;
169
    }
170

171
    /**
172
     * @return bool|string
173
     */
174 1
    public function getStat()
175
    {
176 1
        return $this->stat;
177
    }
178

179
    /**
180
     * @param $flag
181
     */
182 1
    public function setNameStatus($flag)
183
    {
184 1
        $this->nameStatus = (bool) $flag;
185
    }
186

187
    /**
188
     * @return bool
189
     */
190 1
    public function getNameStatus()
191
    {
192 1
        return $this->nameStatus;
193
    }
194

195
    /**
196
     * @return bool
197
     */
198 1
    public function isNameStatus()
199
    {
200 1
        return $this->getNameStatus();
201
    }
202

203
    /**
204
     * @param $count
205
     */
206 1
    public function setMaxCount($count)
207
    {
208 1
        $this->maxCount = (int) $count;
209
    }
210

211
    /**
212
     * @return int
213
     */
214 1
    public function getMaxCount()
215
    {
216 1
        return $this->maxCount;
217
    }
218

219
    /**
220
     * @param $flag
221
     */
222 1
    public function setNoMerges(bool $flag)
223
    {
224 1
        $this->noMerges = $flag;
225
    }
226

227
    /**
228
     * @return bool
229
     */
230 1
    public function getNoMerges()
231
    {
232 1
        return $this->noMerges;
233
    }
234

235
    /**
236
     * @return bool
237
     */
238 1
    public function isNoMerges()
239
    {
240 1
        return $this->getNoMerges();
241
    }
242

243
    /**
244
     * @param $format
245
     */
246 1
    public function setFormat($format)
247
    {
248 1
        $this->format = $format;
249
    }
250

251
    /**
252
     * @return string
253
     */
254 1
    public function getFormat()
255
    {
256 1
        return $this->format;
257
    }
258

259
    /**
260
     * @param $date
261
     */
262 0
    public function setDate($date)
263
    {
264 0
        $this->date = $date;
265
    }
266

267
    /**
268
     * @return string
269
     */
270 1
    public function getDate()
271
    {
272 1
        return $this->date;
273
    }
274

275
    /**
276
     * @param $since
277
     */
278 1
    public function setSince($since)
279
    {
280 1
        $this->since = $since;
281
    }
282

283
    /**
284
     * @return string
285
     */
286 1
    public function getSince()
287
    {
288 1
        return $this->since;
289
    }
290

291
    /**
292
     * @param $after
293
     */
294 1
    public function setAfter($after)
295
    {
296 1
        $this->setSince($after);
297
    }
298

299
    /**
300
     * @param $until
301
     */
302 1
    public function setUntil($until)
303
    {
304 1
        $this->until = $until;
305
    }
306

307
    /**
308
     * @return string
309
     */
310 1
    public function getUntil()
311
    {
312 1
        return $this->until;
313
    }
314

315
    /**
316
     * @param $before
317
     */
318 1
    public function setBefore($before)
319
    {
320 1
        $this->setUntil($before);
321
    }
322

323
    /**
324
     * @param $paths
325
     */
326 1
    public function setPaths($paths)
327
    {
328 1
        $this->paths = $paths;
329
    }
330

331
    /**
332
     * @return string
333
     */
334 1
    public function getPaths()
335
    {
336 1
        return $this->paths;
337
    }
338

339
    /**
340
     * @param $prop
341
     */
342 1
    public function setOutputProperty($prop)
343
    {
344 1
        $this->outputProperty = $prop;
345
    }
346
}

Read our documentation on viewing source code .

Loading