pull-request-split-advisor 3.2.4 → 3.2.5

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/git.js +38 -16
  2. package/package.json +1 -1
package/dist/git/git.js CHANGED
@@ -243,33 +243,55 @@ export function findCascadeParent(currentBranch, baseBranch) {
243
243
  if (!familyMatch)
244
244
  return null;
245
245
  const familyPrefix = `${familyMatch[1]}/${familyMatch[2].toUpperCase()}`;
246
- // Listar todas las ramas locales
247
- const raw = shSafe("git branch --format=%(refname:short)");
248
- if (!raw)
249
- return null;
250
- const candidates = raw
251
- .split("\n")
252
- .map((b) => b.trim())
253
- .filter((b) => b &&
254
- b !== currentBranch &&
255
- b.toUpperCase().startsWith(familyPrefix.toUpperCase()));
246
+ // Construir lista de ramas locales Y remotas para no perder ramas hermanas
247
+ // que existen en el remoto pero aún no han sido descargadas localmente.
248
+ // Para cada entrada guardamos { name, ref }:
249
+ // - name: nombre de la rama sin prefijo de remoto (para mostrar al usuario y para checkout)
250
+ // - ref: ref resolvible por git (local: igual al name; remota: "origin/feature/…")
251
+ const branches = [];
252
+ // Ramas locales
253
+ const localRaw = shSafe("git branch --format=%(refname:short)");
254
+ for (const b of localRaw.split("\n").map((s) => s.trim()).filter(Boolean)) {
255
+ branches.push({ name: b, ref: b });
256
+ }
257
+ // Ramas remotas (ej. "origin/feature/FASTY-0001-xyz")
258
+ // Se usa el nombre sin el prefijo del remoto (primer segmento hasta "/").
259
+ // Si ya existe la rama localmente, se omite (la ref local tiene precedencia).
260
+ const remoteRaw = shSafe("git branch -r --format=%(refname:short)");
261
+ for (const b of remoteRaw.split("\n").map((s) => s.trim()).filter(Boolean)) {
262
+ const slash = b.indexOf("/");
263
+ if (slash < 0)
264
+ continue;
265
+ const name = b.slice(slash + 1); // "origin/feature/…" → "feature/…"
266
+ if (!name || name.startsWith("HEAD"))
267
+ continue;
268
+ if (!branches.some((x) => x.name === name)) {
269
+ branches.push({ name, ref: b }); // ref = "origin/feature/…" (resolvible sin checkout)
270
+ }
271
+ }
272
+ const candidates = branches.filter(({ name }) => name !== currentBranch &&
273
+ name.toUpperCase().startsWith(familyPrefix.toUpperCase()));
256
274
  if (candidates.length === 0)
257
275
  return null;
258
276
  // De los candidatos, quedarnos con los que tengan commits adelantados
259
- // respecto a la base y ordenarlos por committerdate descendente
260
- const withAhead = candidates.filter((b) => {
261
- const count = shSafe(`git rev-list ${q(baseBranch)}..${q(b)} --count`);
277
+ // respecto a la base y ordenarlos por committerdate descendente.
278
+ // Si la rama solo existe en el remoto, la ref "origin/feature/…" es
279
+ // resolvible directamente por git sin necesidad de checkout local.
280
+ const withAhead = candidates.filter(({ ref }) => {
281
+ const count = shSafe(`git rev-list ${q(baseBranch)}..${q(ref)} --count`);
262
282
  return (parseInt(count, 10) || 0) > 0;
263
283
  });
264
284
  if (withAhead.length === 0)
265
285
  return null;
266
286
  // El más reciente es el que tiene el commit más nuevo
267
287
  const sorted = withAhead.sort((a, b) => {
268
- const dateA = shSafe(`git log -1 --format=%ct ${q(a)}`);
269
- const dateB = shSafe(`git log -1 --format=%ct ${q(b)}`);
288
+ const dateA = shSafe(`git log -1 --format=%ct ${q(a.ref)}`);
289
+ const dateB = shSafe(`git log -1 --format=%ct ${q(b.ref)}`);
270
290
  return (parseInt(dateB, 10) || 0) - (parseInt(dateA, 10) || 0);
271
291
  });
272
- return sorted[0] ?? null;
292
+ // Retornar el nombre sin prefijo de remoto para que el usuario pueda usar
293
+ // "git checkout <name>" y git resuelva automáticamente la ref de tracking.
294
+ return sorted[0]?.name ?? null;
273
295
  }
274
296
  /**
275
297
  * Hace push de una rama local al remoto indicado.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pull-request-split-advisor",
3
- "version": "3.2.4",
3
+ "version": "3.2.5",
4
4
  "description": "CLI that analyses your Git working tree and suggests how to split changes into smaller, reviewable pull requests and commits.",
5
5
  "keywords": [
6
6
  "git",