Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub directory #47

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $ changelog -h
-x, --exclude <types> exclude selected commit types (comma separated)
-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout
-u, --repo-url [url] specify the repo URL for commit links, defaults to checking the package.json
-s, --sub-directory <path> specify a path to be passed into git log
```

It's possible to create a `./CHANGELOG.md` file for a specific commit range:
Expand Down Expand Up @@ -107,6 +108,11 @@ The way that I would recommend using this module would be the way it's being use
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags",
```

### Sub-directory

Setting up the `--sub-directory` flag will run the `git log` command under the specified path.
When combined with the `--file` flag, the input/output file would be ***relative to the sub-directory*** specified in the previous flag.

## Testing

To run the test suite, just clone the repository and run the following:
Expand Down
7 changes: 5 additions & 2 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
'use strict';

var Bluebird = require('bluebird');
var Path = require('path');

var CLI = require('../lib/cli');
var Changelog = require('../lib');
var File = require('../lib/file');

CLI.parse(process.argv);

var filePath = CLI.file !== '-' ? Path.join(CLI.subDirectory, CLI.file) : CLI.file;

return Bluebird.all([
Changelog.generate(CLI),
File.readIfExists(CLI.file)
File.readIfExists(filePath)
])
.spread(function (newLogs, oldLogs) {
return File.writeToFile(CLI.file, newLogs + oldLogs);
return File.writeToFile(filePath, newLogs + oldLogs);
})
.catch(function (err) {
console.error(err);
Expand Down
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ module.exports = CLI
.option('-t, --tag <range>', 'generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)')
.option('-x, --exclude <types>', 'exclude selected commit types (comma separated)', list)
.option('-f, --file [file]', 'file to write to, defaults to ./CHANGELOG.md, use - for stdout', './CHANGELOG.md')
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json');
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json')
.option('-s, --sub-directory <path>', 'specify a path to be passed into git log', '.');
4 changes: 3 additions & 1 deletion lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ exports.getCommits = function (options) {
revisions = tag ? tag + '..HEAD' : '';
}

var gitLogCommand = 'git log -E --format=' + FORMAT + ' ' + revisions + ' -- ' + options.subDirectory;

return CP.execAsync(
'git log -E --format=' + FORMAT + ' ' + revisions,
gitLogCommand,
{
maxBuffer: Number.MAX_SAFE_INTEGER
}
Expand Down
14 changes: 14 additions & 0 deletions test/git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ describe('git', function () {
});
});

it('uses subDirectory for filtering git log command when `-s` / `--sub-directory` option was used', function () {
Sinon.stub(CP, 'execAsync')
.onFirstCall().returns(Bluebird.resolve('1.2.3.4'))
.onSecondCall().returns(Bluebird.resolve(VALID_COMMITS));

var subDirectory = 'subdirectory';

return Git.getCommits({ subDirectory: subDirectory })
.then(function () {
CP.execAsync.secondCall.calledWithMatch(new RegExp('-- ' + subDirectory + '$'));
CP.execAsync.restore();
});
});

});

});