MTrackWeb/Hook/git.php
[web.mtrack] / MTrackWeb / Hook / git.php
1 <?php  
2
3 /****
4  *
5  *  usage:
6  *
7  *  #repo/hooks/post-receive
8  *  /usr/bin/php {PATH TO APPLICATION}/index.php Hook/git post  >> /tmp/githooklog
9  *
10  *
11  *
12  */
13
14
15
16 /* For licensing and copyright terms, see the file named LICENSE */
17 // called as:
18
19 // git-commit-hook what [mtrackconfig] > /tmp/gitlog
20 // the cwd is the repo path
21 // a list of "oldrev newrev refname" lines is presented to us on stdin
22
23  
24 require_once 'MTrackWeb.php';
25
26 class MTrackWeb_Hook_git extends MTrackWeb
27 {
28     function getAuth()
29     {
30         if (!HTML_FlexyFramework::get()->cli) {
31             die("NOT CLI!");
32         }
33         
34     }
35     
36     
37     function get($action)
38     {
39         
40         try {
41             $repo = DB_DataObject::factory('mtrack_repos');
42             $repo->repopath = getcwd();
43             if (!$repo->find(true)) {
44                 $this->addEvent("HOOKERROR", false, "invalid repo:". getcwd() );
45                 die("INVALID REPO" . getcwd() );
46             }
47             echo "running hook";
48             
49             require_once 'MTrack/SCM/Git/CommitHookBridge.php';
50             
51             $bridge = new MTrack_SCM_Git_CommitHookBridge($repo);
52             
53             die("work out user?");
54             
55             // WTF is this for.. it the hook should be telling who the user is.
56             $author = 'www-data';//MTrackAuth::whoami();
57             $author = mtrack_canon_username($author);
58             MTrackAuth::su($author);
59         
60             $checker = new MTrackCommitChecker($repo);
61             
62             switch ($action) {
63                 
64                 case 'pre':
65                     $checker->preCommit($bridge);
66                     break;
67                     
68                 default:
69                     $checker->postCommit($bridge);
70                   
71             }
72             //_log("SUCCESS");
73             exit(0);
74             
75             
76             
77         } catch (Exception $e) {
78              
79           fwrite(STDERR, "\n" . $e->getMessage() .
80             "\n\n" .
81             $e->getTraceAsString() .
82             "\n\n ** Commit failed [$action]\n");
83         
84           exit(1);
85         }
86         
87     }
88     
89 }
90