ai-cmg 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/dist/index.js +15 -63
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -115,32 +115,6 @@ function isGitAvailable() {
115
115
  return false;
116
116
  }
117
117
  }
118
- function resolveGitDir(repoRoot) {
119
- const gitPath = join(repoRoot, '.git');
120
- if (!existsSync(gitPath))
121
- return null;
122
- try {
123
- const stat = execSync(`test -d "${gitPath}" && echo "dir" || echo "file"`).toString().trim();
124
- if (stat === 'dir')
125
- return gitPath;
126
- }
127
- catch {
128
- // fallthrough to file parsing
129
- }
130
- try {
131
- const content = readFileSync(gitPath, 'utf8').trim();
132
- const match = content.match(/^gitdir:\s*(.+)$/i);
133
- if (!match)
134
- return null;
135
- const gitDirPath = match[1].trim();
136
- return gitDirPath.startsWith('/')
137
- ? gitDirPath
138
- : resolve(repoRoot, gitDirPath);
139
- }
140
- catch {
141
- return null;
142
- }
143
- }
144
118
  function isDiffArgs(args) {
145
119
  return args.includes('diff');
146
120
  }
@@ -152,15 +126,12 @@ function formatGitExecError(error) {
152
126
  const message = err.message ? String(err.message).trim() : '';
153
127
  return [message, stderr].filter(Boolean).join('\n');
154
128
  }
155
- function runGitWithArgs(args) {
156
- return execFileSync('git', args, {
157
- env: getGitEnv(),
158
- maxBuffer: 50 * 1024 * 1024
159
- }).toString();
160
- }
161
129
  function runGit(args, repoRoot) {
162
130
  try {
163
- return runGitWithArgs(['-C', repoRoot, ...args]);
131
+ return execFileSync('git', ['-C', repoRoot, ...args], {
132
+ env: getGitEnv(),
133
+ maxBuffer: 50 * 1024 * 1024
134
+ }).toString();
164
135
  }
165
136
  catch (error) {
166
137
  if (isDiffArgs(args)) {
@@ -169,34 +140,9 @@ function runGit(args, repoRoot) {
169
140
  if (stdout)
170
141
  return stdout;
171
142
  }
172
- const gitDir = resolveGitDir(repoRoot);
173
- if (!gitDir) {
174
- throw new Error(formatGitExecError(error));
175
- }
176
- try {
177
- return runGitWithArgs(['--git-dir', gitDir, '--work-tree', repoRoot, ...args]);
178
- }
179
- catch (fallbackError) {
180
- if (isDiffArgs(args)) {
181
- const err = fallbackError;
182
- const stdout = err.stdout ? String(err.stdout) : '';
183
- if (stdout)
184
- return stdout;
185
- }
186
- throw new Error(formatGitExecError(fallbackError));
187
- }
143
+ throw new Error(formatGitExecError(error));
188
144
  }
189
145
  }
190
- function spawnGit(args, repoRoot) {
191
- const first = spawnSync('git', ['-C', repoRoot, ...args], { stdio: 'inherit', env: getGitEnv() });
192
- if (first.status === 0)
193
- return 0;
194
- const gitDir = resolveGitDir(repoRoot);
195
- if (!gitDir)
196
- return first.status ?? 1;
197
- const second = spawnSync('git', ['--git-dir', gitDir, '--work-tree', repoRoot, ...args], { stdio: 'inherit', env: getGitEnv() });
198
- return second.status ?? 1;
199
- }
200
146
  function findRepoRootByFs(startDir) {
201
147
  let current = resolve(startDir);
202
148
  while (true) {
@@ -349,7 +295,7 @@ async function promptStageFiles(repoRoot) {
349
295
  if (action === 'cancel')
350
296
  return false;
351
297
  if (action === 'all') {
352
- spawnGit(['add', '.'], repoRoot);
298
+ spawnSync('git', ['-C', repoRoot, 'add', '.'], { stdio: 'inherit', env: getGitEnv() });
353
299
  return true;
354
300
  }
355
301
  const fileChoices = candidates.map((entry) => ({
@@ -366,7 +312,7 @@ async function promptStageFiles(repoRoot) {
366
312
  const files = picked.files;
367
313
  if (!files || files.length === 0)
368
314
  return false;
369
- spawnGit(['add', '--', ...files], repoRoot);
315
+ spawnSync('git', ['-C', repoRoot, 'add', '--', ...files], { stdio: 'inherit', env: getGitEnv() });
370
316
  return true;
371
317
  }
372
318
  function getExtension(filePath) {
@@ -571,11 +517,17 @@ async function main() {
571
517
  const action = actions[choice - 1].value;
572
518
  switch (action) {
573
519
  case 'commit':
574
- spawnGit(['commit', '-m', message], repoRoot);
520
+ spawnSync('git', ['-C', repoRoot, 'commit', '-m', message], {
521
+ stdio: 'inherit',
522
+ env: getGitEnv()
523
+ });
575
524
  console.log('Commit complete.');
576
525
  break;
577
526
  case 'edit':
578
- spawnGit(['commit', '-e', '-m', message], repoRoot);
527
+ spawnSync('git', ['-C', repoRoot, 'commit', '-e', '-m', message], {
528
+ stdio: 'inherit',
529
+ env: getGitEnv()
530
+ });
579
531
  console.log('Commit complete.');
580
532
  break;
581
533
  case 'copy':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-cmg",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI Commit Message Generator",
5
5
  "type": "module",
6
6
  "bin": {