threadlines 0.1.18 → 0.1.19

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 +33 -3
  2. package/package.json +1 -1
package/dist/git/diff.js CHANGED
@@ -98,6 +98,27 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
98
98
  // In CI environments, prioritizes remote refs since local branches often don't exist
99
99
  async function detectBaseBranch(git, branchName) {
100
100
  const isCI = !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.VERCEL || process.env.GITLAB_CI);
101
+ const isVercel = !!process.env.VERCEL;
102
+ // Vercel-specific strategy: Try multiple approaches with clear logging
103
+ // Once we know what works, we'll remove the approaches that don't work
104
+ if (isVercel) {
105
+ console.log(`[DEBUG] Vercel environment detected - trying Vercel-specific base branch detection for '${branchName}'`);
106
+ // Strategy 3: Try using local main (maybe Vercel already has it checked out)
107
+ try {
108
+ console.log(`[DEBUG] Vercel: Checking if local 'main' branch exists...`);
109
+ await git.revparse(['main']);
110
+ console.log(`[DEBUG] Vercel: Found local 'main' branch - using as base`);
111
+ return 'main';
112
+ }
113
+ catch (error) {
114
+ console.log(`[DEBUG] Vercel: Local 'main' branch not found: ${error.message || 'does not exist'}`);
115
+ }
116
+ // All Vercel-specific strategies failed - fail loudly
117
+ throw new Error(`Vercel: Base branch 'main' is not available in the git repository. ` +
118
+ `Vercel CI does not have the base branch checked out or fetched. ` +
119
+ `Tried: local 'main' branch. ` +
120
+ `This is a Vercel CI limitation - the base branch needs to be available for comparison.`);
121
+ }
101
122
  // Strategy 1: Try upstream tracking branch (most reliable if set)
102
123
  try {
103
124
  const upstream = await git.revparse(['--abbrev-ref', '--symbolic-full-name', `${branchName}@{u}`]);
@@ -156,15 +177,15 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
156
177
  catch (error) {
157
178
  console.log(`[DEBUG] Default branch (refs/remotes/origin/HEAD) not configured: ${error.message || 'not found'}`);
158
179
  }
159
- // Strategy 3: Try common branch names by checking remote refs first (most reliable fallback)
180
+ // Strategy 3: Try common branch names by checking remote refs first, then local branches
160
181
  // This works reliably in CI with fetch-depth: 0, and also works locally
161
182
  const commonBases = ['main', 'master', 'develop'];
162
183
  for (const candidate of commonBases) {
163
184
  if (candidate.toLowerCase() === branchName.toLowerCase()) {
164
185
  continue; // Skip if it's the same branch
165
186
  }
187
+ // Try remote ref first
166
188
  try {
167
- // Always check remote ref first (this is reliable in CI with fetch-depth: 0)
168
189
  await git.revparse([`origin/${candidate}`]);
169
190
  // In CI, prefer remote refs since local branches often don't exist
170
191
  if (isCI) {
@@ -184,7 +205,16 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
184
205
  }
185
206
  catch (error) {
186
207
  console.log(`[DEBUG] Remote branch 'origin/${candidate}' not found: ${error.message || 'does not exist'}`);
187
- // Continue to next candidate
208
+ // If remote doesn't exist, also try local branch (especially for CI like Vercel)
209
+ try {
210
+ await git.revparse([candidate]);
211
+ console.log(`[DEBUG] Remote 'origin/${candidate}' not available, but local branch '${candidate}' found - using local`);
212
+ return candidate;
213
+ }
214
+ catch (localError) {
215
+ console.log(`[DEBUG] Local branch '${candidate}' also not found: ${localError.message || 'does not exist'}`);
216
+ // Continue to next candidate
217
+ }
188
218
  }
189
219
  }
190
220
  // All strategies failed - provide clear error with context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threadlines",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Threadline CLI - AI-powered linter based on your natural language documentation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {