forked from hitautodestruct/gityup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (51 loc) · 1.37 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
var exec = require('child_process').execSync;
module.exports = (function () {
var REPO = '';
// Setup repo name so we can access outside of the folder
var setup = function ( repo_path ) {
REPO = repo_path;
};
// Returns the git path with the command
// Allows us to access the git repo outside of the given directory
var get_git_path = function () {
return 'git --git-dir='+ REPO +'/.git --work-tree='+ REPO;
};
// Outputs result to log
var log_result = function(error, stdout, stderr) {
console.log(stdout);
};
// Excutes given command and outputs result
var execute = function ( command ) {
exec( command );
};
// Clone the directory via http url
var clone = function ( url ) {
var command = 'git clone ' + url;
execute( command );
};
// Checkout branch
var checkout = function ( branch_name ) {
var git_path = get_git_path(),
command = git_path + ' checkout ' + branch_name;
execute( command );
};
// Show git status
var status = function () {
var git_path = get_git_path(),
command = git_path + ' status';
execute( command );
};
// Pull from repo on current branch
var pull = function () {
var git_path = get_git_path(),
command = git_path + ' pull';
execute( command );
};
return {
setup,
clone,
checkout,
status,
pull
};
})();