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-gc
22
 *
23
 * @author  Victor Farazdagi <simple.square@gmail.com>
24
 * @package phing.tasks.ext.git
25
 * @see     VersionControl_Git
26
 * @since   2.4.3
27
 */
28
class GitGcTask extends GitBaseTask
29
{
30
    /**
31
     * --aggressive key to git-gc
32
     *
33
     * @var boolean
34
     */
35
    private $isAggressive = false;
36

37
    /**
38
     * --auto key to git-gc
39
     *
40
     * @var boolean
41
     */
42
    private $isAuto = false;
43

44
    /**
45
     * --no-prune key to git-gc
46
     *
47
     * @var boolean
48
     */
49
    private $noPrune = false;
50

51
    /**
52
     * --prune=<date>option of git-gc
53
     *
54
     * @var string
55
     */
56
    private $prune = '2.weeks.ago';
57

58
    /**
59
     * The main entry point for the task
60
     */
61 1
    public function main()
62
    {
63 1
        if (null === $this->getRepository()) {
64 1
            throw new BuildException('"repository" is required parameter');
65
        }
66

67 1
        $client = $this->getGitClient(false, $this->getRepository());
68 1
        $command = $client->getCommand('gc');
69
        $command
70 1
            ->setOption('aggressive', $this->isAggressive())
71 1
            ->setOption('auto', $this->isAuto())
72 1
            ->setOption('no-prune', $this->isNoPrune());
73 1
        if ($this->isNoPrune() == false) {
74 1
            $command->setOption('prune', $this->getPrune());
75
        }
76

77
        // suppress output
78 1
        $command->setOption('q');
79

80 1
        $this->log('git-gc command: ' . $command->createCommandString(), Project::MSG_INFO);
81

82
        try {
83 1
            $command->execute();
84 0
        } catch (Exception $e) {
85 0
            throw new BuildException('Task execution failed', $e);
86
        }
87

88 1
        $this->log(
89 1
            sprintf('git-gc: cleaning up "%s" repository', $this->getRepository()),
90 1
            Project::MSG_INFO
91
        );
92
    }
93

94
    /**
95
     * @see getAggressive()
96
     */
97 1
    public function isAggressive()
98
    {
99 1
        return $this->getAggressive();
100
    }
101

102
    /**
103
     * @return bool
104
     */
105 1
    public function getAggressive()
106
    {
107 1
        return $this->isAggressive;
108
    }
109

110
    /**
111
     * @param $flag
112
     */
113 1
    public function setAggressive(bool $flag)
114
    {
115 1
        $this->isAggressive = $flag;
116
    }
117

118
    /**
119
     * @see getAuto()
120
     */
121 1
    public function isAuto()
122
    {
123 1
        return $this->getAuto();
124
    }
125

126
    /**
127
     * @return bool
128
     */
129 1
    public function getAuto()
130
    {
131 1
        return $this->isAuto;
132
    }
133

134
    /**
135
     * @param $flag
136
     */
137 1
    public function setAuto(bool $flag)
138
    {
139 1
        $this->isAuto = $flag;
140
    }
141

142
    /**
143
     * @see NoPrune()
144
     */
145 1
    public function isNoPrune()
146
    {
147 1
        return $this->getNoPrune();
148
    }
149

150
    /**
151
     * @return bool
152
     */
153 1
    public function getNoPrune()
154
    {
155 1
        return $this->noPrune;
156
    }
157

158
    /**
159
     * @param $flag
160
     */
161 1
    public function setNoPrune(bool $flag)
162
    {
163 1
        $this->noPrune = $flag;
164
    }
165

166
    /**
167
     * @return string
168
     */
169 1
    public function getPrune()
170
    {
171 1
        return $this->prune;
172
    }
173

174
    /**
175
     * @param $date
176
     */
177 1
    public function setPrune($date)
178
    {
179 1
        $this->prune = $date;
180
    }
181
}

Read our documentation on viewing source code .

Loading