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