Skip to content

Commit

Permalink
fix: apply --first-parent filter to commits
Browse files Browse the repository at this point in the history
closes #20
  • Loading branch information
antongolub committed Jul 14, 2020
1 parent 8430857 commit 01aa116
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ function createInlinePluginCreator(packages, multiContext) {
*/
const analyzeCommits = async (pluginOptions, context) => {
// Filter commits by directory.
commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead);
commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead, context.branch.name);
// context.logger.log("filtered commits", JSON.stringify(commits, null, 2));

// Set context.commits so analyzeCommits does correct analysis.
context.commits = commits;
Expand Down
5 changes: 3 additions & 2 deletions lib/getCommitsFiltered.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const cleanPath = require("./cleanPath");
* @param {string} cwd Absolute path of the working directory the Git repo is in.
* @param {string} dir Path to the target directory to filter by. Either absolute, or relative to cwd param.
* @param {string|void} lastHead The SHA of the previous release
* @param {string|void} branch first-parent to determine which merges went into master
* @return {Promise<Array<Commit>>} The list of commits on the branch `branch` since the last release.
*/
async function getCommitsFiltered(cwd, dir, lastHead = undefined) {
async function getCommitsFiltered(cwd, dir, lastHead = undefined, branch = "master") {
// Clean paths and make sure directories exist.
check(cwd, "cwd: directory");
check(dir, "dir: path");
Expand All @@ -43,7 +44,7 @@ async function getCommitsFiltered(cwd, dir, lastHead = undefined) {
// Use git-log-parser to get the commits.
const relpath = relative(root, dir);
const stream = gitLogParser.parse(
{ _: [lastHead ? `${lastHead}..HEAD` : "HEAD", "--", relpath] },
{ _: ["--first-parent", branch, lastHead ? `${lastHead}..HEAD` : "HEAD", "--", relpath] },
{ cwd, env: process.env }
);
const commits = await getStream.array(stream);
Expand Down

0 comments on commit 01aa116

Please sign in to comment.