Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ gulp.task('subtree', function () {
## Options

Options can be passed into subtree to choose the remote, branch, and message to push with. By default, it's `origin`, `gh-pages`, and `'Distribution Commit'`.
By default gulp subtree creates a temporary commit to pick up any generated files. Use the skipCommit flag if you wish to skip this.

```js
var subtree = require('gulp-subtree');
Expand All @@ -37,7 +38,8 @@ gulp.task('subtree', function () {
.pipe(subtree({
remote: 'upstream',
branch: 'master',
message: 'Here We Go!'
message: 'Here We Go!',
skipCommit: false
}))
.pipe(clean());
});
Expand Down
74 changes: 44 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,45 @@ var chalk = require('chalk');
// Execute with Callback
//////////////////////////////
function execute(command, callback){
exec(command, function(error, stdout, stderr){ callback(stdout); });
exec(command, function(error, stdout, stderr){
console.log(error);
callback(stdout);
});
};

module.exports = function (options) {
return es.map(function (file, cb) {
//////////////////////////////
// Finish Deploy
//////////////////////////////
var deployStart = function() {
execute('git ls-remote ' + remote + ' ' + branch, function (rmt) {
if (rmt.length > 0) {
gutil.log('Cleaning ' + chalk.cyan(remote) + '/' + chalk.cyan(branch));
execute('git push ' + remote + ' :' + branch, function () {
deployFinish();
});
}
else {
deployFinish();
}
});
};

//////////////////////////////
// Finish Deploy
//////////////////////////////
var deployFinish = function () {
gutil.log('Pushing ' + chalk.magenta(folder) + ' to ' + chalk.cyan(remote) + '/' + chalk.cyan(branch));
execute('git subtree push --prefix ' + folder + ' ' + remote + ' ' + branch, function () {
if (!skipCommit) {
gutil.log('Resetting ' + chalk.magenta(folder) + ' temporary commit');
execute('git reset HEAD^', function () {
return cb(null, file);
});
}
});
};

//////////////////////////////
// Does not work with buffers
Expand All @@ -30,41 +64,21 @@ module.exports = function (options) {
var remote = 'origin';
var branch = 'gh-pages';
var message = 'Distribution Commit';
var skipCommit = false;
if (options !== undefined) {
remote = options.remote || remote;
branch = options.branch || branch;
message = options.message || message;
skipCommit = options.skipCommit || skipCommit;
}



// execute('git add ' + folder, function () {
execute('git add ' + folder + ' && git commit -m "' + message + '"', function () {
gutil.log('Temporarily committing ' + chalk.magenta(folder));
execute('git ls-remote ' + remote + ' ' + branch, function (rmt) {
if (rmt.length > 0) {
gutil.log('Cleaning ' + chalk.cyan(remote) + '/' + chalk.cyan(branch));
execute('git push ' + remote + ' :' + branch, function () {
deployFinish();
});
}
else {
deployFinish();
}
});
});

//////////////////////////////
// Finish Deploy
//////////////////////////////
var deployFinish = function () {
gutil.log('Pushing ' + chalk.magenta(folder) + ' to ' + chalk.cyan(remote) + '/' + chalk.cyan(branch));
execute('git subtree push --prefix ' + folder + ' ' + remote + ' ' + branch, function () {
gutil.log('Resetting ' + chalk.magenta(folder) + ' temporary commit');
execute('git reset HEAD^', function () {
return cb(null, file);
});
if (!skipCommit) {
execute('git add ' + folder + ' && git commit -m "' + message + '"', function () {
gutil.log('Temporarily committing ' + chalk.magenta(folder));
deployStart();
});
};
} else {
deployStart();
}
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-subtree",
"version": "0.1.0",
"version": "0.1.2",
"description": "Gulp module to push a folder to a subtree",
"main": "index.js",
"scripts": {
Expand Down