Skip to content

Commit

Permalink
Merge pull request #864 from MacHoel/strip_dot_git
Browse files Browse the repository at this point in the history
Strip dot git
  • Loading branch information
klaussilveira committed Aug 25, 2021
2 parents 271e6c5 + 2e0a400 commit 434521a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.ini-example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ client = '/usr/bin/git' ; Your git executable path
default_branch = 'master' ; Default branch when HEAD is detached
repositories[] = '/home/git/repositories/' ; Path to your repositories
; If you wish to add more repositories, just add a new line
strip_dot_git = false ; Remove usual bare repo .git extension from displayed name

; WINDOWS USERS
;client = '"C:\Program Files (x86)\Git\bin\git.exe"' ; Your git executable path
Expand Down
1 change: 1 addition & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function __construct(Config $config, $root = null)
$config->get('git', 'hidden') : array(),
'git.default_branch' => $config->get('git', 'default_branch') ?
$config->get('git', 'default_branch') : 'master',
'git.strip_dot_git' => $config->get('git', 'strip_dot_git')
));

$this->register(new ViewUtilServiceProvider());
Expand Down
8 changes: 7 additions & 1 deletion src/Git/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class Client extends BaseClient
protected $defaultBranch;
protected $hidden;
protected $projects;
protected $stripDotGit;

public function __construct($options = null)
{
parent::__construct($options['path']);
$this->setDefaultBranch($options['default_branch']);
$this->setHidden($options['hidden']);
$this->setProjects($options['projects']);
$this->stripDotGit = $options['strip_dot_git'];
}

public function getRepositoryFromName($paths, $repo)
Expand Down Expand Up @@ -209,7 +211,11 @@ private function recurseDirectory($path, $appendPath = '')
$description = null;
}

$repoName = $appendPath . $file->getFilename();
if (($file->getExtension() == 'git') and $this->stripDotGit) {
$repoName = $appendPath . pathinfo($file->getFilename(), PATHINFO_FILENAME);
} else {
$repoName = $appendPath . $file->getFilename();
}

if (is_array($this->getProjects()) && !in_array($repoName, $this->getProjects())) {
continue;
Expand Down
1 change: 1 addition & 0 deletions src/Provider/GitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function register(Application $app)
$options['projects'] = $app['git.projects'];
$options['ini.file'] = $app['ini.file'];
$options['default_branch'] = $app['git.default_branch'];
$options['strip_dot_git'] = $app['git.strip_dot_git'];

return new Client($options);
};
Expand Down
1 change: 1 addition & 0 deletions tests/InterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function setUpBeforeClass()
$options['hidden'] = array(self::$tmpdir . '/hiddenrepo');
$options['default_branch'] = 'master';
$options['ini.file'] = 'config.ini';
$options['strip_dot_git'] = false;
$options['projects'] = false;

$cacheDir = self::$tmpdir . DIRECTORY_SEPARATOR . 'cache';
Expand Down

0 comments on commit 434521a

Please sign in to comment.