spork-create: bail if local clone already exists

Trying to add remotes to an existing clone gets the origin wrong.
Better to error out and let the user handle it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erich Blume 2026-03-28 23:03:38 -07:00
commit ee6f516b2b

View file

@ -354,56 +354,42 @@ def main(
else: else:
local_path = LOCAL_BASE / repo_name local_path = LOCAL_BASE / repo_name
if local_path.exists(): if local_path.exists():
console.print(f"[yellow]Local directory already exists:[/yellow] {local_path}") console.print(
console.print("Setting up remotes on existing clone...") f"[red]Error:[/red] Local directory already exists: [bold]{local_path}[/bold]"
# Add missing remotes
mirror_url = f"{FORGE_SSH}/{MIRROR_ORG}/{repo_name}.git"
subprocess.run(
["git", "remote", "add", "mirror", mirror_url],
cwd=local_path,
capture_output=True, # may already exist
) )
if upstream_url and upstream_url != "unknown": console.print(
subprocess.run( "Remove it first or use [dim]--no-clone[/dim] to skip local setup."
["git", "remote", "add", "upstream", upstream_url], )
cwd=local_path, raise SystemExit(1)
capture_output=True,
) console.print(f"Cloning to {local_path}...")
clone_url = f"{FORGE_SSH}/{OWNER}/{repo_name}.git"
subprocess.run(
["git", "clone", clone_url, str(local_path)],
check=True,
capture_output=True,
)
# Add mirror and upstream remotes
mirror_url = f"{FORGE_SSH}/{MIRROR_ORG}/{repo_name}.git"
subprocess.run(
["git", "remote", "add", "mirror", mirror_url],
cwd=local_path,
check=True,
capture_output=True,
)
if upstream_url and upstream_url != "unknown":
subprocess.run( subprocess.run(
["git", "fetch", "--all"], ["git", "remote", "add", "upstream", upstream_url],
cwd=local_path,
check=True,
capture_output=True,
)
else:
console.print(f"Cloning to {local_path}...")
clone_url = f"{FORGE_SSH}/{OWNER}/{repo_name}.git"
subprocess.run(
["git", "clone", clone_url, str(local_path)],
check=True,
capture_output=True,
)
# Add mirror and upstream remotes
mirror_url = f"{FORGE_SSH}/{MIRROR_ORG}/{repo_name}.git"
subprocess.run(
["git", "remote", "add", "mirror", mirror_url],
cwd=local_path,
check=True,
capture_output=True,
)
if upstream_url and upstream_url != "unknown":
subprocess.run(
["git", "remote", "add", "upstream", upstream_url],
cwd=local_path,
check=True,
capture_output=True,
)
subprocess.run(
["git", "fetch", "--all"],
cwd=local_path, cwd=local_path,
check=True, check=True,
capture_output=True, capture_output=True,
) )
subprocess.run(
["git", "fetch", "--all"],
cwd=local_path,
check=True,
capture_output=True,
)
console.print(f"[green]Local clone ready at {local_path}[/green]") console.print(f"[green]Local clone ready at {local_path}[/green]")
# Summary # Summary