From 02dcce1c1672cf74b566438318ff500483cc5965 Mon Sep 17 00:00:00 2001 From: kang Date: Mon, 3 Mar 2025 15:25:57 +0900 Subject: [PATCH] feat: add clear command --- src/commands/clear.ts | 24 ++++++++++++++++++++++++ src/commands/index.ts | 1 + src/commands/status.ts | 8 +------- src/index.ts | 5 +++-- src/utils/storage.ts | 7 +++++++ 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/commands/clear.ts diff --git a/src/commands/clear.ts b/src/commands/clear.ts new file mode 100644 index 0000000..08f42be --- /dev/null +++ b/src/commands/clear.ts @@ -0,0 +1,24 @@ +import { storage } from '@/utils/storage'; +import { Command } from 'commander'; +import prompts from 'prompts'; + +const clear = new Command() + .command('clear') + .description('Clear all intentional commits') + .action(async () => { + const response = await prompts({ + type: 'confirm', + name: 'clear', + message: 'Are you sure you want to clear all intentional commits?', + initial: false, + }); + + if (!response.clear) { + return; + } + + await storage.clearCommits(); + console.log('All intentional commits cleared'); + }); + +export default clear; diff --git a/src/commands/index.ts b/src/commands/index.ts index af95832..dfc9a02 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -5,3 +5,4 @@ export { default as status } from './status.js'; export { default as finish } from './finish.js'; export { default as remove } from './remove.js'; export { default as cancel } from './cancel.js'; +export { default as clear } from './clear.js'; diff --git a/src/commands/status.ts b/src/commands/status.ts index e1e39d2..de71aa9 100644 --- a/src/commands/status.ts +++ b/src/commands/status.ts @@ -1,4 +1,3 @@ -import { getStatus } from '@/utils/git.js'; import { storage } from '@/utils/storage.js'; import chalk from 'chalk'; import { Command } from 'commander'; @@ -18,15 +17,10 @@ const status = new Command() console.log(chalk.blue('\nCurrently working on:')); console.log(`ID: ${chalk.blue(currentCommit.id)}`); console.log(`Message: ${currentCommit.message}`); + if (currentCommit.metadata.startedAt) { console.log(`Started: ${new Date(currentCommit.metadata.startedAt).toLocaleString()}`); } - - const gitStatus = await getStatus(); - if (gitStatus) { - console.log('\nGit Status:'); - console.log(gitStatus); - } }); export default status; diff --git a/src/index.ts b/src/index.ts index 74512d4..9694e9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node import { Command } from 'commander'; -import { cancel, create, finish, list, remove, start, status } from './commands/index.js'; +import { cancel, clear, create, finish, list, remove, start, status } from './commands/index.js'; import { getPackageInfo } from './utils/get-package-info.js'; import { storage } from './utils/storage.js'; @@ -21,7 +21,8 @@ import { storage } from './utils/storage.js'; .addCommand(start) .addCommand(status) .addCommand(finish) - .addCommand(cancel); + .addCommand(cancel) + .addCommand(clear); program.parse(); })(); diff --git a/src/utils/storage.ts b/src/utils/storage.ts index d296d90..d04c92c 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -116,6 +116,13 @@ export class GitIntentionalCommitStorage { await fs.writeJSON(commitsFile, data, { spaces: 2 }); } + async clearCommits(): Promise { + const root = await this.getGitRoot(); + const commitsFile = await this.getCommitsFile(); + await fs.remove(commitsFile); + await git.cwd(root).raw(['update-ref', '-d', `${this.REFS_PREFIX}/commits`]); + } + async initializeRefs(): Promise { const root = await this.getGitRoot(); await checkIsRepo(root);