1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fabrica\Helps\Git; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Git Interface Class |
7
|
|
|
* |
8
|
|
|
* This class enables the creating, reading, and manipulation |
9
|
|
|
* of git repositories. |
10
|
|
|
* |
11
|
|
|
* @class Git |
12
|
|
|
*/ |
13
|
|
|
class Git |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Git executable location |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected static $bin = '/usr/bin/git'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Sets git executable path |
25
|
|
|
* |
26
|
|
|
* @param string $path executable location |
27
|
|
|
*/ |
28
|
|
|
public static function set_bin($path) |
29
|
|
|
{ |
30
|
|
|
self::$bin = $path; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Gets git executable path |
35
|
|
|
*/ |
36
|
|
|
public static function get_bin() |
37
|
|
|
{ |
38
|
|
|
return self::$bin; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Sets up library for use in a default Windows environment |
43
|
|
|
*/ |
44
|
|
|
public static function windows_mode() |
45
|
|
|
{ |
46
|
|
|
self::set_bin('git'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create a new git repository |
51
|
|
|
* |
52
|
|
|
* Accepts a creation path, and, optionally, a source path |
53
|
|
|
* |
54
|
|
|
* @access public |
55
|
|
|
* @param string repository path |
56
|
|
|
* @param string directory to source |
57
|
|
|
* @return GitRepo |
58
|
|
|
*/ |
59
|
|
|
public static function &create($repo_path, $source = null) |
60
|
|
|
{ |
61
|
|
|
return GitRepo::create_new($repo_path, $source); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Open an existing git repository |
66
|
|
|
* |
67
|
|
|
* Accepts a repository path |
68
|
|
|
* |
69
|
|
|
* @access public |
70
|
|
|
* @param string repository path |
71
|
|
|
* @return GitRepo |
72
|
|
|
*/ |
73
|
|
|
public static function open($repo_path) |
74
|
|
|
{ |
75
|
|
|
return new GitRepo($repo_path); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Clones a remote repo into a directory and then returns a GitRepo object |
80
|
|
|
* for the newly created local repo |
81
|
|
|
* |
82
|
|
|
* Accepts a creation path and a remote to clone from |
83
|
|
|
* |
84
|
|
|
* @access public |
85
|
|
|
* @param string repository path |
86
|
|
|
* @param string remote source |
87
|
|
|
* @param string reference path |
88
|
|
|
* @return GitRepo |
89
|
|
|
**/ |
90
|
|
|
public static function &clone_remote($repo_path, $remote, $reference = null) |
91
|
|
|
{ |
92
|
|
|
//Changed the below boolean from true to false, since this appears to be a bug when not using a reference repo. A more robust solution may be appropriate to make it work with AND without a reference. |
93
|
|
|
return GitRepo::create_new($repo_path, $remote, false, $reference); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Checks if a variable is an instance of GitRepo |
98
|
|
|
* |
99
|
|
|
* Accepts a variable |
100
|
|
|
* |
101
|
|
|
* @access public |
102
|
|
|
* @param mixed variable |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public static function is_repo($var) |
106
|
|
|
{ |
107
|
|
|
return (get_class($var) == 'GitRepo'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|