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
 * Base class for Git tasks
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
abstract class GitBaseTask extends Task
29
{
30
    /**
31
     * Bath to git binary
32
     *
33
     * @var string
34
     */
35
    private $gitPath = '/usr/bin/git';
36

37
    /**
38
     * @var VersionControl_Git
39
     */
40
    private $gitClient = null;
41

42
    /**
43
     * Current repository directory
44
     *
45
     * @var string
46
     */
47
    private $repository;
48

49
    /**
50
     * Initialize Task.
51
     * Check and include necessary libraries.
52
     */
53 2
    public function init()
54
    {
55 2
        @include_once 'VersionControl/Git.php';
56 2
        if (false == class_exists('VersionControl_Git')) {
57 0
            throw new BuildException(
58 0
                "The Git tasks depend on the pear/versioncontrol_git package being installed.",
59 0
                $this->getLocation()
60
            );
61
        }
62
    }
63

64
    /**
65
     * Set repository directory
66
     *
67
     * @param  string $repository Repo directory
68
     * @return GitBaseTask
69
     */
70 2
    public function setRepository($repository)
71
    {
72 2
        $this->repository = $repository;
73

74 2
        return $this;
75
    }
76

77
    /**
78
     * Get repository directory
79
     *
80
     * @return string
81
     */
82 2
    public function getRepository()
83
    {
84 2
        return $this->repository;
85
    }
86

87
    /**
88
     * Set path to git executable
89
     *
90
     * @param  string $gitPath New path to git repository
91
     * @return GitBaseTask
92
     */
93 2
    public function setGitPath($gitPath)
94
    {
95 2
        $this->gitPath = $gitPath;
96

97 2
        return $this;
98
    }
99

100
    /**
101
     * Get path to git executable
102
     *
103
     * @return string
104
     */
105 2
    public function getGitPath()
106
    {
107 2
        return $this->gitPath;
108
    }
109

110
    /**
111
     * @param bool $reset
112
     * @param null $repository
113
     * @return null|VersionControl_Git
114
     * @throws BuildException
115
     */
116 2
    protected function getGitClient($reset = false, $repository = null)
117
    {
118 2
        $this->gitClient = ($reset === true) ? null : $this->gitClient;
119 2
        $repository = $repository ?? $this->getRepository();
120

121 2
        if (null === $this->gitClient) {
122
            try {
123 2
                $this->gitClient = new VersionControl_Git($repository);
124 2
            } catch (VersionControl_Git_Exception $e) {
125
                // re-package
126 2
                throw new BuildException(
127 2
                    'You must specify readable directory as repository.',
128
                    $e
129
                );
130
            }
131
        }
132 2
        $this->gitClient->setGitCommandPath($this->getGitPath());
133

134 2
        return $this->gitClient;
135
    }
136
}

Read our documentation on viewing source code .

Loading