|
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
|
|
|
use \GitElephant\Utilities; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Git binary |
|
26
|
|
|
* It contains the reference to the system git binary |
|
27
|
|
|
* |
|
28
|
|
|
* @author Matteo Giachino <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
class GitBinary |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* the path to the repository |
|
34
|
|
|
* |
|
35
|
|
|
* @var string $path |
|
36
|
|
|
*/ |
|
37
|
|
|
private $path; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Class constructor |
|
41
|
|
|
* |
|
42
|
|
|
* @param null $path the physical path to the git binary |
|
43
|
|
|
*/ |
|
44
|
103 |
|
public function __construct($path = null) |
|
45
|
|
|
{ |
|
46
|
103 |
|
if (is_null($path)) { |
|
47
|
102 |
|
$cmd = (Utilities::isWindows() ? "where" : "which") . " git"; |
|
48
|
102 |
|
$path = exec($cmd); |
|
49
|
|
|
|
|
50
|
|
|
// Escape spaces in the binary path for windows |
|
51
|
102 |
|
if(Utilities::isWindows()) { |
|
|
|
|
|
|
52
|
|
|
$path = '"'.$path.'"'; |
|
53
|
|
|
} |
|
54
|
102 |
|
} |
|
55
|
103 |
|
$this->setPath($path); |
|
56
|
103 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* path getter |
|
60
|
|
|
* returns the path of the binary |
|
61
|
|
|
* |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
*/ |
|
64
|
99 |
|
public function getPath() |
|
65
|
|
|
{ |
|
66
|
99 |
|
return $this->path; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* path setter |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $path the path to the system git binary |
|
73
|
|
|
*/ |
|
74
|
103 |
|
public function setPath($path) |
|
75
|
|
|
{ |
|
76
|
103 |
|
$this->path = $path; |
|
77
|
103 |
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|