7 * #repo/hooks/post-receive
8 * /usr/bin/php {PATH TO APPLICATION}/index.php Hook/git post >> /tmp/githooklog
16 /* For licensing and copyright terms, see the file named LICENSE */
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
24 require_once 'MTrackWeb.php';
26 class MTrackWeb_Hook_git extends MTrackWeb
30 if (!HTML_FlexyFramework::get()->cli) {
39 $repo = DB_DataObject::factory('mtrack_repos');
40 $repo->repopath = getcwd();
41 if (!$repo->find(true)) {
42 $this->addEvent("HOOKERROR", false, "invalid repo:". getcwd() );
43 die("INVALID REPO" . getcwd() );
47 require_once 'MTrack/SCM/Git/CommitHookBridge.php';
49 $bridge = new MTrack_SCM_Git_CommitHookBridge($repo);
51 // for POST commit, we can use bridge->commits[0] to determine who..
52 $revs = $repo->history('.',1,'rev', $bridge->commits[0]);
54 print_r($revs[0]->changebyToRFC());
55 die("work out user?");
57 // WTF is this for.. it the hook should be telling who the user is.
58 $author = 'www-data';//MTrackAuth::whoami();
59 $author = mtrack_canon_username($author);
60 MTrackAuth::su($author);
62 $checker = new MTrackCommitChecker($repo);
67 $checker->preCommit($bridge);
71 $checker->postCommit($bridge);
79 } catch (Exception $e) {
81 fwrite(STDERR, "\n" . $e->getMessage() .
83 $e->getTraceAsString() .
84 "\n\n ** Commit failed [$action]\n");