Permalink
Browse files

get last commit id & committed files listing function

  • Loading branch information...
carlosmarte committed Jun 16, 2013
1 parent 70c8cd1 commit 2ed7ac72e4ffc3341a84bd4293a375f323b1684e
Showing with 117 additions and 7 deletions.
  1. +0 −1 .gitignore
  2. +23 −0 .jshintrc
  3. +94 −6 tasks/git_ftp.js
View
@@ -16,7 +16,6 @@ npm-debug.log
node_modules/
.gitattributes
.jshintrc
.npmignore
.DS_Store
.gitignore
View
@@ -0,0 +1,23 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"es5": true,
"globalstrict":true,
"predef": [
"describe",
"it",
"before",
"beforeEach",
"after",
"afterEach"
]
}
View
@@ -34,6 +34,7 @@ module.exports = function(grunt){
str = require('string'),
ftp = new Ftp_client(),
remote_directories = [],
done = null,
Grunt_git_ftp_class = function(){
this.host_config = null;
@@ -50,6 +51,8 @@ module.exports = function(grunt){
if(host_name != null){
this.host_config = grunt.file.readJSON(filename);
this.host_config._key = host_name;
this.revision_number = null;
this.done = null;
}else{
log.error('Error, please check {' + host_name.red + '} or json file format');
}
@@ -69,6 +72,52 @@ module.exports = function(grunt){
return (this.host_config[this.host_config._key][key] ? this.host_config[this.host_config._key][key] : null);
};
/*
* Command function
*/
Grunt_git_ftp_class.prototype.cmd = function(command,cb,err){
cmd(command,function(error, stdout, stderr){
console.log(stdout.split(/\n/));
if(!error){
cb(stdout);
}else{
err(error);
}
});
};
/*
* Command function
*/
Grunt_git_ftp_class.prototype.cmd_split = function(split,command,cb,err){
cmd(command,function(error, stdout, stderr){
console.log(stdout);
if(!error){
cb(stdout.split(/\n/));
}else{
err(error);
}
});
};
/*
* Command function
*/
Grunt_git_ftp_class.prototype.git_cmd_err = function(err){
log.error(err);
done();
};
/*
* take command output and return array of directories/files
*/
Grunt_git_ftp_class.prototype.extract_git_listing = function(list){
var temp = typeof(list.split(/\n/));
return temp; //String(list).split(/\n/);
};
App = new Grunt_git_ftp_class();
grunt.registerMultiTask('git_ftp','queries last git commit and FTPs modified files to server',function(){
@@ -77,7 +126,9 @@ module.exports = function(grunt){
var options = this.options({
'host_file':'.gitftppass',
'host':'default'
}),done = this.async();
});
done = this.async();
//get host file
if(App.get_host_file(options.host,options.host_file) === null){
@@ -96,11 +147,48 @@ module.exports = function(grunt){
//FTP is ready
ftp.on('ready',function(){
log.ok('Connected to ftp host: ' + App.ftp('host').green);
done();
});
//callbacks
grunt.util.async.waterfall([
function(callback){
//get last commited revision number
App.cmd('git rev-parse --verify HEAD',function(output){
//revision_number trim and toString
App.revision_number = str(output).toString();
//check string length
if(App.revision_number.length !== 0){
//notify user
log.ok('git last commit HASH: ' + App.revision_number.blue);
//get list of commited files/directories
App.cmd('git diff-tree --no-commit-id --name-only -r ' + App.revision_number,function(output){
//check output length
if(output.length !== 0){
//Get List of commited items
App.last_commited_items = App.extract_git_listing(output); //App.extract_git_listing(str(output).toString());
//next callback
callback(null,App.extract_git_listing(App.last_commited_items));
}else{
log.error('Error while getting Git Commited items');
callback(true);
}
},App.git_cmd_err);
}else{
log.error('Error while getting Git Commit Hash');
callback(true);
}
},App.git_cmd_err);
},function(arg_last_commited,callback){
console.log(arg_last_commited);
callback(null,1);
}],function(err,result){ //Completed
console.log(result);
done();
}
);
});
});
};
};

0 comments on commit 2ed7ac7

Please sign in to comment.