make mime type detection work on php-fpm which has no PATH env variable
[phorkie.git] / src / phorkie / Repository / Setup.php
1 <?php
2 namespace phorkie;
3
4 class Repository_Setup
5 {
6     protected $repo;
7
8     public function __construct(Repository $repo)
9     {
10         $this->repo = $repo;
11     }
12
13     /**
14      * Should be called right after a repository has been created,
15      * either by "git init" or "git clone".
16      * Takes care of removing hook example files and creating
17      * the git daemon export file
18      *
19      * @return void
20      */
21     public function afterInit()
22     {
23         foreach (glob($this->repo->gitDir . '/hooks/*') as $hookfile) {
24             unlink($hookfile);
25         }
26         touch($this->repo->gitDir . '/git-daemon-export-ok');
27
28         $vc = $this->repo->getVc();
29
30         file_put_contents(
31             $this->repo->gitDir . '/hooks/post-update',
32             <<<CDE
33 #!/bin/sh
34 # Hook script to prepare a packed repository for use over dumb transports.
35
36 echo foo > /tmp/foo
37 exec git update-server-info
38
39 CDE
40         );
41         chmod($this->repo->gitDir . '/hooks/post-update', 0755);
42
43         //keep track of owner
44         $vc->getCommand('config')
45             ->addArgument('owner.name')
46             ->addArgument($_SESSION['name'])
47             ->execute();
48         $vc->getCommand('config')
49             ->addArgument('owner.email')
50             ->addArgument($_SESSION['email'])
51             ->execute();
52     }
53
54 }
55
56 ?>