Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ npx changelogen@latest [...args] [--dir <dir>]
- `--noAuthors`: Skip contributors section in changelog.
- `--bump`: Determine semver change and update version in `package.json`.
- `--release`. Bumps version in `package.json` and creates commit and git tags using local `git`. You can disable commit using `--no-commit` and tag using `--no-tag`. You can enable the automatic push of the new tag and release commit to your git repository by adding `--push`.
- `--onlyMerges`: Use merge commits in changelog.
- `--noMerges`: Exclude merge commits in changelog.
- `--publish`. Publishes package as a new version on `npm`. You will need to set authorisation tokens separately via `.npmrc` or environment variables.
- `--publishTag` Use custom npm tag for publishing (Default is `latest`)
- `--nameSuffix`: Adds suffix to package name (Example: `--nameSuffix canary` renames `foo` to `foo-canary`)
Expand Down
10 changes: 9 additions & 1 deletion src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ export default async function defaultMain(args: Argv) {
const logger = consola.create({ stdout: process.stderr });
logger.info(`Generating changelog for ${config.from || ""}...${config.to}`);

const rawCommits = await getGitDiff(config.from, config.to, config.cwd);
let onlyMerges: boolean;
if (args.onlyMerges) {
onlyMerges = true;
}
if (args.noMerges) {
onlyMerges = false;
}

const rawCommits = await getGitDiff(config.from, config.to, config.cwd, onlyMerges);

// Parse commits as conventional commits
const commits = parseCommits(rawCommits, config)
Expand Down
15 changes: 12 additions & 3 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,21 @@ export async function getCurrentGitStatus(cwd?: string) {
export async function getGitDiff(
from: string | undefined,
to = "HEAD",
cwd?: string
cwd?: string,
onlyMerges?: boolean
): Promise<RawGitCommit[]> {
let mergeFilter = "";
if (onlyMerges === true) {
mergeFilter = "--merges";
}
if (onlyMerges === false) {
mergeFilter = "--no-merges";
}

// https://git-scm.com/docs/pretty-formats
const r = execCommand(
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status`,
cwd
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status ${mergeFilter}`,
cwd,
);
return r
.split("----\n")
Expand Down