Skip to content

Use origin/<default_branch> as the base for new, diff, git-log and ship - #108

Merged
frantufro merged 7 commits into
mainfrom
skulk-origin-base
Nov 30, 2026
Merged

frantufro merged 7 commits into
mainfrom
skulk-origin-base

Conversation

@frantufro

Copy link
Copy Markdown
Owner

Why

Nothing kept the base clone's local <default_branch> up to date. Over time it fell behind origin. When that happened:

  • skulk new branched agents from an old commit.
  • skulk diff, git-log and ship compared against the old local branch. Upstream commits the agent already had then showed up as the agent's own changes, and the PR description generated by ship could describe work the agent never did.

What changed

New src/base.rs

sync_base runs one remote script that:

  1. Fetches origin/<default_branch> with a 15s watchdog. The script uses a watchdog because macOS has no timeout. On timeout it kills git's transport children first so nothing is left running.
  2. Reuses recent fetches. It writes a stamp in the git dir for every fetch attempt, failed or not, together with any warning. Another command within 30s skips the fetch and repeats the warning. This means diff --stat followed by diff fetches once, and an unreachable origin costs one timeout, not one per command.
  3. Never falls back to the local branch. If the fetch fails, it uses the last fetched origin/<default_branch> and adds a warning. If that ref doesn't exist at all, the command fails.
  4. Fast-forwards the local branch when it is safe. It uses update-ref guarded by the old sha. If the branch is checked out, read-tree -m -u moves the files, and the ref is rolled back if that step fails. It leaves the branch alone, with a warning, when the branch:
    • has commits that aren't on origin (diverged)
    • is checked out with uncommitted changes (dirty)
    • is checked out in another worktree (checked-out)
    • doesn't exist (missing)
  5. Locks the update per base clone. It uses flock where available. Otherwise it uses a mkdir lock directory, which is treated as stale after a minute. Normal commands skip the update silently if the lock is held.

The branch name is shell-quoted once into $B and only ever expanded inside double quotes or passed as a printf argument. The parsed base sha must be a full 40- or 64-character hex sha, because it is put into later commands unquoted.

Commands

  • new / replay: create the worktree from the fetched sha, with --no-track so the agent's branch doesn't track origin/main.
  • diff, git-log, ship: compare against the fetched sha. Warnings go to stderr in human mode and into warnings in JSON. ship fetches before pushing, so a missing base ref stops it before anything is pushed.
  • pull (without --force): uses the same script, but it always fetches and waits up to 15s for the lock. Every warning becomes an error that explains the cause and how to fix it. This replaces matching on the stderr of git pull --ff-only, so pull can no longer create a merge. --force behaves as before.

JSON output

new, replay, diff, git-log and ship gain these fields:

  • base: the ref used, e.g. "origin/main"
  • base_sha: the commit that ref pointed at
  • base_updated: {from, to} when the local branch was fast-forwarded, otherwise null

diff, git-log and ship also gain warnings (new and replay already had it). pull without --force gains the three base fields.

Breaking: git-log's base changes from "main" to "origin/main".

Docs

The README has a new "The base branch" section, and its config, command and JSON tables are updated. The plugin skill's diff comment is updated too.

Tests

  • Unit tests: mock-driven tests that check call order, that nothing falls back to the local branch, that ship doesn't push after a failed sync, and that pull's error messages match each warning kind.
  • Script tests: run the real script against throwaway repos. They cover a branch name full of shell metacharacters, quoting in warnings, the mkdir lock (taking it, skipping while it is held, breaking a stale one), reusing a failed fetch within 30s, and a missing local branch.
  • CLI tests in tests/cli_json.rs cover:
    • stale local main with diff, git-log, new and ship
    • reusing a recent fetch
    • an unreachable origin, in JSON and human output
    • diverged and dirty base clones
    • another branch checked out
    • a held lock
    • pull fast-forwarding and refusing

🤖 Generated with Claude Code

bzWorkspace agents and others added 7 commits November 30, 2026 12:29
…ult_branch>

The base clone's local default branch is never updated, so diffing against
it pulled in every commit it was behind. diff and git-log now fetch
origin/<default_branch> first (reusing a fetch from the last 30 s, giving
up after 15 s) and use it as the base. A failed fetch falls back to the
last fetched ref with a warning, never to the local branch.

While there, the local default branch is fast-forwarded under a flock when
that is safe; diverged or dirty branches are left alone with a warning.
JSON results report base, base_sha, base_updated and warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`skulk new` (and `replay`) used to branch from the base clone's local
default branch, which drifts behind. They now fetch origin/<default_branch>
and create the worktree from it with --no-track, fast-forwarding the local
branch when safe. Fetch warnings join the JSON warnings, and the result
reports base, base_sha and base_updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lt_branch>

ship fed claude the diff against the base clone's stale local default
branch, so descriptions covered unrelated upstream commits. It now fetches
origin/<default_branch> before pushing and diffs against it. The JSON
result reports base, base_sha, base_updated and warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ay why not

pull used `git pull --ff-only origin <branch>`, which fast-forwards
whatever branch the base clone has checked out. It now goes through the
same base sync as new/diff/git-log/ship: it always fetches, waits for the
lock, and fast-forwards the local default branch itself (merge when checked
out, guarded update-ref otherwise). Diverged history, uncommitted changes,
a failed fetch or a busy lock are errors that say why. --force still
hard-resets. The JSON result adds base, base_sha and base_updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Quote default_branch once into $B and pass it to printf as an argument,
  so a branch name with ; ' % $ ` or " can neither break nor inject.
- Stamp failed and timed-out fetches too, with their warning, so commands
  within 30 s reuse the last fetched ref and repeat the warning instead of
  each waiting out the timeout.
- Fall back to a mkdir lock (removed on exit, broken after a minute) where
  flock is missing, and move the branch with an update-ref guarded by the
  old sha, then read-tree -m -u when it is checked out, undoing the ref if
  the files can't follow.
- Report a missing local branch as a "missing" warning; pull refuses with
  how to create it instead of claiming it is up to date.
- Accept only a full hex sha as the base.
- Restore the pull tests for a connectivity error in the base clone check
  and for an unknown sync error keeping its stderr, and the other dropped
  pull tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They used to name origin/<default_branch> in a second round-trip, so a
fetch in between could make them use a different commit than the base_sha
they report. They now take the sha the base sync returned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frantufro
frantufro merged commit eb40e63 into main Nov 30, 2026
8 of 10 checks passed
@frantufro
frantufro deleted the skulk-origin-base branch November 30, 2026 17:41
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.

1 participant