gh-setup-git-identity 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # gh-setup-git-identity
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0171f4e: Add `--repair` and `--no-auto-login` CLI options
8
+
9
+ ## New Features
10
+
11
+ ### `--repair` option
12
+
13
+ Repair git identity configuration without triggering the login flow. This is useful when:
14
+
15
+ - Git operations fail with "empty ident name not allowed" error
16
+ - The `user.name` or `user.email` was accidentally cleared or corrupted
17
+ - You want to reconfigure git identity without going through login again
18
+
19
+ The `--repair` option requires existing GitHub CLI authentication.
20
+
21
+ ### `--no-auto-login` option
22
+
23
+ Disable automatic login if not authenticated. Instead of starting the interactive login process, the tool will exit with an error and show manual authentication instructions.
24
+
25
+ This is useful in scripts or automated environments where you want to fail fast rather than wait for an interactive login prompt.
26
+
3
27
  ## 0.7.1
4
28
 
5
29
  ### Patch Changes
package/README.md CHANGED
@@ -93,6 +93,8 @@ Git Identity Options:
93
93
  --local, -l Set git config locally (in current repository)
94
94
  --dry-run, --dry Dry run - show what would be done without making changes
95
95
  --verify Verify current git identity configuration
96
+ --repair Repair git identity without triggering login (requires existing auth)
97
+ --no-auto-login Disable automatic login if not authenticated
96
98
  --verbose, -v Enable verbose output
97
99
 
98
100
  GitHub Authentication Options:
@@ -210,6 +212,33 @@ git config --local user.name
210
212
  git config --local user.email
211
213
  ```
212
214
 
215
+ ### Repairing Configuration
216
+
217
+ If your git identity configuration becomes corrupted or misconfigured (e.g., empty `user.name` or `user.email`), you can use the `--repair` option to fix it without triggering a new login:
218
+
219
+ ```bash
220
+ # Repair git identity using existing authentication
221
+ gh-setup-git-identity --repair
222
+ ```
223
+
224
+ This is useful when:
225
+ - Git operations fail with "empty ident name not allowed" error
226
+ - The `user.name` or `user.email` was accidentally cleared or corrupted
227
+ - You want to reconfigure git identity without going through the login flow again
228
+
229
+ The `--repair` option requires that you're already authenticated with GitHub CLI. If not authenticated, it will show helpful instructions for manual authentication.
230
+
231
+ ### Disabling Auto-Login
232
+
233
+ By default, if you're not authenticated, the tool will automatically start the GitHub CLI login process. You can disable this behavior:
234
+
235
+ ```bash
236
+ # Fail immediately if not authenticated (don't auto-login)
237
+ gh-setup-git-identity --no-auto-login
238
+ ```
239
+
240
+ This is useful in scripts or automated environments where you want to fail fast rather than wait for an interactive login prompt.
241
+
213
242
  ## Library Usage
214
243
 
215
244
  ### Basic Example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gh-setup-git-identity",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "A tool to setup git identity based on current gh user",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/cli.js CHANGED
@@ -44,6 +44,16 @@ const config = makeConfig({
44
44
  description: 'Verify current git identity configuration',
45
45
  default: false
46
46
  })
47
+ .option('repair', {
48
+ type: 'boolean',
49
+ description: 'Repair git identity configuration without triggering login (requires existing authentication)',
50
+ default: false
51
+ })
52
+ .option('no-auto-login', {
53
+ type: 'boolean',
54
+ description: 'Disable automatic login if not authenticated (exit with error instead)',
55
+ default: false
56
+ })
47
57
  // gh auth login options
48
58
  .option('hostname', {
49
59
  type: 'string',
@@ -108,6 +118,8 @@ const config = makeConfig({
108
118
  .example('$0 --scopes repo,user,gist', 'Authenticate with custom scopes')
109
119
  .example('$0 --git-protocol ssh', 'Use SSH protocol for git operations')
110
120
  .example('$0 --with-token < token.txt', 'Authenticate using a token file')
121
+ .example('$0 --repair', 'Repair git identity without triggering login')
122
+ .example('$0 --no-auto-login', 'Fail if not authenticated instead of auto-login')
111
123
  .help('h')
112
124
  .alias('h', 'help')
113
125
  .version('0.1.0')
@@ -186,7 +198,36 @@ async function main() {
186
198
  // Check if gh is authenticated
187
199
  const authenticated = await isGhAuthenticated({ verbose: config.verbose });
188
200
 
201
+ // Determine if auto-login should be disabled
202
+ // --repair implies no auto-login (it's meant to fix config without triggering login)
203
+ // --no-auto-login explicitly disables auto-login
204
+ const skipAutoLogin = config.repair || config.noAutoLogin;
205
+
189
206
  if (!authenticated) {
207
+ if (skipAutoLogin) {
208
+ // In repair mode or with --no-auto-login, don't attempt to login
209
+ console.error('GitHub CLI is not authenticated.');
210
+ if (config.repair) {
211
+ console.error('');
212
+ console.error('The --repair option requires existing authentication.');
213
+ console.error('Please authenticate first using one of these methods:');
214
+ } else {
215
+ console.error('');
216
+ console.error('Automatic login is disabled (--no-auto-login).');
217
+ console.error('Please authenticate manually using one of these methods:');
218
+ }
219
+ console.error('');
220
+ console.error(' # Option 1: Interactive web-based login');
221
+ console.error(` gh auth login -h ${config.hostname} -s ${config.scopes} --git-protocol ${config.gitProtocol} --web`);
222
+ console.error('');
223
+ console.error(' # Option 2: Token-based login');
224
+ console.error(' echo "ghp_your_token" | gh auth login --with-token');
225
+ console.error('');
226
+ console.error(' # Option 3: Use GH_TOKEN environment variable');
227
+ console.error(' export GH_TOKEN="ghp_your_token"');
228
+ process.exit(1);
229
+ }
230
+
190
231
  console.log('GitHub CLI is not authenticated. Starting authentication...');
191
232
  console.log('');
192
233
 
@@ -176,3 +176,20 @@ test('default export contains all functions', async () => {
176
176
  assert.ok(typeof defaultExport.setupGitIdentity === 'function');
177
177
  assert.ok(typeof defaultExport.verifyGitIdentity === 'function');
178
178
  });
179
+
180
+ // Test: CLI --repair and --no-auto-login options are present
181
+ // Note: Full CLI integration tests would require mocking the subprocess
182
+ test('CLI module has --repair and --no-auto-login options', async () => {
183
+ // This test verifies the CLI module syntax is correct and options exist
184
+ const fs = await import('node:fs');
185
+ const cliContent = fs.readFileSync(new URL('../src/cli.js', import.meta.url), 'utf-8');
186
+
187
+ // Verify the new options are defined in the CLI
188
+ assert.ok(cliContent.includes("'repair'"), 'CLI should have --repair option');
189
+ assert.ok(cliContent.includes("'no-auto-login'"), 'CLI should have --no-auto-login option');
190
+
191
+ // Verify the repair/no-auto-login logic is implemented
192
+ assert.ok(cliContent.includes('skipAutoLogin'), 'CLI should have skipAutoLogin logic');
193
+ assert.ok(cliContent.includes('config.repair'), 'CLI should check config.repair');
194
+ assert.ok(cliContent.includes('config.noAutoLogin'), 'CLI should check config.noAutoLogin');
195
+ });