Skip to content

Commit

Permalink
Merge pull request #73 from jimthedev/master
Browse files Browse the repository at this point in the history
Adds disableAppendPaths option to git.commit.
  • Loading branch information
stevelacy committed Apr 20, 2015
2 parents ef69604 + fd05c7b commit 56a2d22
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ gulp.task('commit', function(){
}));
});

// Run git commit without appending a path to the commits
gulp.task('commit', function(){
return gulp.src('./git-test/*')
.pipe(git.commit('initial commit', {
disableAppendPaths: true
}));
});


// Run git remote add
// remote is the remote repo
// repo is the https url of the repo
Expand Down Expand Up @@ -277,7 +286,7 @@ Commits changes to repo

`message`: String, commit message

`opt`: Object (optional) `{args: 'options', cwd: '/cwd/path', quiet: true, disableMessageRequirement: false}`
`opt`: Object (optional) `{args: 'options', cwd: '/cwd/path', quiet: true, disableMessageRequirement: false, disableAppendPaths: false}`

```js
gulp.src('./*')
Expand Down
10 changes: 8 additions & 2 deletions lib/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ module.exports = function(message, opt) {
for (var i = 0; i < numLines; i++) {
messageExpanded += messageEntry(lines[i]);
}
cmd += messageExpanded + opt.args + ' ' + escape(paths);
cmd += messageExpanded + opt.args;
if(!opt.disableAppendPaths) {
cmd += ' ' + escape(paths);
}
} else {
cmd += message + opt.args + ' ' + escape(paths);
cmd += message + opt.args;
if(!opt.disableAppendPaths) {
cmd += ' ' + escape(paths);
}
}
} else if (opt.disableMessageRequirement === true) {
cmd += opt.args;
Expand Down
15 changes: 15 additions & 0 deletions test/_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,27 @@ var testFiles = (function(){
return testFiles;
}).call(this);

var testOptionsFiles = (function(){
var testFiles = [];
for (var i = 0; i < 10; i++) {
testFiles[i] = {
base: 'test/repo',
cwd: 'test/repo',
path: __dirname + '/repo/test.options.' + i + '.js',
contents: new Buffer(fileContents())
};
fs.openSync(testFiles[i].path, 'w');
}
return testFiles;
}).call(this);


module.exports = {
repo: repo,
fileContents: fileContents(),
testCommit: path.join(repo, '.git', 'COMMIT_EDITMSG'),
testFiles: testFiles,
testOptionsFiles: testOptionsFiles,
testSuite: function(){
var testSuite = fs.readdirSync(__dirname);
var testFirst = [
Expand Down
20 changes: 20 additions & 0 deletions test/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var rimraf = require('rimraf');
var should = require('should');
var gutil = require('gulp-util');
var exec = require('child_process').exec;

module.exports = function(git, util){

Expand Down Expand Up @@ -53,4 +54,23 @@ module.exports = function(git, util){
gitS.end();
});

it('should commit a file to the repo when appending paths is disabled', function(done) {
var fakeFile = util.testOptionsFiles[4];
exec('git add ' + fakeFile.path, {cwd: './test/repo/'},
function (error, stdout, stderr) {
var opt = {cwd: './test/repo/', disableAppendPaths: true};
var gitS = git.commit('initial commit', opt);
gitS.on('end', function(err) {
if(err) {console.error(err); }
setTimeout(function(){
fs.readFileSync(util.testCommit)
.toString('utf8')
.should.match(/initial commit/);
done();
}, 100);
});
gitS.write(fakeFile);
gitS.end();
});
});
};

0 comments on commit 56a2d22

Please sign in to comment.