You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also specify as an option on repository creation:
90
+
91
+
$logger = new Monolog\Logger('repository');
92
+
$repository = new Repository('/path/foo', array('logger' => $logger));
93
+
94
+
$repository->run('fetch', array('--all'));
95
+
88
96
This will output:
89
97
90
98
.. code-block:: text
@@ -93,3 +101,35 @@ This will output:
93
101
debug last command (fetch) duration: 23.24ms
94
102
debug last command (fetch) return code: 0
95
103
debug last command (fetch) output: Fetching origin
104
+
105
+
Disable debug-mode
106
+
..................
107
+
108
+
Gitlib throws an exception when something seems wrong. If a ``git` command returns a non-zero result, it will stop execution and throw an ``RuntimeException``.
109
+
110
+
If you want to prevent this, set ``debug`` option to ``false``. This will make Repository log errors and return empty data instead of throwing exceptions.
111
+
112
+
.. code-block:: php
113
+
114
+
$repository = new Repository('/tmp/foo', array('debug' => false, 'logger' => $logger));
115
+
116
+
.. note:: if you plan to disable debug, you should rely on logger to keep a trace of edge failing cases.
117
+
118
+
Specify git command to use
119
+
..........................
120
+
121
+
You can pass option ``command`` to specify which command to use to run git calls. If you have a git binary
122
+
located somewhere else, use this option to specify to gitlib path to your git binary:
123
+
124
+
.. code-block:: php
125
+
126
+
$repository = new Gitonomy\Git\Repository('/tmp/foo', array('command' => '/home/alice/bin/git'));
127
+
128
+
Environment variables
129
+
.....................
130
+
131
+
Now you want to set environment variables to use to run ``git`` commands. It might be useful.
132
+
133
+
.. code-block:: php
134
+
135
+
$repository = new Gitonomy\Git\Repository('/tmp/foo', array('environment_variables' => array('GIT_')))
* * logger : a logger to use for logging actions (Psr\Log\LoggerInterface)
94
99
*
95
100
* * environment_variables : define environment variables for every ran process
96
101
*
@@ -105,11 +110,36 @@ public function __construct($dir, $options = array())
105
110
'working_dir' => null,
106
111
'debug' => true,
107
112
'logger' => null,
108
-
'environment_variables' => array()
113
+
'environment_variables' => array(),
114
+
'command' => 'git'
109
115
), $options);
110
116
111
-
$gitDir = realpath($dir);
112
-
$workingDir = $options['working_dir'];
117
+
if (null !== $options['logger'] && ! $options['logger'] instanceof LoggerInterface) {
118
+
thrownew \InvalidArgumentException(sprintf('Argument "logger" passed to Repository should be a Psr\Log\LoggerInterface. A %s was provided', is_object($options['logger']) ? get_class($options['logger']) : gettype($options['logger'])));
if (null !== $options['logger'] && ! $options['logger'] instanceof LoggerInterface) {
129
-
thrownew \InvalidArgumentException(sprintf('Argument "logger" passed to Repository should be a LoggerInterface. A %s was provided', is_object($options['logger']) ? get_class($options['logger']) : gettype($options['logger'])));
130
-
}
131
-
$this->logger = $options['logger'];
132
-
133
-
if (true === $this->debug && null !== $this->logger) {
134
-
$logger->debug('Repository created (git dir: %s, working dir: %s)', $this->gitDir, $this->workingDir ? : 'none');
135
-
}
136
153
}
137
154
138
155
/**
@@ -567,7 +584,7 @@ public function cloneTo($path, $bare = true, array $options = array())
0 commit comments