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; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Git binary |
24
|
|
|
* It contains the reference to the system git binary |
25
|
|
|
* |
26
|
|
|
* @author Matteo Giachino <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class GitBinary |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* the path to the repository |
32
|
|
|
* |
33
|
|
|
* @var string $path |
34
|
|
|
*/ |
35
|
|
|
private $path; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $version; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Class constructor |
44
|
|
|
* |
45
|
|
|
* @param null $path the physical path to the git binary |
46
|
|
|
*/ |
47
|
108 |
|
public function __construct(string $path = null) |
48
|
|
|
{ |
49
|
108 |
|
if (is_null($path)) { |
50
|
|
|
// unix only! |
51
|
106 |
|
$path = exec('which git'); |
52
|
|
|
} |
53
|
108 |
|
$this->setPath($path); |
54
|
108 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* path getter |
58
|
|
|
* returns the path of the binary |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
101 |
|
public function getPath() |
63
|
|
|
{ |
64
|
101 |
|
return $this->path; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* path setter |
69
|
|
|
* |
70
|
|
|
* @param string $path the path to the system git binary |
71
|
|
|
*/ |
72
|
108 |
|
public function setPath(string $path) |
73
|
|
|
{ |
74
|
108 |
|
$this->path = $path; |
75
|
108 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
97 |
|
public function getVersion() |
81
|
|
|
{ |
82
|
97 |
|
if (is_null($this->version)) { |
|
|
|
|
83
|
|
|
|
84
|
|
|
// unix only! |
85
|
97 |
|
$this->version = exec('git --version | cut -d " " -f 3'); |
86
|
|
|
} |
87
|
|
|
|
88
|
97 |
|
return $this->version; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|