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

feat: add param to require clean working dir (#92) #93

Merged
merged 1 commit into from
Aug 22, 2023
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ npx changelogen@latest [...args] [--dir <dir>]
- `--from`: Start commit reference. When not provided, **latest git tag** will be used as default.
- `--to`: End commit reference. When not provided, **latest commit in HEAD** will be used as default.
- `--dir`: Path to git repository. When not provided, **current working directory** will be used as as default.
- `--clean`: Determine if the working directory is clean and if it is not clean, exit.
- `--output`: Changelog file name to create or update. Defaults to `CHANGELOG.md` and resolved relative to dir. Use `--no-output` to write to console only.
- `--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`.
Expand Down
9 changes: 9 additions & 0 deletions src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { execa } from "execa";
import {
loadChangelogConfig,
getGitDiff,
getCurrentGitStatus,
parseCommits,
bumpVersion,
generateMarkDown,
Expand All @@ -26,6 +27,14 @@ export default async function defaultMain(args: Argv) {
newVersion: typeof args.r === "string" ? args.r : undefined,
});

if (args.clean) {
const dirty = await getCurrentGitStatus();
if (dirty) {
consola.error("Working directory is not clean.");
process.exit(1);
}
}

const logger = consola.create({ stdout: process.stderr });
logger.info(`Generating changelog for ${config.from || ""}...${config.to}`);

Expand Down
4 changes: 4 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export async function getGitRemoteURL(cwd: string, remote = "origin") {
]);
}

export async function getCurrentGitStatus() {
return await execCommand("git", ["status", "--porcelain"]);
}

export async function getGitDiff(
from: string | undefined,
to = "HEAD"
Expand Down