Skip to content

Commit a1652a6

Browse files
committed
fix: ralph command now matches branch name to feature folder
Previously, specify ralph would select the first feature folder found alphabetically (e.g., 001-* over 002-*), ignoring which branch the user was on. Now it: 1. First tries to match the current branch name to a feature folder 2. Falls back to the last folder alphabetically (highest feature number) This ensures working on branch 002-foo uses specs/002-foo/tasks.md instead of incorrectly picking specs/001-bar/tasks.md.
1 parent 16d825a commit a1652a6

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/specify_cli/__init__.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,9 +1364,16 @@ def refresh():
13641364
console.print("[dim]Or run: npm install -g @github/copilot[/dim]")
13651365
raise typer.Exit(1)
13661366

1367-
# Check for tasks.md
1367+
# Check for tasks.md - prioritize matching the current branch name
13681368
cwd = Path.cwd()
13691369

1370+
# First, get the current branch name for matching
1371+
current_branch = None
1372+
try:
1373+
current_branch = run_command(["git", "branch", "--show-current"], capture=True)
1374+
except Exception:
1375+
pass # Will handle branch check later
1376+
13701377
# Try to find spec directory (look for .specify or specs folder pattern)
13711378
spec_dir = None
13721379
tasks_path = None
@@ -1379,12 +1386,23 @@ def refresh():
13791386
# Look in specs/ for feature directories
13801387
specs_dir = cwd / "specs"
13811388
if specs_dir.exists():
1382-
for child in specs_dir.iterdir():
1383-
if child.is_dir() and (child / "tasks.md").exists():
1384-
# Use most recent or only spec directory
1385-
spec_dir = child
1386-
tasks_path = child / "tasks.md"
1387-
break
1389+
# First pass: Try to match branch name to a feature folder
1390+
if current_branch:
1391+
for child in specs_dir.iterdir():
1392+
if child.is_dir() and child.name == current_branch and (child / "tasks.md").exists():
1393+
spec_dir = child
1394+
tasks_path = child / "tasks.md"
1395+
break
1396+
1397+
# If no branch match found, fallback to last alphabetically (most recent feature number)
1398+
if spec_dir is None:
1399+
candidates = sorted(
1400+
[c for c in specs_dir.iterdir() if c.is_dir() and (c / "tasks.md").exists()],
1401+
key=lambda p: p.name
1402+
)
1403+
if candidates:
1404+
spec_dir = candidates[-1]
1405+
tasks_path = spec_dir / "tasks.md"
13881406

13891407
if tasks_path and tasks_path.exists():
13901408
tracker.complete("tasks", f"found: {tasks_path.relative_to(cwd)}")

0 commit comments

Comments
 (0)