xref: /plugin/gitbacked/classes/Git.php (revision b08c3d51e04f23d878d49c6b945b5f8a1aef6f50)
1<?php
2
3/*
4 * Git.php
5 *
6 * A PHP git library
7 *
8 * @package    Git.php
9 * @version    0.1.4
10 * @author     James Brumond
11 * @copyright  Copyright 2013 James Brumond
12 * @repo       http://github.com/kbjr/Git.php
13 */
14
15if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) die('Bad load order');
16
17// ------------------------------------------------------------------------
18
19/**
20 * Git Interface Class
21 *
22 * This class enables the creating, reading, and manipulation
23 * of git repositories.
24 *
25 * @class  Git
26 */
27class Git {
28
29	/**
30	 * Git executable location
31	 *
32	 * @var string
33	 */
34	protected static $bin = '/usr/bin/git';
35
36	/**
37	 * Sets git executable path
38	 *
39	 * @param string $path executable location
40	 */
41	public static function set_bin($path) {
42		self::$bin = $path;
43	}
44
45	/**
46	 * Gets git executable path
47	 */
48	public static function get_bin() {
49		return self::$bin;
50	}
51
52	/**
53	 * Sets up library for use in a default Windows environment
54	 */
55	public static function windows_mode() {
56		self::set_bin('git');
57	}
58
59	/**
60	 * Create a new git repository
61	 *
62	 * Accepts a creation path, and, optionally, a source path
63	 *
64	 * @access  public
65	 * @param   string  repository path
66	 * @param   string  directory to source
67	 * @param   \action_plugin_gitbacked_editcommit plugin
68	 * @return  GitRepo
69	 */
70	public static function &create($repo_path, $source = null, \action_plugin_gitbacked_editcommit $plugin = null) {
71		return GitRepo::create_new($repo_path, $source, $plugin);
72	}
73
74	/**
75	 * Open an existing git repository
76	 *
77	 * Accepts a repository path
78	 *
79	 * @access  public
80	 * @param   string  repository path
81	 * @param   \action_plugin_gitbacked_editcommit plugin
82	 * @return  GitRepo
83	 */
84	public static function open($repo_path, \action_plugin_gitbacked_editcommit $plugin = null) {
85		return new GitRepo($repo_path, $plugin);
86	}
87
88	/**
89	 * Clones a remote repo into a directory and then returns a GitRepo object
90	 * for the newly created local repo
91	 *
92	 * Accepts a creation path and a remote to clone from
93	 *
94	 * @access  public
95	 * @param   string  repository path
96	 * @param   string  remote source
97	 * @param   string  reference path
98	 * @param   \action_plugin_gitbacked_editcommit plugin
99	 * @return  GitRepo
100	 **/
101	public static function &clone_remote($repo_path, $remote, $reference = null, \action_plugin_gitbacked_editcommit $plugin = null) {
102		return GitRepo::create_new($repo_path, $plugin, $remote, true, $reference);
103	}
104
105	/**
106	 * Checks if a variable is an instance of GitRepo
107	 *
108	 * Accepts a variable
109	 *
110	 * @access  public
111	 * @param   mixed   variable
112	 * @return  bool
113	 */
114	public static function is_repo($var) {
115		return ($var instanceof GitRepo);
116	}
117
118}
119
120/* End of file */
121