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