Skip to content

Commit

Permalink
feat: allow git-raw-commits to filter on specific paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Mar 6, 2017
1 parent 8e368a5 commit a322021
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/conventional-changelog-express/package.json
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"lint": "jshint *.js --exclude node_modules && jscs *.js",
"test": "mocha && npm run-script lint",
"test": "mocha --timeout=30000 && npm run-script lint",
"test-windows": "echo 'make work on windows'"
},
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions packages/git-raw-commits/README.md
Expand Up @@ -57,6 +57,12 @@ Type: `function`

A function to get debug information.

##### path

Type: `string`

Filter commits to the path provided.


## CLI

Expand Down
15 changes: 9 additions & 6 deletions packages/git-raw-commits/index.js
Expand Up @@ -21,14 +21,17 @@ function gitRawCommits(options) {
var gitFromTo = template('<%- from ? [from, to].join("..") : to %>')(options);

var args = dargs(options, {
excludes: ['from', 'to', 'format']
excludes: ['from', 'to', 'format', 'path']
});

args = [
'log',
gitFormat,
gitFromTo
].concat(args);
var argsPrefix = [gitFormat, gitFromTo];
// allow commits to focus on a single directory
// this is useful for monorepos.
if (options.path) {
argsPrefix.push('--', options.path);
}

args = ['log'].concat(argsPrefix, args);

if (options.debug) {
options.debug('Your git-log command is:\ngit ' + args.join(' '));
Expand Down
1 change: 1 addition & 0 deletions packages/git-raw-commits/package.json
Expand Up @@ -35,6 +35,7 @@
"istanbul": "^0.4.2",
"jscs": "^2.0.0",
"jshint": "^2.8.0",
"mkdirp": "^0.5.1",
"mocha": "*",
"shelljs": "^0.6.0"
},
Expand Down
25 changes: 24 additions & 1 deletion packages/git-raw-commits/test.js
Expand Up @@ -4,6 +4,7 @@ var gitRawCommits = require('./');
var shell = require('shelljs');
var through = require('through2');
var writeFileSync = require('fs').writeFileSync;
var mkdirp = require('mkdirp');

shell.config.silent = true;
shell.rm('-rf', 'tmp');
Expand All @@ -26,7 +27,9 @@ it('should emit an error and the error should not be read only if there is no co
});

it('should execute the command without error', function(done) {
writeFileSync('test1', '');

mkdirp.sync('./packages/foo');
writeFileSync('./packages/foo/test1', '');
shell.exec('git add --all && git commit -m"First commit"');
writeFileSync('test2', '');
shell.exec('git add --all && git commit -m"Second commit"');
Expand Down Expand Up @@ -128,6 +131,26 @@ it('should honour `options.format`', function(done) {
}));
});

it('should allow commits to be scoped to a specific directory', function(done) {
var i = 0;
var output = '';

gitRawCommits({
path: './packages/foo'
})
.pipe(through(function(chunk, enc, cb) {
output += chunk.toString();

i++;
cb();
}, function() {
expect(i).to.equal(1);
expect(output).to.match(/First commit/);
expect(output).to.not.match(/Second commit/);
done();
}));
});

it('should show your git-log command', function(done) {
gitRawCommits({
format: 'what%n%B',
Expand Down

0 comments on commit a322021

Please sign in to comment.