Skip to content

Commit a22e813

Browse files
committed
fix(init): require explicit choice when stored and detected values conflict
When .cf/project.json and the workspace (e.g. git remote) disagree, the prompt now shows both and Enter accepts the detected value (ground truth). Type `k`/`keep` to keep the stored value instead. Previously Enter would silently keep the stale stored value, which let wrong github_repo_url values persist through repeated `cf init` runs. Made-with: Cursor
1 parent 78eea92 commit a22e813

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ cf init [--project-root DIRECTORY] [--shuttle NAME_OR_ID] [--description TEXT]
249249
**What it does:**
250250
- **Idempotent refresh**: Running `cf init` again on an already-linked project pulls in the current platform values, pre-fills prompts, and only PUTs the differences you confirm. The `platform_project_id` link is preserved.
251251
- **Smart defaults**: Auto-detects project name from directory, project type from GDS files, and GitHub repo URL from your `origin` remote (HTTPS or SSH).
252-
- **Interactive prompts**: Blank input keeps the current/detected value; type `clear` to explicitly remove a field.
252+
- **Interactive prompts**:
253+
- When a stored value and a detected value match (or only one exists), press Enter to accept it.
254+
- When they **differ** (e.g. a stale `github_repo_url` in `.cf/project.json` vs. your current `git remote`), the prompt shows both and Enter accepts the detected value (ground truth). Type `k` or `keep` to keep the current value instead, type a new value to override, or type `clear` to remove the field entirely.
253255
- **Shuttle selection**: On first init, prompts to select an available shuttle (sorted by nearest deadline).
254256
- **Platform registration**: Creates the project on the platform and links it automatically.
255257
- Setting the GitHub repo URL enables `cf precheck --remote` and `cf push --remote`.

chipfoundry_cli/main.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,26 +309,54 @@ def keyview():
309309
_print_manual_key_instructions()
310310

311311
def _prompt_with_default(label: str, current: Optional[str], detected: Optional[str] = None) -> Optional[str]:
312-
"""Interactive prompt that preserves `current` on blank input.
313-
314-
- Enter = keep current (or accept detected when no current).
315-
- Type a value = new value.
316-
- Type 'clear' = explicitly remove the value (returns None).
317-
Returned value is stripped. `clear` is case-insensitive.
312+
"""Interactive prompt with sensible defaults for current/detected values.
313+
314+
Behavior:
315+
- No current, no detected: Enter leaves the value unset (None).
316+
- Only current: Enter keeps current.
317+
- Only detected: Enter accepts detected.
318+
- Current == detected: Enter accepts the (single) value.
319+
- Current != detected: Enter accepts `detected` (ground truth, e.g. git
320+
remote). Type `k` or `keep` to keep current.
321+
Any typed value becomes the new value. `clear` (case-insensitive) explicitly
322+
removes the value (returns None).
318323
"""
319-
effective_default = current if current else detected
320-
hint_parts = []
321-
if current:
322-
hint_parts.append(f"current: [cyan]{current}[/cyan]")
323-
if detected and detected != current:
324-
hint_parts.append(f"detected: [cyan]{detected}[/cyan]")
325-
hint_parts.append("blank=keep, 'clear'=remove")
326-
hint = ", ".join(hint_parts)
327-
raw = console.input(f"{label} ({hint}): ").strip()
324+
normalized_current = current.strip() if isinstance(current, str) and current.strip() else None
325+
normalized_detected = detected.strip() if isinstance(detected, str) and detected.strip() else None
326+
conflict = (
327+
normalized_current is not None
328+
and normalized_detected is not None
329+
and normalized_current != normalized_detected
330+
)
331+
332+
if conflict:
333+
effective_default = normalized_detected
334+
elif normalized_detected is not None:
335+
effective_default = normalized_detected
336+
else:
337+
effective_default = normalized_current
338+
339+
console.print(f"[bold]{label}[/bold]")
340+
if normalized_current:
341+
console.print(f" current: [cyan]{normalized_current}[/cyan]")
342+
if normalized_detected and normalized_detected != normalized_current:
343+
console.print(f" detected: [cyan]{normalized_detected}[/cyan]")
344+
345+
if conflict:
346+
hint = "enter=use detected, k=keep current, clear=remove, or type new value"
347+
elif effective_default:
348+
hint = "enter=accept, clear=remove, or type new value"
349+
else:
350+
hint = "enter=skip, or type value"
351+
352+
raw = console.input(f" [dim]{hint}[/dim]: ").strip()
328353
if raw == "":
329354
return effective_default
330-
if raw.lower() == "clear":
355+
lowered = raw.lower()
356+
if lowered == "clear":
331357
return None
358+
if conflict and lowered in ("k", "keep"):
359+
return normalized_current
332360
return raw
333361

334362

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "chipfoundry-cli"
3-
version = "2.3.14"
3+
version = "2.3.15"
44
description = "CLI tool to automate ChipFoundry project submission to SFTP server"
55
authors = ["ChipFoundry <marwan.abbas@chipfoundry.io>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)