Skip to content
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
24 changes: 24 additions & 0 deletions src/commands/clear.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
8 changes: 1 addition & 7 deletions src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getStatus } from '@/utils/git.js';
import { storage } from '@/utils/storage.js';
import chalk from 'chalk';
import { Command } from 'commander';
Expand All @@ -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;
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -21,7 +21,8 @@ import { storage } from './utils/storage.js';
.addCommand(start)
.addCommand(status)
.addCommand(finish)
.addCommand(cancel);
.addCommand(cancel)
.addCommand(clear);

program.parse();
})();
7 changes: 7 additions & 0 deletions src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export class GitIntentionalCommitStorage {
await fs.writeJSON(commitsFile, data, { spaces: 2 });
}

async clearCommits(): Promise<void> {
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<void> {
const root = await this.getGitRoot();
await checkIsRepo(root);
Expand Down