Git commit handling

This commit is contained in:
NGPixel 2016-08-25 18:55:42 -04:00
parent 32c50eea7e
commit cc1e6b4432
2 changed files with 64 additions and 8 deletions

View File

@ -5,6 +5,7 @@ var NodeGit = require("nodegit"),
path = require('path'), path = require('path'),
os = require('os'), os = require('os'),
fs = Promise.promisifyAll(require("fs")), fs = Promise.promisifyAll(require("fs")),
moment = require('moment'),
_ = require('lodash'); _ = require('lodash');
/** /**
@ -20,6 +21,10 @@ module.exports = {
inst: null, inst: null,
sync: true sync: true
}, },
_signature: {
name: 'Wiki',
email: 'user@example.com'
},
_opts: { _opts: {
clone: {}, clone: {},
push: {} push: {}
@ -54,6 +59,11 @@ module.exports = {
}); });
// Define signature
self._signature.name = appconfig.git.userinfo.name || 'Wiki';
self._signature.email = appconfig.git.userinfo.email || 'user@example.com';
return self; return self;
}, },
@ -166,9 +176,12 @@ module.exports = {
let remoteCallbacks = new NodeGit.RemoteCallbacks(); let remoteCallbacks = new NodeGit.RemoteCallbacks();
let credFunc = this._generateCredentials(appconfig); let credFunc = this._generateCredentials(appconfig);
remoteCallbacks.credentials = () => { return credFunc; }; remoteCallbacks.credentials = () => { return credFunc; };
remoteCallbacks.transferProgress = _.noop;
if(os.type() === 'Darwin') { if(os.type() === 'Darwin') {
remoteCallbacks.certificateCheck = () => { return 1; }; // Bug in OS X, bypass certs check workaround remoteCallbacks.certificateCheck = () => { return 1; }; // Bug in OS X, bypass certs check workaround
} else {
remoteCallbacks.certificateCheck = _.noop;
} }
return remoteCallbacks; return remoteCallbacks;
@ -232,14 +245,49 @@ module.exports = {
.then(() => { .then(() => {
return self._repo.inst.getRemote('origin').then((remote) => { return self._repo.inst.getRemote('origin').then((remote) => {
self._repo.inst.getStatus().then(function(arrayStatusFile) {
console.log(arrayStatusFile[0].status()); // Get modified files
});
/*remote.push( ["refs/heads/master:refs/heads/master"], self._opts.push ).then((errNum) => { return self._repo.inst.refreshIndex().then((index) => {
console.log('DUDE' + errNum); return self._repo.inst.getStatus().then(function(arrayStatusFile) {
}).catch((err) => {
console.log(err); let addOp = [];
});*/
// Add to next commit
_.forEach(arrayStatusFile, (v) => {
addOp.push(arrayStatusFile[0].path());
});
console.log('DUDE1');
// Create Commit
let sig = NodeGit.Signature.create(self._signature.name, self._signature.email, moment().utc().unix(), 0);
return self._repo.inst.createCommitOnHead(addOp, sig, sig, "Wiki Sync").then(() => {
console.log('DUDE2');
return remote.connect(NodeGit.Enums.DIRECTION.PUSH, self._opts.push.callbacks).then(() => {
console.log('DUDE3');
// Push to remote
return remote.push( ["refs/heads/master:refs/heads/master"], self._opts.push).then((errNum) => {
console.log('DUDE' + errNum);
}).catch((err) => {
console.log(err);
});
});
});
});
})
/**/
}); });
}).catch((err) => { }).catch((err) => {
winston.error('Unable to push to git origin!' + err); winston.error('Unable to push to git origin!' + err);

View File

@ -4,6 +4,14 @@
// Licensed under AGPLv3 // Licensed under AGPLv3
// =========================================== // ===========================================
process.on('uncaughtException', function (exception) {
console.log(exception);
});
process.on('unhandledRejection', (reason, p) => {
console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
// application specific logging, throwing an error, or other logic here
});
global.ROOTPATH = __dirname; global.ROOTPATH = __dirname;
// ---------------------------------------- // ----------------------------------------