var express = require('express');
var router = express.Router();
var path = require('path');
var exec = require('child_process').exec;

/* GET home page. */
router.post('/', function(req, res) {
    console.log(req);
    try{
        var commits = req.body.head_commit;
        console.log(commits);
        var git_path = path.resolve('.');
        exec("cd " + git_path + "&& git pull origin master", function(err, stdout, stderr) {
            if(err) {
                res.send(err);
            }else {
                if(commits.removed.length) {
                    if(file.match(/orgs\/.*.\w.org/)){
                        db.reload();
                        return;
                    }
                };

                if(commits.modified.length) {
                    if(file.match(/orgs\/.*.\w.org/)){
                        db.reload();
                        return;
                    }
                };

                var added = commits.added;
                var flag = false;
                for(var i = 0; i < added.length; i++) {
                    if(added[i].match(/orgs\/.*.\w.org/)) {
                        db.add(added[i]);
                        flag = true;
                    }
                }
                if(flag) db.save();

                res.send(200);
            }
        })
    } catch(e) {
        res.send(e);
    }
});

module.exports = router;

@@ -538,32 +538,161 @@
 moved.length) %7B%0A
+                    for(var i = 0; i %3C commits.removed.length; i++) %7B%0A                        var file = commits.removed%5Bi%5D;%0A    
                 
@@ -746,32 +746,36 @@
                 
+    
 db.reload();%0A   
@@ -791,32 +791,36 @@
             
+ 
+   
 return;%0A
             
@@ -799,32 +799,58 @@
         return;%0A
+                        %7D%0A
                 
@@ -913,32 +913,163 @@
 ified.length) %7B%0A
+                    for(var i = 0; i %3C commits.modified.length; i++) %7B%0A                        var file = commits.modified%5Bi%5D;%0A    
                 
@@ -1099,32 +1099,36 @@
 %5C/.*.%5Cw.org/))%7B%0A
+    
                 
@@ -1168,32 +1168,36 @@
             
+    
 return;%0A
             
@@ -1176,32 +1176,58 @@
         return;%0A
+                        %7D%0A
                 

test hook