Skip to content

Commit f2ed9d5

Browse files
author
William Blankenship
committed
Changed working directory back to original cwd. Tooled code with error messages.
1 parent ec6e66a commit f2ed9d5

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- "0.6"
34
- "0.8"
45
- "0.10"
56
- "0.11"

index.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var repo_url = "[email protected]:Marak/colors.js.git";
22
var repo_path = process.env["HOME"]+"/.cfi";
33
(function () {
4-
console.log(repo_path);
54
//Logic for executing the file
65
var args = process.argv.splice(2);
76
switch(args[0]) {
@@ -34,6 +33,8 @@ function help() {
3433

3534
//maintainRepo ensures our repo is being maintained and is updated
3635
function maintainRepo(callback) {
36+
//TODO: Ensure git is installed
37+
3738
//File system maintenence
3839
var fs = require('fs');
3940
try {
@@ -50,30 +51,34 @@ function maintainRepo(callback) {
5051
try {
5152
process.chdir(repo_path);
5253
} catch(error) {
54+
console.log("Could not change directory to git repo!");
5355
//TODO: handle error
5456
}
55-
//TODO: Ensure git is installed
57+
5658
var exec = require('child_process').exec;
5759
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);
6361
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);
6963
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+
}
7573
callback();
7674
})
7775
});
7876
});
7977
}
78+
79+
function execResult(error, stdout,stderr) {
80+
if(error!=null) {
81+
return false;
82+
}
83+
return true;
84+
}

0 commit comments

Comments
 (0)