Add option to remove .git extension from repo names

Boolean option strip_dot_git in config.ini.
This commit is contained in:
Hoel Guilcher
2020-05-17 10:21:32 +02:00
parent 271e6c5518
commit 2e0a400303
5 changed files with 11 additions and 1 deletions

View File

@@ -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

View File

@@ -59,6 +59,7 @@ class Application extends SilexApplication
$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());

View File

@@ -9,6 +9,7 @@ class Client extends BaseClient
protected $defaultBranch;
protected $hidden;
protected $projects;
protected $stripDotGit;
public function __construct($options = null)
{
@@ -16,6 +17,7 @@ class Client extends BaseClient
$this->setDefaultBranch($options['default_branch']);
$this->setHidden($options['hidden']);
$this->setProjects($options['projects']);
$this->stripDotGit = $options['strip_dot_git'];
}
public function getRepositoryFromName($paths, $repo)
@@ -209,7 +211,11 @@ class Client extends BaseClient
$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;

View File

@@ -16,6 +16,7 @@ class GitServiceProvider implements ServiceProviderInterface
$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);
};

View File

@@ -34,6 +34,7 @@ class InterfaceTest extends WebTestCase
$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';