Skip to content

Commit 275cfdd

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 badd146 commit 275cfdd

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
@@ -1711,9 +1711,16 @@ def refresh():
17111711
console.print("[dim]Or run: npm install -g @github/copilot[/dim]")
17121712
raise typer.Exit(1)
17131713

1714-
# Check for tasks.md
1714+
# Check for tasks.md - prioritize matching the current branch name
17151715
cwd = Path.cwd()
17161716

1717+
# First, get the current branch name for matching
1718+
current_branch = None
1719+
try:
1720+
current_branch = run_command(["git", "branch", "--show-current"], capture=True)
1721+
except Exception:
1722+
pass # Will handle branch check later
1723+
17171724
# Try to find spec directory (look for .specify or specs folder pattern)
17181725
spec_dir = None
17191726
tasks_path = None
@@ -1726,12 +1733,23 @@ def refresh():
17261733
# Look in specs/ for feature directories
17271734
specs_dir = cwd / "specs"
17281735
if specs_dir.exists():
1729-
for child in specs_dir.iterdir():
1730-
if child.is_dir() and (child / "tasks.md").exists():
1731-
# Use most recent or only spec directory
1732-
spec_dir = child
1733-
tasks_path = child / "tasks.md"
1734-
break
1736+
# First pass: Try to match branch name to a feature folder
1737+
if current_branch:
1738+
for child in specs_dir.iterdir():
1739+
if child.is_dir() and child.name == current_branch and (child / "tasks.md").exists():
1740+
spec_dir = child
1741+
tasks_path = child / "tasks.md"
1742+
break
1743+
1744+
# If no branch match found, fallback to last alphabetically (most recent feature number)
1745+
if spec_dir is None:
1746+
candidates = sorted(
1747+
[c for c in specs_dir.iterdir() if c.is_dir() and (c / "tasks.md").exists()],
1748+
key=lambda p: p.name
1749+
)
1750+
if candidates:
1751+
spec_dir = candidates[-1]
1752+
tasks_path = spec_dir / "tasks.md"
17351753

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

0 commit comments

Comments
 (0)