Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To keep the skill with a project, copy the folder `skills/prepush-ci-setup/` int

The agent needs a git repository with a remote it can push branches to, and a package index it can reach to install `prepush-ci`. It works on a branch and opens a pull request with the result; it does not push to the default branch.

The agent always stops to ask you two things: to confirm the command that runs the full check, and what pre-push should do on your own machines. It asks more only where the repository leaves something open: which hook manager to use when there are two, the default branch when `origin/HEAD` is unset, and a yes before it removes a hook.
The agent always stops to ask you two things: to confirm the command that runs the full check, and what pre-push should do on your own machines. It asks more only where the repository leaves something open: which hook manager to use when there are two, the default branch when `origin` is missing, cannot be reached, has no default branch, or the clone does not fetch it (a single-branch clone of another branch), and a yes before it removes a hook.

The steps below are the manual core. On top of them the skill finds or writes the command that runs the full check, sets up the services and the preflight so that a missing service fails the check, extends the SessionStart script with dependencies and services, and proves the setup with `doctor`.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Decisions

- **Refresh with `git remote set-head origin --auto`, not `git ls-remote --symref origin HEAD`.** The skill keeps its `symbolic-ref` command and its prefix removal (#113); `set-head --auto` only makes the local record true. `ls-remote` prints `ref: refs/heads/<branch>\tHEAD`, a second parsing rule for the agent to get wrong. The cost is a write to `.git/refs/remotes/origin/HEAD`, which `git clone` itself does.
- **The agent asks when `set-head --auto` fails, even if the stale record still reads.** An unreachable remote must not fall back to a record that may be the very stale value of #127.
- **`init` checks local remote-tracking branches, not the network.** `init` stays fast and offline; `git fetch --prune` keeps `refs/remotes/origin/*` true. A network call in `init` would hang a setup on a plane for a typo check.
- **The check applies only when `origin` has remote-tracking branches, `origin` has the default fetch refspec and the up-to-date ref is `origin/<branch>`.** A repository without a remote, with an empty or never-fetched one, or whose gate is `upstream/<branch>` (a fork) has no evidence the branch is missing there. In a single-branch or shallow clone (`--single-branch -b feature`, `--depth 1`) the refspec names one branch, so `git fetch origin` never brings `main` in and the remote-tracking branches say nothing about what `origin` has: checking them would refuse a good branch with a remedy that does not work (the terminator's break on this change). A refusal on guesswork would block legitimate setups; the cost is that a typo in such a clone is not caught, and `ls-remote` was rejected for the same reason as above (a network call).
- **The interactive default is not changed.** The question still defaults to the branch `origin/HEAD` names; a stale default is refused when accepted, with the same message, and the user types the right name.

## Tools run

git 2.39.5, against a bare remote whose default branch was renamed `master` to `main` after a clone, then `git fetch --prune origin`:

- `git symbolic-ref refs/remotes/origin/HEAD` still prints `refs/remotes/origin/master`; `git for-each-ref refs/remotes/origin` lists `origin/HEAD` and `origin/main`, no `origin/master`.
- `git remote set-head origin --auto` prints `origin/HEAD set to main`, exits 0; the symbolic ref then prints `refs/remotes/origin/main`.
- With `origin/HEAD` deleted (`git remote set-head origin -d`), `symbolic-ref` exits 128; `set-head --auto` sets it again.
- Without a remote `origin`, or with `origin` pointing at a path that is not a repository: `set-head --auto` exits 128.
- Against an empty cloned remote: `error: Cannot determine remote HEAD`, exit 1, and `git for-each-ref refs/remotes` lists nothing.
- **The readme requirement follows the skill's trigger.** The README said the agent asks when `origin/HEAD` is unset; with `set-head --auto` that is no longer the trigger, and an unreachable `origin` makes the agent ask though `origin/HEAD` is set. The README and the skill name one trigger, so a reader is not told two.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Issue: #127

## Why

The setup skill takes `--default-branch` from `git symbolic-ref refs/remotes/origin/HEAD`, a local record that `git fetch --prune` never updates. In a clone that predates a rename of the remote's default branch, the hint yields the old name, `init` accepts it and writes `default_branch = "master"` for a branch that no longer exists. Every push of a trailer commit is then refused by the up-to-date check, and the user was told the setup worked (#1, section 4.1, skill and `init`).

## What Changes

- The skill's `<default branch>` step runs `git remote set-head origin --auto` first, which asks the remote for its default branch and refreshes the local record, and only then `git symbolic-ref refs/remotes/origin/HEAD`. When the first command fails (no `origin`, remote unreachable, remote without a default branch, a clone that does not fetch the default branch), the agent asks the user instead of guessing, as it already does when `origin/HEAD` is unset.
- `init` refuses a default branch, given by flag or typed as the answer, that `origin` lacks: the repository holds remote-tracking branches of `origin`, none of them the named one, `origin` has the default fetch refspec, and the up-to-date ref in effect is `origin/<branch>`. It exits 1 and writes nothing.
- Without remote-tracking branches of `origin` (no remote, an empty remote, a remote never fetched), with a fetch refspec of `origin` that is not the default (a single-branch or shallow clone) or with another up-to-date ref, nothing is checked, so a first `init` in a new repository keeps working.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `skill`: the default branch hint refreshes `origin/HEAD` first; the agent asks when that fails.
- `init`: two added requirements, a default branch that `origin` lacks is refused, and when nothing is checked.
- `readme`: the agent step names the cases in which the agent asks for the default branch, the same as the skill does.

## Impact

- `skills/prepush-ci-setup/SKILL.md`: the `<default branch>` bullet.
- `src/prepush_ci/init_command.py`: one more check on the default branch, next to the branch-name check.
- `README.md`: the sentence on what the agent asks.
- Tests: `tests/integration/skill_spec.py` and the init integration specs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## ADDED Requirements

### Requirement: A default branch that origin lacks
`init` SHALL refuse a default branch, given with `--default-branch` or typed as the answer, when the remote-tracking branches of `origin` (any `refs/remotes/origin/*` other than `HEAD`) exist and none is the named one, unless the next requirement says it is not checked. It SHALL exit 1 with one message naming `default_branch`, the branch and the command `git fetch origin`, and write no file.

#### Scenario: A branch the remote renamed away
- **WHEN** a clone with the default fetch refspec has the remote-tracking branch `origin/main` only and `init --non-interactive --check scripts/ci --default-branch master` runs
- **THEN** it exits 1, the message names `default_branch`, `master` and `git fetch origin`, and no file was created

#### Scenario: A stale default accepted interactively
- **WHEN** a clone with the default fetch refspec has `origin/HEAD` naming `origin/master`, the remote-tracking branch `origin/main` only, and `init --check scripts/ci` runs with an empty line for `default_branch`
- **THEN** it exits 1, the message names `default_branch` and `master`, and no file was created

#### Scenario: A branch origin has
- **WHEN** a clone with the default fetch refspec has the remote-tracking branches `origin/main` and `origin/trunk` and `init --non-interactive --check scripts/ci --default-branch trunk` runs
- **THEN** it exits 0 and the loaded config has default branch `trunk`

### Requirement: When the default branch is not checked
`init` SHALL NOT check the default branch against `origin` when the repository holds no remote-tracking branch of `origin` (no remote, an empty remote, a remote never fetched), when no value of `remote.origin.fetch` is the default `+refs/heads/*:refs/remotes/origin/*` (a single-branch or shallow clone, a narrowed fetch: the remote-tracking branches then say nothing about what `origin` has), or when the up-to-date ref in effect is not `origin/<branch>`.

#### Scenario: No remote-tracking branches
- **WHEN** the repository has no remote, or a remote `origin` whose branches were never fetched, and `init --non-interactive --check scripts/ci --default-branch trunk` runs
- **THEN** it exits 0 and the loaded config has default branch `trunk`

#### Scenario: A single-branch clone
- **WHEN** a clone made with `--single-branch -b feature` holds the remote-tracking branch `origin/feature` only, with the fetch refspec `+refs/heads/feature:refs/remotes/origin/feature`, and `init --non-interactive --check scripts/ci --default-branch main` runs
- **THEN** it exits 0 and the loaded config has default branch `main`

#### Scenario: Another up-to-date ref
- **WHEN** a clone with the default fetch refspec has the remote-tracking branch `origin/main` only and `init --non-interactive --check scripts/ci --default-branch trunk --require-up-to-date upstream/trunk` runs
- **THEN** it exits 0 and the loaded config has default branch `trunk`
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## MODIFIED Requirements

### Requirement: The agent step says what the agent asks
The agent step SHALL say that the agent always stops to ask the user to confirm the full check command and what pre-push should do on their own machines, and asks more only where the repository leaves something open: the hook manager when there are two, the default branch when `origin` is missing, cannot be reached, has no default branch, or the clone does not fetch it (a single-branch clone of another branch), and a yes before it removes a hook.

#### Scenario: What the agent always asks
- **WHEN** a reader looks at the agent step
- **THEN** it says the agent always asks the user to confirm the check command and what pre-push should do locally

#### Scenario: What the agent asks only sometimes
- **WHEN** a reader looks at the agent step
- **THEN** it says the agent also asks which hook manager to use when there are two, for the default branch when `origin` is missing, cannot be reached, has no default branch, or the clone does not fetch it (a single-branch clone of another branch), and for a yes before it removes a hook, and not otherwise
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## MODIFIED Requirements

### Requirement: The default branch hint yields a branch name
The `<default branch>` step of the skill SHALL give the commands `git remote set-head origin --auto` and then `git symbolic-ref refs/remotes/origin/HEAD`, SHALL tell the agent to remove the leading `refs/remotes/origin/` from the output of the second before passing it to `--default-branch`, and SHALL say that the first refreshes the local record from the remote. The result SHALL be a value `init` accepts, and the branch the remote has as its default.

#### Scenario: A repository with origin/HEAD
- **WHEN** the test runs the hint's commands in a repository whose remote's default branch is `trunk`, removes the leading `refs/remotes/origin/` and runs the `init` invocation of the skill with the result as the default branch
- **THEN** `init` exits 0 and the loaded config's default branch is `trunk`

#### Scenario: A branch name with a slash
- **WHEN** the same happens in a repository whose remote's default branch is `release/1`
- **THEN** `init` exits 0 and the loaded config's default branch is `release/1`

#### Scenario: A local branch named like the remote branch
- **WHEN** the same happens in a repository whose remote's default branch is `trunk` and which also has a local branch `origin/trunk`
- **THEN** `init` exits 0 and the loaded config's default branch is `trunk`

#### Scenario: A record older than a rename
- **WHEN** the same happens in a clone whose `origin/HEAD` names `origin/master` after the remote renamed its default branch to `main` and the clone ran `git fetch --prune origin`
- **THEN** `init` exits 0 and the loaded config's default branch is `main`

#### Scenario: The step says to remove the prefix
- **WHEN** a reader looks at the `<default branch>` step
- **THEN** it names `git remote set-head origin --auto` before `git symbolic-ref refs/remotes/origin/HEAD` and says to remove the leading `refs/remotes/origin/` from the output of the second

### Requirement: Without origin/HEAD the agent asks
The `<default branch>` step SHALL say that the commands fail when `origin` does not exist, cannot be reached, has no default branch, or the clone does not fetch it (a single-branch clone of another branch), and that the agent then asks the user for the name of the default branch and SHALL NOT guess it, nor read a record that was left from before. If the first command fails the agent SHALL NOT use the output of the second.

#### Scenario: A repository without origin/HEAD
- **WHEN** the test runs the hint's first command in a repository without a remote `origin` (so without `origin/HEAD`)
- **THEN** the command exits non-zero

#### Scenario: A remote that cannot be reached
- **WHEN** the test runs the hint's first command in a repository whose `origin/HEAD` names `origin/master` and whose remote `origin` is a path that is not a repository
- **THEN** the command exits non-zero

#### Scenario: A single-branch clone
- **WHEN** the test runs the hint's first command in a clone made with `--single-branch -b feature` of a remote whose default branch is `main`
- **THEN** the command exits non-zero

#### Scenario: The step says to ask
- **WHEN** a reader looks at the `<default branch>` step
- **THEN** it says the commands fail without a reachable `origin` with a default branch that the clone fetches, to ask the user for the default branch instead of guessing it, and not to use the second command's output when the first failed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Tasks

## 1. The skill refreshes origin/HEAD

- [x] 1.1 Change the `<default branch>` step of `skills/prepush-ci-setup/SKILL.md` to run `git remote set-head origin --auto` before `git symbolic-ref refs/remotes/origin/HEAD` and to ask the user when either fails; verify with a test for every scenario of the two skill requirements

## 2. init refuses a default branch that origin lacks

- [x] 2.1 Make `init` refuse a flag or answer default branch for which `origin` has remote-tracking branches but not that one, when `origin` has the default fetch refspec and the up-to-date ref in effect is `origin/<branch>`, naming `default_branch`, the branch and `git fetch origin`; verify with a test for every scenario of the added requirement
- [x] 2.2 Run `sh scripts/ci` and verify it passes

## 3. The README follows

- [x] 3.1 Change the sentence in `README.md` on what the agent asks to name the same cases as the skill; verify with the `readme` spec for what the agent asks only sometimes

## Workflow follow-up

- Archive the change (`openspec archive 127-default-branch-fresh`) before the pull request is marked ready.
30 changes: 30 additions & 0 deletions openspec/specs/init/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,33 @@ Running `init` again with the same flags SHALL write no file, leave every file w
#### Scenario: The branch name is accepted
- **WHEN** `init --non-interactive --check scripts/ci --default-branch main` runs
- **THEN** it exits 0 and the loaded config has default branch `main`

### Requirement: A default branch that origin lacks
`init` SHALL refuse a default branch, given with `--default-branch` or typed as the answer, when the remote-tracking branches of `origin` (any `refs/remotes/origin/*` other than `HEAD`) exist and none is the named one, unless the next requirement says it is not checked. It SHALL exit 1 with one message naming `default_branch`, the branch and the command `git fetch origin`, and write no file.

#### Scenario: A branch the remote renamed away
- **WHEN** a clone with the default fetch refspec has the remote-tracking branch `origin/main` only and `init --non-interactive --check scripts/ci --default-branch master` runs
- **THEN** it exits 1, the message names `default_branch`, `master` and `git fetch origin`, and no file was created

#### Scenario: A stale default accepted interactively
- **WHEN** a clone with the default fetch refspec has `origin/HEAD` naming `origin/master`, the remote-tracking branch `origin/main` only, and `init --check scripts/ci` runs with an empty line for `default_branch`
- **THEN** it exits 1, the message names `default_branch` and `master`, and no file was created

#### Scenario: A branch origin has
- **WHEN** a clone with the default fetch refspec has the remote-tracking branches `origin/main` and `origin/trunk` and `init --non-interactive --check scripts/ci --default-branch trunk` runs
- **THEN** it exits 0 and the loaded config has default branch `trunk`

### Requirement: When the default branch is not checked
`init` SHALL NOT check the default branch against `origin` when the repository holds no remote-tracking branch of `origin` (no remote, an empty remote, a remote never fetched), when no value of `remote.origin.fetch` is the default `+refs/heads/*:refs/remotes/origin/*` (a single-branch or shallow clone, a narrowed fetch: the remote-tracking branches then say nothing about what `origin` has), or when the up-to-date ref in effect is not `origin/<branch>`.

#### Scenario: No remote-tracking branches
- **WHEN** the repository has no remote, or a remote `origin` whose branches were never fetched, and `init --non-interactive --check scripts/ci --default-branch trunk` runs
- **THEN** it exits 0 and the loaded config has default branch `trunk`

#### Scenario: A single-branch clone
- **WHEN** a clone made with `--single-branch -b feature` holds the remote-tracking branch `origin/feature` only, with the fetch refspec `+refs/heads/feature:refs/remotes/origin/feature`, and `init --non-interactive --check scripts/ci --default-branch main` runs
- **THEN** it exits 0 and the loaded config has default branch `main`

#### Scenario: Another up-to-date ref
- **WHEN** a clone with the default fetch refspec has the remote-tracking branch `origin/main` only and `init --non-interactive --check scripts/ci --default-branch trunk --require-up-to-date upstream/trunk` runs
- **THEN** it exits 0 and the loaded config has default branch `trunk`
Loading
Loading