git-watchtower 1.1.0 → 1.2.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/bin/git-watchtower.js +116 -1
- package/package.json +1 -1
package/bin/git-watchtower.js
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
const http = require('http');
|
|
56
56
|
const fs = require('fs');
|
|
57
57
|
const path = require('path');
|
|
58
|
-
const { exec, spawn } = require('child_process');
|
|
58
|
+
const { exec, execSync, spawn } = require('child_process');
|
|
59
59
|
const readline = require('readline');
|
|
60
60
|
|
|
61
61
|
// Casino mode - Vegas-style feedback effects
|
|
@@ -279,9 +279,124 @@ async function runConfigurationWizard() {
|
|
|
279
279
|
console.log('\n✓ Configuration saved to ' + CONFIG_FILE_NAME);
|
|
280
280
|
console.log(' You can edit this file manually or delete it to reconfigure.\n');
|
|
281
281
|
|
|
282
|
+
// Ask user how to handle the new config file in git
|
|
283
|
+
await promptConfigFileHandling();
|
|
284
|
+
|
|
282
285
|
return config;
|
|
283
286
|
}
|
|
284
287
|
|
|
288
|
+
/**
|
|
289
|
+
* After creating .watchtowerrc.json, ask the user how to handle it in git.
|
|
290
|
+
* This prevents the new config file from dirtying the working directory
|
|
291
|
+
* and blocking branch switching.
|
|
292
|
+
*/
|
|
293
|
+
async function promptConfigFileHandling() {
|
|
294
|
+
// Check if we're in a git repo
|
|
295
|
+
try {
|
|
296
|
+
execSync('git rev-parse --git-dir', { cwd: PROJECT_ROOT, stdio: 'pipe' });
|
|
297
|
+
} catch {
|
|
298
|
+
return; // Not a git repo, nothing to do
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
console.log('How should the config file be handled in git?\n');
|
|
302
|
+
console.log(' 1. Keep local (ignore via .git/info/exclude) [recommended]');
|
|
303
|
+
console.log(' 2. Track in repo (commit ' + CONFIG_FILE_NAME + ')');
|
|
304
|
+
console.log(' 3. Add to .gitignore (you\'ll need to commit .gitignore)');
|
|
305
|
+
console.log(' 4. Do nothing (handle manually)\n');
|
|
306
|
+
|
|
307
|
+
const answer = await promptUser('Choice', '1');
|
|
308
|
+
|
|
309
|
+
switch (answer) {
|
|
310
|
+
case '1':
|
|
311
|
+
handleConfigExcludeLocal();
|
|
312
|
+
break;
|
|
313
|
+
case '2':
|
|
314
|
+
await handleConfigCommit();
|
|
315
|
+
break;
|
|
316
|
+
case '3':
|
|
317
|
+
handleConfigGitignore();
|
|
318
|
+
break;
|
|
319
|
+
case '4':
|
|
320
|
+
default:
|
|
321
|
+
console.log(' Skipped. Note: the config file may block branch switching until handled.\n');
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Add .watchtowerrc.json to .git/info/exclude (local-only gitignore)
|
|
328
|
+
*/
|
|
329
|
+
function handleConfigExcludeLocal() {
|
|
330
|
+
try {
|
|
331
|
+
const gitDir = execSync('git rev-parse --git-dir', { cwd: PROJECT_ROOT, encoding: 'utf8' }).trim();
|
|
332
|
+
const excludePath = path.join(PROJECT_ROOT, gitDir, 'info', 'exclude');
|
|
333
|
+
|
|
334
|
+
// Ensure the info directory exists
|
|
335
|
+
const infoDir = path.dirname(excludePath);
|
|
336
|
+
if (!fs.existsSync(infoDir)) {
|
|
337
|
+
fs.mkdirSync(infoDir, { recursive: true });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Check if already excluded
|
|
341
|
+
if (fs.existsSync(excludePath)) {
|
|
342
|
+
const content = fs.readFileSync(excludePath, 'utf8');
|
|
343
|
+
if (content.includes(CONFIG_FILE_NAME)) {
|
|
344
|
+
console.log(' Already excluded in .git/info/exclude.\n');
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Append the exclusion
|
|
350
|
+
const line = '\n# Git Watchtower config (local)\n' + CONFIG_FILE_NAME + '\n';
|
|
351
|
+
fs.appendFileSync(excludePath, line, 'utf8');
|
|
352
|
+
console.log(' ✓ Added ' + CONFIG_FILE_NAME + ' to .git/info/exclude');
|
|
353
|
+
console.log(' Config file will be ignored locally without affecting the repo.\n');
|
|
354
|
+
} catch (e) {
|
|
355
|
+
console.error(' Warning: Could not update .git/info/exclude: ' + e.message);
|
|
356
|
+
console.log(' You may need to handle the config file manually.\n');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Stage and commit .watchtowerrc.json
|
|
362
|
+
*/
|
|
363
|
+
async function handleConfigCommit() {
|
|
364
|
+
try {
|
|
365
|
+
execSync(`git add "${CONFIG_FILE_NAME}"`, { cwd: PROJECT_ROOT, stdio: 'pipe' });
|
|
366
|
+
execSync(`git commit -m "Add git-watchtower configuration"`, { cwd: PROJECT_ROOT, stdio: 'pipe' });
|
|
367
|
+
console.log(' ✓ Committed ' + CONFIG_FILE_NAME + ' to the repository.\n');
|
|
368
|
+
} catch (e) {
|
|
369
|
+
console.error(' Warning: Could not commit config file: ' + (e.message || 'unknown error'));
|
|
370
|
+
console.log(' You may need to commit it manually: git add ' + CONFIG_FILE_NAME + ' && git commit\n');
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Add .watchtowerrc.json to .gitignore
|
|
376
|
+
*/
|
|
377
|
+
function handleConfigGitignore() {
|
|
378
|
+
try {
|
|
379
|
+
const gitignorePath = path.join(PROJECT_ROOT, '.gitignore');
|
|
380
|
+
|
|
381
|
+
// Check if already in .gitignore
|
|
382
|
+
if (fs.existsSync(gitignorePath)) {
|
|
383
|
+
const content = fs.readFileSync(gitignorePath, 'utf8');
|
|
384
|
+
if (content.includes(CONFIG_FILE_NAME)) {
|
|
385
|
+
console.log(' Already listed in .gitignore.\n');
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const line = '\n# Git Watchtower config\n' + CONFIG_FILE_NAME + '\n';
|
|
391
|
+
fs.appendFileSync(gitignorePath, line, 'utf8');
|
|
392
|
+
console.log(' ✓ Added ' + CONFIG_FILE_NAME + ' to .gitignore');
|
|
393
|
+
console.log(' Note: You\'ll need to commit the .gitignore change.\n');
|
|
394
|
+
} catch (e) {
|
|
395
|
+
console.error(' Warning: Could not update .gitignore: ' + e.message);
|
|
396
|
+
console.log(' You may need to add it manually.\n');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
285
400
|
async function ensureConfig(cliArgs) {
|
|
286
401
|
// Check if --init flag was passed (force reconfiguration)
|
|
287
402
|
if (cliArgs.init) {
|
package/package.json
CHANGED