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: check git status before bump if option.all is falsy #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import process from 'node:process'
import symbols from 'log-symbols'
import * as ezSpawn from '@jsdevtools/ez-spawn'
import { version as packageVersion } from '../../package.json'
import type { VersionBumpProgress } from '../types/version-bump-progress'
import { ProgressEvent } from '../types/version-bump-progress'
Expand Down Expand Up @@ -28,6 +29,10 @@ export async function main(): Promise<void> {
process.exit(ExitCode.Success)
}
else {
if (!options.all) {
litingyes marked this conversation as resolved.
Show resolved Hide resolved
checkGitStatus()
}

if (!quiet)
options.progress = options.progress ? options.progress : progress

Expand All @@ -39,6 +44,13 @@ export async function main(): Promise<void> {
}
}

export function checkGitStatus() {
const { stdout } = ezSpawn.sync('git', ['status', '--porcelain'])
if (stdout.trim()) {
throw new Error(`Git working tree is not clean:\n${stdout}`)
}
}

function progress({ event, script, updatedFiles, skippedFiles, newVersion }: VersionBumpProgress): void {
switch (event) {
case ProgressEvent.FileUpdated:
Expand Down