Skip to content

Commit ee6827c

Browse files
committed
Allow using several git repos
- Git.php: - in case of auto determined repos: - use git rev-parse --git-dir option rather than --absolute-git-dir to support a maximum range of git versions - function absolute_git_dir($path): - extended the logic to ensure to return an absolute repo_path in any case
1 parent ff5ae89 commit ee6827c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

lib/Git.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,19 +305,21 @@ public function test_git() {
305305
}
306306

307307
/**
308-
* Determine closest parent git repository for a given path
308+
* Determine closest parent git repository for a given path as absolute PHP realpath().
309309
*
310310
* @access public
311-
* @return string the next parent git repo root dir or empty string, if no parent repo found
311+
* @return string the next parent git repo root dir as absolute PHP realpath() or empty string, if no parent repo found
312312
*/
313313
public function absolute_git_dir($path) {
314314
$descriptorspec = array(
315315
1 => array('pipe', 'w'),
316316
2 => array('pipe', 'w'),
317317
);
318318
$pipes = array();
319-
$command = Git::get_bin()." rev-parse --absolute-git-dir";
320-
//dbglog("Command: ".$command);
319+
// Using --git-dir rather than --absolute-git-dir for a wider git versions compatibility
320+
//$command = Git::get_bin()." rev-parse --absolute-git-dir";
321+
$command = Git::get_bin()." rev-parse --git-dir";
322+
//dbglog("GitBacked - Command: ".$command);
321323
$resource = proc_open($command, $descriptorspec, $pipes, $path);
322324
$stdout = stream_get_contents($pipes[1]);
323325
$stderr = stream_get_contents($pipes[2]);
@@ -328,8 +330,14 @@ public function absolute_git_dir($path) {
328330
$status = trim(proc_close($resource));
329331
if ($status == 0) {
330332
$repo_git_dir = trim($stdout);
333+
//dbglog("GitBacked - $command: '".$repo_git_dir."'");
331334
if (!empty($repo_git_dir)) {
332-
$repo_path = dirname($repo_git_dir);
335+
if (strcmp($repo_git_dir, ".git") === 0) {
336+
// convert to absolute path based on this command execution directory
337+
$repo_git_dir = $path.'/'.$repo_git_dir;
338+
}
339+
$repo_path = dirname(realpath($repo_git_dir));
340+
//dbglog('GitBacked - $repo_path: '.$repo_path);
333341
if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
334342
return $repo_path;
335343
}

0 commit comments

Comments
 (0)