threadlines 0.2.19 → 0.2.20

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/git/diff.js +41 -3
  2. package/package.json +1 -1
package/dist/git/diff.js CHANGED
@@ -190,8 +190,13 @@ async function getPRDiff(repoRoot, targetBranch, logger) {
190
190
  /**
191
191
  * Get diff for a specific commit (or HEAD if no SHA provided).
192
192
  *
193
- * Uses `git show` which works reliably with shallow clones (depth=1).
194
- * This is safer than `HEAD~1...HEAD` which requires depth >= 2.
193
+ * Fetches the parent commit on-demand to ensure git show can generate a proper diff.
194
+ * This works regardless of CI checkout depth settings (depth=1 or depth=2).
195
+ *
196
+ * Strategy:
197
+ * 1. Get parent SHA from commit metadata (git show --format=%P)
198
+ * 2. Fetch parent commit if available (git fetch origin <parentSHA> --depth=1)
199
+ * 3. Use git show to get diff (now parent is available for comparison)
195
200
  *
196
201
  * Used by:
197
202
  * - All CI environments for push/commit context (GitHub, GitLab, Bitbucket, Vercel)
@@ -202,7 +207,40 @@ async function getPRDiff(repoRoot, targetBranch, logger) {
202
207
  */
203
208
  async function getCommitDiff(repoRoot, sha = 'HEAD') {
204
209
  const git = (0, simple_git_1.default)(repoRoot);
205
- // Get diff using git show
210
+ // Fetch parent commit on-demand to ensure git show can generate a proper diff
211
+ // This works regardless of CI checkout depth settings (depth=1 or depth=2)
212
+ // If parent is already available, fetch is fast/no-op; if not, we fetch it
213
+ // Get parent SHA from commit metadata (works even if parent isn't fetched locally)
214
+ let parentSha;
215
+ try {
216
+ parentSha = (0, child_process_1.execSync)(`git show ${sha} --format=%P --no-patch`, {
217
+ encoding: 'utf-8',
218
+ cwd: repoRoot
219
+ }).trim();
220
+ }
221
+ catch (error) {
222
+ const errorMessage = error instanceof Error ? error.message : String(error);
223
+ throw new Error(`Failed to get parent commit SHA for ${sha}. ` +
224
+ `This is required to generate a proper diff. ` +
225
+ `Error: ${errorMessage}`);
226
+ }
227
+ // Fetch parent commit if we have a parent (root commits have no parent)
228
+ if (parentSha && parentSha.length === 40) {
229
+ try {
230
+ // Fetch just this one commit (depth=1 is fine, we only need the parent)
231
+ await git.fetch(['origin', parentSha, '--depth=1']);
232
+ }
233
+ catch (error) {
234
+ const errorMessage = error instanceof Error ? error.message : String(error);
235
+ throw new Error(`Failed to fetch parent commit ${parentSha} from origin. ` +
236
+ `This is required to generate a proper diff in shallow clones. ` +
237
+ `Ensure 'origin' remote is configured and accessible. ` +
238
+ `Error: ${errorMessage}`);
239
+ }
240
+ }
241
+ // If no parent (root commit), git show will show the full commit content
242
+ // This is expected behavior for root commits
243
+ // Get diff using git show (now parent should be available)
206
244
  let diff;
207
245
  let changedFiles;
208
246
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threadlines",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "Threadlines CLI - AI-powered linter based on your natural language documentation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {