-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit.js
50 lines (41 loc) · 1.48 KB
/
git.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Git interface for pushing packages to github
// (c)copyright 2016, 2018 by Gerald Wodni <[email protected]>
const path = require("path");
const simpleGit = require("simple-git");
/* package subrepo status */
function repoStatus( dir, callback ) {
const git = simpleGit( dir );
git.status( callback );
}
function getStatus( dir, callback ) {
repoStatus( dir, ( err, stati ) => {
if( err ) return callback( err );
var files = [];
function addStatiFiles( statiFiles, text ) {
statiFiles.forEach( file => files.push({
path: file,
status: text
}) );
}
addStatiFiles( stati.not_added, "NOT ADDED" );
addStatiFiles( stati.conflicted, "CONFLICT" );
addStatiFiles( stati.created, "CREATED" );
addStatiFiles( stati.deleted, "DELETED" );
addStatiFiles( stati.modified, "MODIFIED" );
addStatiFiles( stati.renamed, "RENAMED" );
addStatiFiles( stati.staged, "STAGED" );
callback( null, files );
});
}
function addCommitPush( sshDir, dir, commitMessage, callback ) {
const GIT_SSH_COMMAND = `ssh -i ${sshDir}.id_rsa`;
const git = simpleGit( dir );
git.env("GIT_SSH_COMMAND", GIT_SSH_COMMAND)
.add("./*")
.commit( commitMessage )
.push( 'origin', 'master', callback );
}
module.exports = {
getStatus: getStatus,
addCommitPush: addCommitPush
};