final move of files
[web.mtrack] / MTrackWeb / Hook / git.php
1 #!/usr/bin/env php
2 <?php # vim:ts=2:sw=2:et:ft=php:
3 /* For licensing and copyright terms, see the file named LICENSE */
4 // called as:
5
6 // git-commit-hook what [mtrackconfig] > /tmp/gitlog
7 // the cwd is the repo path
8 // a list of "oldrev newrev refname" lines is presented to us on stdin
9
10
11 die("MAKE INTO CLASS");
12
13 $action = $argv[1]; 
14
15 include dirname(__FILE__) . '/../inc/common.php';
16
17 require_once 'SCM/Git/CommitHookBridge.php';
18
19 MTrackConfig::checkInitializing();
20
21 //MTrackCommitChecker::addCheck('NoEmptyLogMessage');
22 //MTrackCommitChecker::addCheck('BlankLines');
23 //MTrackCommitChecker::addCheck('UnixLineBreak');
24 //MTrackCommitChecker::addCheck('SingleIssue'); 
25
26 //ini_set('display_errors', true);
27  
28
29 try {
30     
31     $repo = MTrackRepo::loadByLocation(getcwd());
32     $bridge = new MTrack_SCM_Git_CommitHookBridge($repo);
33     
34     // WTF is this for.. it the hook should be telling who the user is.
35     $author = 'www-data';//MTrackAuth::whoami();
36     $author = mtrack_canon_username($author);
37     MTrackAuth::su($author);
38
39     $checker = new MTrackCommitChecker($repo);
40     
41     switch ($argv[1]) {
42         
43         case 'pre':
44             $checker->preCommit($bridge);
45             break;
46             
47         default:
48             $checker->postCommit($bridge);
49           
50     }
51     //_log("SUCCESS");
52     exit(0);
53     
54     
55     
56 } catch (Exception $e) {
57      
58   fwrite(STDERR, "\n" . $e->getMessage() .
59     "\n\n" .
60     $e->getTraceAsString() .
61     "\n\n ** Commit failed [$action]\n");
62
63   exit(1);
64 }
65