Completed
Push — develop ( 5f7df1...9cb564 )
by Matteo
10s
created

RevListCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * GitElephant - An abstraction layer for git written in PHP
4
 * Copyright (C) 2013  Matteo Giachino
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
18
 */
19
20
namespace GitElephant\Command;
21
22
use \GitElephant\Objects\Tag;
23
use \GitElephant\Objects\Commit;
24
use \GitElephant\Repository;
25
26
/**
27
 * RevList Command generator
28
 *
29
 * @author Matteo Giachino <[email protected]>
30
 */
31
class RevListCommand extends BaseCommand
32
{
33
    const GIT_REVLIST = 'rev-list';
34
35
    /**
36
     * constructor
37
     *
38
     * @param \GitElephant\Repository $repo The repository object this command 
39
     *                                      will interact with
40
     */
41 29
    public function __construct(Repository $repo = null)
42
    {
43 29
        parent::__construct($repo);
44 29
    }
45
46
    /**
47
     * get tag commit command via rev-list
48
     *
49
     * @param \GitElephant\Objects\Tag $tag a tag instance
50
     *
51
     * @throws \RuntimeException
52
     * @return string
53
     */
54 26
    public function getTagCommit(Tag $tag)
55
    {
56 26
        $this->clearAll();
57 26
        $this->addCommandName(static::GIT_REVLIST);
58
        // only the last commit
59 26
        $this->addCommandArgument('-n1');
60 26
        $this->addCommandSubject($tag->getFullRef());
61
62 26
        return $this->getCommand();
63
    }
64
65
    /**
66
     * get the commits path to the passed commit. Useful to count commits in a repo
67
     *
68
     * @param \GitElephant\Objects\Commit $commit commit instance
69
     * @param int                         $max    max count
70
     *
71
     * @throws \RuntimeException
72
     * @return string
73
     */
74 3
    public function commitPath(Commit $commit, $max = 1000)
75
    {
76 3
        $this->clearAll();
77 3
        $this->addCommandName(static::GIT_REVLIST);
78 3
        $this->addCommandArgument(sprintf('--max-count=%s', $max));
79 3
        $this->addCommandSubject($commit->getSha());
80
81 3
        return $this->getCommand();
82
    }
83
}
84