Skip to content

setup.sh: fork, clone, run one command - #2

Merged
brettheap merged 2 commits into
mainfrom
v0.1/setup-sh
Sep 2, 2026
Merged

brettheap merged 2 commits into
mainfrom
v0.1/setup-sh

Conversation

@brettheap

@brettheap brettheap commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Brett, 2026-09-02: "can we put a setup.sh in the repo so we fork, clone, then
run setup.sh to finish?"
This is exactly that.

gh repo fork opensoft/openRepoShape --org <your-org> --clone
cd openRepoShape
./setup.sh --project Atlas

What it does

It adds no behaviour of its own. It shells out to the same
scripts/validate-repository-naming.py, scaffold-project.py and
make bootstrap that #1 shipped and the README documents, in the same order,
so a person who prefers to run those by hand gets an identical result — the
README's new "What setup.sh does" section is those commands verbatim.

  1. Preflight — git, python3 (≥3.9), make, gh + gh auth status,
    each with a tick or a precise fix hint; exit 2 on a missing prerequisite.
    make absent is a tick, not a failure: bootstrap falls back to
    python3 scripts/bootstrap.py.
  2. Organisation — detected from the clone's own origin via
    gh repo view --json owner --jq .owner.login, falling back to parsing the
    remote URL when offline. --org overrides.
  3. The guard that earns its keep — gh repo fork --clone leaves you in
    your fork; git clone opensoft/openRepoShape leaves you in the upstream;
    from inside the directory those look identical. Scaffolding into opensoft
    refuses unless --allow-upstream-org is passed.
  4. Names checked before anything exists — --explain on all three; a
    finding stops the run before the scaffold.
  5. The plan, and one explicit yes — a real scaffold-project.py --dry-run, then a prompt that accepts that word only. With no terminal and
    no --yes it refuses after showing the plan rather than guessing.
  6. Scaffold, then clone beside the fork (../<Project>, or
    --into <dir>) with --recurse-submodules, then make bootstrap, then a
    final block naming the clone path, the three repository URLs and the next
    commands.

--local-remote-dir <dir> is the test path: three bare repositories on disk,
no network, no gh, no real repository.

Also in this PR

  • tests/test_setup_sh.py — drives the real script end to end through the
    local path and asserts exit 0, the clone where --into says, both legs on
    main after bootstrap, and the degrade line printed; plus every refusal
    (unknown flag, bad visibility, a name outside the policy stopping before
    the scaffold, the upstream-org guard and its --allow-upstream-org escape,
    no-terminal-no---yes, and -- pass-through reaching the scaffold).
  • README — the new-org flow is now fork → clone → ./setup.sh, with the
    manual steps kept underneath as "What setup.sh does".
  • AGENTS.md — an assistant runs setup.sh without --yes and lets the
    human answer its prompt, and never passes --allow-upstream-org on its own
    initiative; if setup.sh refuses on it, stop and relay what it said.
  • tests/test_repo_hygiene.py — setup.sh is executable, starts with
    #!/usr/bin/env bash, carries set -euo pipefail, parses under bash -n,
    and is the front door both docs point at.

Deviation worth flagging

The upstream-org refusal applies in every mode, --local-remote-dir
included. What a local run skips is org detection, not the refusal: --org
is what a scaffolded project.yaml records as the owner of all three legs, so
a manifest reading opensoft/Sample written from an upstream clone is exactly
as wrong as three repositories in the wrong place — and it makes the guard
testable without a network. A local run that names no --org gets the
localorg placeholder, so the guard never fires by surprise.

Tests

python3 -m pytest tests -q

103 passed in 14.26s

🤖 Generated with Claude Code

https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ

Summary by Sourcery

Provide a safe one-command workflow for forking, scaffolding, cloning, and bootstrapping a new project shape.

New Features:

  • Add an executable setup.sh entry point that validates prerequisites and repository names, confirms the plan, scaffolds the three repositories, clones the assembly root, and bootstraps it.
  • Support organisation detection and offline local bare-repository runs, with safeguards against accidentally scaffolding into the upstream organisation and options for custom clone destinations and scaffold arguments.

Enhancements:

  • Update contributor guidance to use setup.sh with human confirmation and prohibit bypassing the upstream-organisation guard without explicit instruction.

Documentation:

  • Document the fork-to-setup workflow and preserve the equivalent manual setup commands.

Tests:

  • Add end-to-end coverage for successful offline setup, cloning, bootstrapping, refusal paths, argument pass-through, and script hygiene.

Brett, 2026-09-02: "can we put a setup.sh in the repo so we fork, clone, then
run setup.sh to finish?" This is that, and nothing more: it shells out to the
same `validate-repository-naming.py`, `scaffold-project.py` and
`make bootstrap` the README already documents, in the same order, adding no
behaviour of its own. The README's new "What setup.sh does" section is those
commands, so a person who prefers to run them by hand gets the same result.

It is the FIRST thing a person runs in a fork, before they know anything about
the repository, so it works with what is on the machine: preflight names git,
python3 (>=3.9), make and gh with a tick or a precise fix hint, and refuses on
a missing one rather than failing halfway through.

THE GUARD THAT EARNS ITS KEEP: `gh repo fork --clone` leaves you in your fork
and `git clone opensoft/openRepoShape` leaves you in the upstream, and from
inside the directory those look identical. The organisation is detected from
the clone's own origin (`gh repo view`, falling back to parsing the remote URL
when offline), and scaffolding into `opensoft` REFUSES unless
`--allow-upstream-org` is passed. That refusal applies in every mode,
`--local-remote-dir` included: what a local run skips is org DETECTION, not
the refusal, because `--org` is what a scaffolded `project.yaml` records as the
owner of all three legs, and a manifest reading `opensoft/Sample` written from
an upstream clone is exactly as wrong as three repositories in the wrong place.

Nothing is created before an explicit `yes`: the plan is a real
`scaffold-project.py --dry-run` and the prompt accepts that word only. With no
terminal and no `--yes` it refuses after showing the plan rather than guessing.

`--local-remote-dir` is the test path — three bare repositories on disk, no
network, no `gh`, no real repository — and `tests/test_setup_sh.py` drives the
script end to end through it: exit 0, the clone where `--into` says, both legs
on `main`, the degrade line printed, plus the refusals (unknown flag, bad
visibility, a name outside the policy stopping BEFORE the scaffold, the
upstream-org guard, no-terminal-no-yes, and `--` pass-through reaching the
scaffold).

AGENTS.md now tells an assistant to run setup.sh WITHOUT `--yes` and let the
human answer its prompt, and never to pass `--allow-upstream-org` on its own
initiative — if setup.sh refuses on it, stop and relay what it said.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ
Copilot AI lite review requested due to automatic review settings September 2, 2026 22:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 18 hours and 19 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces setup.sh as a guarded, confirmation-based orchestration layer for the existing naming validation, scaffolding, cloning, and bootstrap commands, with offline support and comprehensive documentation and tests.

Flow diagram for the setup.sh orchestration

flowchart TD
    A["./setup.sh --project Project"] --> B["Preflight git, python3, make, gh"]
    B --> C["Detect organisation from origin or --org"]
    C --> D{"Upstream organisation?"}
    D -->|"Yes, no escape flag"| X["Refuse before scaffolding"]
    D -->|"No or allowed"| E["Validate Project, Project-spec, Project-code"]
    E --> F{"Naming policy passes?"}
    F -->|"No"| Y["Refuse before repositories exist"]
    F -->|"Yes"| G["Run scaffold-project.py --dry-run"]
    G --> H{"Explicit yes or --yes?"}
    H -->|"No"| Z["Refuse; nothing created"]
    H -->|"Yes"| I["Run scaffold-project.py"]
    I --> J["Clone assembly root with submodules"]
    J --> K["make bootstrap or python3 scripts/bootstrap.py"]
    K --> L["Print clone path, repository URLs, and next commands"]
Loading

File-Level Changes

Change Details Files
Add an executable setup front door that orchestrates repository validation, scaffolding, cloning, and bootstrap while preserving the existing manual workflow.
  • Parse setup options and forward arguments after -- to the scaffold command.
  • Run prerequisite checks with local/offline degradation for missing make and gh.
  • Detect or override the target organization and refuse accidental scaffolding into upstream opensoft unless explicitly allowed.
  • Validate all repository names before creation, show a dry-run plan, and require yes unless --yes is supplied.
  • Create the project, clone the assembly repository beside the fork with submodules, bootstrap it, and print handoff details.
  • Support an offline test mode backed by local bare repositories.
setup.sh
Update contributor and user documentation to make setup.sh the standard new-project workflow while retaining equivalent manual commands.
  • Document fork, clone, and setup.sh usage plus its safety flags and behavior.
  • Add the exact underlying commands in execution order for manual operation.
  • Instruct assistants to require human confirmation and never independently bypass the upstream-organization guard.
  • Update the repository file inventory and bootstrap guidance.
README.md
AGENTS.md
Add coverage for script hygiene, end-to-end setup behavior, and refusal paths.
  • Verify executable mode, Bash shebang, strict mode, syntax validity, and documentation references.
  • Exercise local bare-repository setup through clone and bootstrap, including branch, output, and degrade-line assertions.
  • Cover invalid arguments, invalid visibility, naming failures before scaffold, upstream guard and escape hatch, noninteractive confirmation refusal, and scaffold argument pass-through.
tests/test_setup_sh.py
tests/test_repo_hygiene.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

`test_no_project_and_no_terminal_refuses` ran WITHOUT `--local-remote-dir`, so
it reached the real `gh auth status` preflight and refused for that reason
instead of the one it asserts. It passed on an authenticated laptop and failed
in CI, which is the whole failure mode: a test whose answer depends on who is
logged in is not testing the script.

Fixed, and made a rule rather than a convention:
`test_no_test_here_depends_on_gh_being_authenticated` scans every `run_setup`
call in this file and requires `--local-remote-dir` on all but the three
argument-parsing refusals, which the script answers before it looks at the
machine at all.

Verified both ways: 104 passed with a logged-in `gh`, and 104 passed with
GH_CONFIG_DIR pointed at nothing.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

setup.sh’s --local-remote-dir path can refuse unnecessarily when git config user.name is unset despite common CI Git identity env vars being available, making offline/local runs brittle.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a single setup.sh entry point to make scaffolding a new project from an openRepoShape fork a one-command flow, while keeping the underlying implementation delegated to the existing Python scaffold + bootstrap tooling.

Changes:

  • Add setup.sh to perform preflight checks, org detection (with upstream-org guard), naming validation, dry-run plan display + confirmation, then scaffold/clone/bootstrap.
  • Add end-to-end tests for setup.sh (local/offline path + refusal scenarios) and repo hygiene checks ensuring setup.sh is executable, uses safe shell flags, and is documented.
  • Update README and AGENTS procedure to make setup.sh the primary documented entry point and to codify the “no --yes / no implicit --allow-upstream-org” assistant rules.
File summaries
File Description
tests/test_setup_sh.py End-to-end + refusal-path coverage for the new setup.sh flow using --local-remote-dir.
tests/test_repo_hygiene.py Adds hygiene assertions for setup.sh executability, bash parsing, and documentation references.
setup.sh New top-level orchestrator script wrapping preflight/org detection/plan confirmation/scaffold/clone/bootstrap.
README.md Documents ./setup.sh --project ... as the primary “new org flow” and lists the equivalent manual commands.
AGENTS.md Updates the assistant procedure to route through setup.sh and reinforces guardrails around confirmation and upstream-org protection.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread setup.sh
Comment on lines +240 to +248
if [ -z "$ELECTED_BY" ] && [ "$LOCAL_MODE" -ne 1 ]; then
ELECTED_BY="$(gh api user --jq .login 2>/dev/null || true)"
fi
if [ -z "$ELECTED_BY" ]; then
ELECTED_BY="$(git config user.name 2>/dev/null || true)"
fi
if [ -z "$ELECTED_BY" ]; then
die "cannot work out who is electing this shape. Re-run with --elected-by 'Your Name' — the manifest records whose act it was."
fi
Copilot AI review requested due to automatic review settings September 2, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

There are a couple of concrete reliability issues in setup.sh (notably offline --elected-by fallback and recovery instructions when make is absent) that can cause unexpected refusals or misleading guidance.

Review details

Suppressed comments (2)

Previously missed (1) — in code that hasn't changed since the last review.

setup.sh:329

  • If the clone destination already exists, the refusal message always tells users to run make bootstrap, but earlier preflight explicitly allows make to be absent (and the script later falls back to python3 scripts/bootstrap.py). The recovery instructions should match the detected bootstrap mechanism so users aren’t sent to a command that may not exist.

setup.sh:247

  • In local/offline mode, --elected-by currently falls back only to git config user.name and then refuses if that is unset. This makes setup.sh --local-remote-dir ... brittle in CI or fresh environments where no git identity is configured, even though the script already sets Git author/committer env vars in tests and could use those as a last-resort elector name.
if [ -z "$ELECTED_BY" ]; then
	ELECTED_BY="$(git config user.name 2>/dev/null || true)"
fi
if [ -z "$ELECTED_BY" ]; then
	die "cannot work out who is electing this shape. Re-run with --elected-by 'Your Name' — the manifest records whose act it was."
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants