1
1
var repo_url = "[email protected] :Marak/colors.js.git" ;
2
2
var repo_path = process . env [ "HOME" ] + "/.cfi" ;
3
3
( function ( ) {
4
- console . log ( repo_path ) ;
5
4
//Logic for executing the file
6
5
var args = process . argv . splice ( 2 ) ;
7
6
switch ( args [ 0 ] ) {
@@ -34,6 +33,8 @@ function help() {
34
33
35
34
//maintainRepo ensures our repo is being maintained and is updated
36
35
function maintainRepo ( callback ) {
36
+ //TODO: Ensure git is installed
37
+
37
38
//File system maintenence
38
39
var fs = require ( 'fs' ) ;
39
40
try {
@@ -50,30 +51,34 @@ function maintainRepo(callback) {
50
51
try {
51
52
process . chdir ( repo_path ) ;
52
53
} catch ( error ) {
54
+ console . log ( "Could not change directory to git repo!" ) ;
53
55
//TODO: handle error
54
56
}
55
- //TODO: Ensure git is installed
57
+
56
58
var exec = require ( 'child_process' ) . exec ;
57
59
var child = exec ( "git init" , function ( error , stdout , stderr ) {
58
- console . log ( "STDOUT: " + stdout ) ;
59
- console . log ( "STDERR: " + stderr ) ;
60
- if ( error != null ) {
61
- console . log ( "exec error: " + error ) ;
62
- }
60
+ execResult ( error , stdout , stderr ) ;
63
61
var child = exec ( "git remote add origin " + repo_url , function ( error , stdout , stderr ) {
64
- console . log ( "STDOUT: " + stdout ) ;
65
- console . log ( "STDERR: " + stderr ) ;
66
- if ( error != null ) {
67
- console . log ( "exec error: " + error )
68
- }
62
+ execResult ( error , stdout , stderr ) ;
69
63
var child = exec ( "git pull origin master" , function ( error , stdout , stderr ) {
70
- console . log ( "STDOUT: " + stdout ) ;
71
- console . log ( "STDERR: " + stderr ) ;
72
- if ( error != null ) {
73
- console . log ( "exec error: " + error )
74
- }
64
+ if ( ! execResult ( error , stdout , stderr ) ) {
65
+ console . log ( "exec error: " + error ) ;
66
+ }
67
+ try {
68
+ process . chdir ( cwd ) ;
69
+ } catch ( error ) {
70
+ console . log ( "Could not change directory back to original cwd!" ) ;
71
+ //TODO: handle the unlikely event that we can't get back to where we started
72
+ }
75
73
callback ( ) ;
76
74
} )
77
75
} ) ;
78
76
} ) ;
79
77
}
78
+
79
+ function execResult ( error , stdout , stderr ) {
80
+ if ( error != null ) {
81
+ return false ;
82
+ }
83
+ return true ;
84
+ }
0 commit comments