forked from jwcooper/Gitty
/
index.js
109 lines (94 loc) · 2.33 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Gitty - index.js
* Author: Gordon Hall
*
* Initializes module and exposes public methods
*/
var Repository = require('./lib/repository');
var Command = require('./lib/command');
/**
* Setup function for getting access to a GIT repo
* @constructor
* @param {String} path
*/
var Gitty = function(path) {
return new Repository(path);
};
/**
* Handles the global GIT configuration
* @param {String} key
* @param {String} val
* @param {Function} callback
*/
Gitty.setConfig = function(key, val, callback) {
var cmd = new Command('/', 'config', ['--global', key], '"' + val + '"');
var done = callback || new Function();
cmd.exec(function(err, stdout, stderr) {
done(err || null);
});
};
/**
* Handles the global GIT configuration
* @param {String} key
* @param {String} val
* @param {Function} callback
*/
Gitty.setConfigSync = function(key, val) {
var cmd = new Command('/', 'config', ['--global', key], '"' + val + '"');
return cmd.execSync();
};
/**
* Handles the global GIT configuration
* @param {String} key
* @param {Function} callback
*/
Gitty.getConfig = function(key, callback) {
var cmd = new Command('/', 'config', ['--global', key]);
var done = callback || new Function();
cmd.exec(function(err, stdout, stderr) {
done(err || null, stdout);
});
};
/**
* Handles the global GIT configuration
* @param {String} key
* @param {Function} callback
*/
Gitty.getConfigSync = function(key) {
var cmd = new Command('/', 'config', ['--global', key]);
return cmd.execSync();
};
/**
* Wrapper for the GIT clone function
* @param {String} path
* @param {String} url
* @param {Object} creds
* @param {Function} callback
*/
Gitty.clone = function(path, url) {
var self = this;
var args = Array.prototype.slice.apply(arguments);
var done = args.slice(-1).pop() || new Function();
var command = ['clone', url, path].join(' ');
var cmd = new Command('/', command);
cmd.exec(function(err, stdout, stderr) {
done(err, {stdout: stdout, stderr: stderr});
});};
/**
* Export Contructor
* @constructor
* @type {Object}
*/
module.exports = Gitty;
/**
* Export Repository Contructor
* @constructor
* @type {Object}
*/
module.exports.Repository = Repository;
/**
* Export Command Contructor
* @constructor
* @type {Object}
*/
module.exports.Command = Command;