Skip to content

Commit 9fadb78

Browse files
authored
Merge pull request #21 from link-foundation/issue-20-8158b9d7900a
feat: add `--verify` option to verify git identity configuration
2 parents 50287c1 + 754730a commit 9fadb78

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

.changeset/add-verify-option.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"gh-setup-git-identity": minor
3+
---
4+
5+
feat: add --verify option to verify git identity configuration
6+
7+
- Added `--verify` CLI option to run all 3 verification commands at once
8+
- Users can now use `gh-setup-git-identity --verify` instead of running individual commands
9+
- Works with `--local` flag for local repository configuration
10+
- Updated README with verification documentation and code blocks

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ gh-setup-git-identity --local
7474
# Preview what would be configured (dry run)
7575
gh-setup-git-identity --dry-run
7676

77+
# Verify current git identity configuration
78+
gh-setup-git-identity --verify
79+
7780
# Enable verbose output
7881
gh-setup-git-identity --verbose
7982
```
@@ -87,6 +90,7 @@ Options:
8790
--global, -g Set git config globally (default: true)
8891
--local, -l Set git config locally (in current repository)
8992
--dry-run, --dry Dry run - show what would be done without making changes
93+
--verify Verify current git identity configuration
9094
--verbose, -v Enable verbose output
9195
--help, -h Show help
9296
--version Show version number
@@ -136,6 +140,36 @@ You can verify your configuration with:
136140
git config --global user.email
137141
```
138142

143+
### Verifying Configuration
144+
145+
You can verify your git identity configuration at any time using:
146+
147+
```bash
148+
gh-setup-git-identity --verify
149+
```
150+
151+
Or by running the three verification commands directly:
152+
153+
```bash
154+
gh auth status
155+
git config --global user.name
156+
git config --global user.email
157+
```
158+
159+
For local repository configuration, use `--local`:
160+
161+
```bash
162+
gh-setup-git-identity --verify --local
163+
```
164+
165+
Or:
166+
167+
```bash
168+
gh auth status
169+
git config --local user.name
170+
git config --local user.email
171+
```
172+
139173
## Library Usage
140174

141175
### Basic Example

src/cli.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { 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
1313
const 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

Comments
 (0)