@@ -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