Skip to content

Commit

Permalink
feat: apply --first-parent filter to commits
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jul 14, 2020
1 parent 5a200ab commit 14a896b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ function createInlinePluginCreator(packages, multiContext) {
* @internal
*/
const analyzeCommits = async (pluginOptions, context) => {
const { logger } = context;

// Filter commits by directory.
commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead);
logger.log("filtered commits", JSON.stringify(commits, null, 2));
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 14a896b

Please sign in to comment.