Change Details
| doc/syncgit.mdtext |
| 70 | 70 | $cfg['idf_plugin_syncgit_path_gitserve'] = '/home/www/indefero/scripts/gitserve.py'; # yes .py |
| 71 | 71 | $cfg['idf_plugin_syncgit_path_authorized_keys'] = '/home/git/.ssh/authorized_keys'; |
| 72 | 72 | $cfg['idf_plugin_syncgit_sync_file'] = '/tmp/SYNC-GIT'; |
| 73 | # Remove the git repositories which do not have a corresponding project |
| 74 | # This is run at cron time |
| 75 | $cfg['idf_plugin_syncgit_remove_orphans'] = false; |
| 73 | 76 | |
| 74 | 77 | When someone will change his SSH key or add a new one, the |
| 75 | 78 | `/tmp/SYNC-GIT` file will be created. The cron job |
| src/IDF/Plugin/SyncGit/Cron.php |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | * Remove orphan repositories. |
| 74 | */ |
| 75 | public static function removeOrphanRepositories() |
| 76 | { |
| 77 | $path = Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories'); |
| 78 | if (!is_dir($path) || is_link($path)) { |
| 79 | throw new Pluf_Exception_SettingError(sprintf( |
| 80 | 'Directory %s does not exist! Setting "idf_plugin_syncgit_base_repositories not set.', |
| 81 | $path)); |
| 82 | } |
| 83 | if (!is_writable($path)) { |
| 84 | throw new Exception(sprintf('Repository %s is not writable.', $path)); |
| 85 | } |
| 86 | $projects = array(); |
| 87 | foreach (Pluf::factory('IDF_Project')->getList() as $project) { |
| 88 | $projects[] = $project->shortname; |
| 89 | } |
| 90 | unset($project); |
| 91 | $it = new DirectoryIterator($path); |
| 92 | $orphans = array(); |
| 93 | while ($it->valid()) { |
| 94 | if (!$it->isDot() && $it->isDir() && !in_array(basename($it->getFileName(), '.git'), $projects)) { |
| 95 | $orphans[] = $it->getPathName(); |
| 96 | } |
| 97 | $it->next(); |
| 98 | } |
| 99 | if (count($orphans)) { |
| 100 | $cmd = Pluf::f('idf_exec_cmd_prefix', '').'rm -rf '.implode(' ', $orphans); |
| 101 | exec($cmd); |
| 102 | while (list(, $project) = each($orphans)) { |
| 103 | if (is_dir($project)) { |
| 104 | throw new Exception(sprintf('Cannot remove %s directory.', $project)); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 73 | 111 | * Check if a sync is needed. |
| 74 | 112 | * |
| 75 | 113 | */ |
| ... | ... | |
| 79 | 117 | @unlink(Pluf::f('idf_plugin_syncgit_sync_file')); |
| 80 | 118 | self::sync(); |
| 81 | 119 | self::markExport(); |
| 120 | if (Pluf::f('idf_plugin_syncgit_remove_orphans', false)) { |
| 121 | self::removeOrphanRepositories(); |
| 122 | } |
| 82 | 123 | } |
| 83 | 124 | } |
| 84 | 125 | } |
Download the corresponding diff file