77 */
88
99import { makeConfig } from 'lino-arguments' ;
10- import { setupGitIdentity , isGhAuthenticated , runGhAuthLogin } from './index.js' ;
10+ import { setupGitIdentity , isGhAuthenticated , runGhAuthLogin , verifyGitIdentity } from './index.js' ;
1111
1212// Parse command-line arguments with environment variable and .lenv support
1313const config = makeConfig ( {
@@ -38,6 +38,11 @@ const config = makeConfig({
3838 description : 'Dry run mode - show what would be done without making changes' ,
3939 default : getenv ( 'GH_SETUP_GIT_IDENTITY_DRY_RUN' , false )
4040 } )
41+ . option ( 'verify' , {
42+ type : 'boolean' ,
43+ description : 'Verify current git identity configuration' ,
44+ default : false
45+ } )
4146 . check ( ( argv ) => {
4247 // --global and --local are mutually exclusive
4348 if ( argv . global && argv . local ) {
@@ -48,12 +53,68 @@ const config = makeConfig({
4853 . example ( '$0' , 'Setup git identity globally using GitHub user' )
4954 . example ( '$0 --local' , 'Setup git identity for current repository only' )
5055 . example ( '$0 --dry-run' , 'Show what would be configured without making changes' )
56+ . example ( '$0 --verify' , 'Verify current git identity configuration' )
5157 . help ( 'h' )
5258 . alias ( 'h' , 'help' )
5359 . version ( '0.1.0' )
5460 . strict ( ) ,
5561} ) ;
5662
63+ /**
64+ * Run verification commands and display results
65+ * @param {string } scope - 'global' or 'local'
66+ * @param {boolean } verbose - Enable verbose logging
67+ */
68+ async function runVerify ( scope , verbose ) {
69+ const scopeFlag = scope === 'local' ? '--local' : '--global' ;
70+
71+ console . log ( 'Verifying git identity configuration...' ) ;
72+ console . log ( '' ) ;
73+
74+ // 1. Run gh auth status
75+ console . log ( '1. GitHub CLI authentication status:' ) ;
76+ console . log ( ' $ gh auth status' ) ;
77+ console . log ( '' ) ;
78+
79+ const { spawn } = await import ( 'node:child_process' ) ;
80+
81+ // Run gh auth status interactively to show full output
82+ await new Promise ( ( resolve ) => {
83+ const child = spawn ( 'gh' , [ 'auth' , 'status' ] , { stdio : 'inherit' } ) ;
84+ child . on ( 'close' , resolve ) ;
85+ child . on ( 'error' , resolve ) ;
86+ } ) ;
87+
88+ console . log ( '' ) ;
89+
90+ // 2. Get git config user.name
91+ console . log ( `2. Git user.name (${ scope } ):` ) ;
92+ console . log ( ` $ git config ${ scopeFlag } user.name` ) ;
93+
94+ const identity = await verifyGitIdentity ( { scope, verbose } ) ;
95+
96+ if ( identity . username ) {
97+ console . log ( ` ${ identity . username } ` ) ;
98+ } else {
99+ console . log ( ' (not set)' ) ;
100+ }
101+
102+ console . log ( '' ) ;
103+
104+ // 3. Get git config user.email
105+ console . log ( `3. Git user.email (${ scope } ):` ) ;
106+ console . log ( ` $ git config ${ scopeFlag } user.email` ) ;
107+
108+ if ( identity . email ) {
109+ console . log ( ` ${ identity . email } ` ) ;
110+ } else {
111+ console . log ( ' (not set)' ) ;
112+ }
113+
114+ console . log ( '' ) ;
115+ console . log ( 'Verification complete!' ) ;
116+ }
117+
57118/**
58119 * Main CLI function
59120 */
@@ -62,6 +123,12 @@ async function main() {
62123 // Determine scope
63124 const scope = config . local ? 'local' : 'global' ;
64125
126+ // Handle --verify mode
127+ if ( config . verify ) {
128+ await runVerify ( scope , config . verbose ) ;
129+ process . exit ( 0 ) ;
130+ }
131+
65132 // Check if gh is authenticated
66133 const authenticated = await isGhAuthenticated ( { verbose : config . verbose } ) ;
67134
0 commit comments