Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit 3c717d0

Browse files
committed
docs(README.md): Update commit message format options
- Add new commit format options: `repo` and `custom` - Explain the `--learn` and `--author` flags for learning repository and author-specific commit styles - Clarify that learned styles will be used for future commits unless overridden with `--format` BREAKING CHANGE: The `--learn` flag now supports both repository-wide and author-specific commit style learning. The learned styles will be used as the default format going forward.
1 parent 8badb3f commit 3c717d0

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,20 @@ The tool supports several commit message formats:
159159
Signed-off-by: John Doe <john@example.com>
160160
```
161161

162-
5. **Repository or Author-Specific**: Learn from repository history or specific author's style
162+
5. **Repository-Specific** (`--learn`): Learn and use the commit style from your repository's history
163163
```
164-
# Learn commit style from repository history
164+
# Learn and use repository-wide commit style
165165
auto-commit --learn
166+
```
166167

167-
# Learn commit style from specific author
168+
6. **Author-Specific** (`--learn --author`): Learn and use a specific author's commit style
169+
```
170+
# Learn and use commit style from specific author
168171
auto-commit --learn --author="user@example.com"
169172
```
170173

174+
The learned styles (both repository and author-specific) are saved and will be used for future commits unless overridden with the `--format` flag.
175+
171176
## Requirements
172177

173178
- Git

main.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export enum CommitFormat {
1010
CONVENTIONAL = 'conventional',
1111
SEMANTIC = 'semantic',
1212
ANGULAR = 'angular',
13-
KERNEL = 'kernel'
13+
KERNEL = 'kernel',
14+
REPO = 'repo',
15+
CUSTOM = 'custom',
1416
}
1517

1618
// Then define all other functions and constants
@@ -463,6 +465,8 @@ async function main(): Promise<void> {
463465
alias: { h: "help" },
464466
});
465467

468+
let selectedFormat = CommitFormat.CONVENTIONAL; // Add this line here
469+
466470
// Handle --help flag
467471
if (flags.help) {
468472
console.log(`
@@ -544,34 +548,40 @@ For more information, visit: https://github.com/sidedwards/auto-commit
544548

545549
// Handle format selection
546550
if (flags.learn) {
547-
// Learning mode - analyze and store the style
548-
const commits = await getCommitHistory(flags.author);
549-
const styleGuide = await analyzeCommitStyle(commits, apiKey);
550-
551-
// Store as both author-specific (if specified) and default style
552-
if (flags.author) {
553-
await storeCommitStyle(styleGuide, flags.author);
551+
try {
552+
const commits = await getCommitHistory(flags.author);
553+
const styleGuide = await analyzeCommitStyle(commits, apiKey);
554+
555+
if (flags.author) {
556+
await storeCommitStyle(styleGuide, flags.author);
557+
await storeDefaultFormat(CommitFormat.CUSTOM);
558+
selectedFormat = CommitFormat.CUSTOM;
559+
console.log(`\nLearned and saved commit style for ${flags.author}`);
560+
console.log(`Using commit format: custom (${flags.author})`);
561+
} else {
562+
// Store repository style and use 'repo' as format
563+
await storeCommitStyle(styleGuide);
564+
await storeDefaultFormat(CommitFormat.REPO);
565+
selectedFormat = CommitFormat.REPO;
566+
console.log("\nLearned and saved commit style from repository");
567+
console.log("Using commit format: repo");
568+
}
569+
} catch (error) {
570+
console.error("Failed to learn commit style:", error);
571+
console.log("Falling back to default commit style...");
554572
}
555-
await storeCommitStyle(styleGuide); // Store as default
556-
557-
// Remove this line - don't force Conventional format
558-
// await storeDefaultFormat(CommitFormat.CONVENTIONAL);
559-
560-
console.log(`\nLearned and saved commit style${flags.author ? ` for ${flags.author}` : ''}`);
561573
} else if (flags.format) {
562-
// Explicit format specified
574+
// Explicit format specified - store both format and its template
563575
const formatInput = flags.format.toLowerCase();
564576
let selectedFormat = CommitFormat.CONVENTIONAL;
565577

566-
// Handle common typos and variations
578+
// Handle format selection as before
567579
if (formatInput.includes('kern')) {
568580
selectedFormat = CommitFormat.KERNEL;
569581
} else if (formatInput.includes('sem')) {
570582
selectedFormat = CommitFormat.SEMANTIC;
571583
} else if (formatInput.includes('ang')) {
572584
selectedFormat = CommitFormat.ANGULAR;
573-
} else if (formatInput.includes('con')) {
574-
selectedFormat = CommitFormat.CONVENTIONAL;
575585
}
576586

577587
const template =
@@ -581,12 +591,10 @@ For more information, visit: https://github.com/sidedwards/auto-commit
581591
CONVENTIONAL_FORMAT;
582592

583593
await storeCommitStyle(template);
584-
// Store the format as default
585594
await storeDefaultFormat(selectedFormat);
586595
}
587596

588597
// Use format flag if provided
589-
let selectedFormat = CommitFormat.CONVENTIONAL; // default
590598
if (typeof flags.format === 'string') { // Type check the flag
591599
const formatInput = flags.format.toLowerCase();
592600
// Handle common typos and variations
@@ -603,8 +611,6 @@ For more information, visit: https://github.com/sidedwards/auto-commit
603611
selectedFormat = await getDefaultFormat() || CommitFormat.CONVENTIONAL;
604612
}
605613

606-
console.log(`Using commit format: ${selectedFormat}`);
607-
608614
if (flags.learn) {
609615
try {
610616
const commits = await getCommitHistory(flags.author);

0 commit comments

Comments
 (0)