Merge remote-tracking branch 'origin/feat/daemon-scope' into feat/native-gui

This commit is contained in:
dasemu committed 2026-11-16 17:30:56 +01:00
commit 23b7970644
26 files changed
+2297 -108

No files matched your search

+30 -1
View File
@@ -59,7 +59,7 @@ they may only contain letters, digits, `-` and `_`.
- Real two-PC validation by the author (acceptance criterion of this phase).
- Daemon, file watching, scheduling, IPC (Phase 2). Locking against concurrent user git commands.
- Migration of repos with submodules or existing linked worktrees; `new` and provider code (Phase 4).
- Migration of repos with submodules; `new` and provider code (Phase 4).
- Resolve actions for `Diverged` (Phase 5): today it is only detected and left intact.
## Validation on the real Gitea (2026-11-16)
@@ -88,3 +88,32 @@ pass until that machine syncs again.
`clone_bare_layout` created worktrees without upstream tracking, so `Diverged` and `Behind` were
reported as `Synced` on repos cloned by grove itself. Fixed: every local branch with an `origin/<br>`
counterpart gets `--set-upstream-to` before worktrees are materialized (asserted in `tests/registry.rs`).
## Linked worktrees (`git worktree add`)
`grove add` accepts repos that already have linked worktrees:
- Linked worktrees nested inside the repo (e.g. `.claude/worktrees/<name>`, often detached) move with
the main checkout into `<repo>/<branch-dir>/...`. Ones outside the repo directory (e.g. a sibling
`Repo-feature` dir) stay where they are.
- The two link files of each (`<wt>/.git` and `.bare/worktrees/<id>/gitdir`) are rewritten to the new
absolute paths; the result is verified (`git worktree list` shows every worktree, none prunable, and
HEAD/branch/`status --ignored` of each are identical to before).
- Backup: the repo tar covers nested worktrees; each outside worktree gets its own tar
(`<repo>-<stamp>-linked<N>-<name>.tar`, listed in the report). Rollback also restores the link files.
- Refused up front (nothing touched): a linked worktree that is locked, missing/prunable, has an
operation in progress (rebase/merge/cherry-pick/revert/bisect), uses relative `.git` links, or
contains the repo itself.
- `grove add` prints each linked worktree with its branch or `detached`.
Sync behaviour with worktrees that are not at `<repo>/<branch-dir>`:
- Detached worktrees are reported but never snapshotted (a snapshot ref is per branch).
- Branch worktrees elsewhere are synced like any other, under `refs/sync/<machine>/<branch>`.
- `materialize` skips branches that already have a worktree anywhere; `archive_gone` only removes
worktrees directly under the repo dir, never ones elsewhere.
- The daemon's discovery ignores linked worktrees (`.git` file pointing into `.../worktrees/<id>`), so
a sibling worktree is not synced as a second repo.
- Known limit: a nested linked worktree is an embedded repo for the main worktree's snapshot, so it is
recorded as a gitlink (same limitation as nested untracked repos); its own content is not synced
through the main worktree's snapshot.
+4 -3
View File
@@ -5,8 +5,9 @@ is `grove_core::sync::sync_repo`, the same code the CLI runs. The daemon only de
## Behaviour
- **Repos**: every directory `root/<repo>` or `root/<group>/<repo>` that has a `.bare` or `.git`
(dot-directories skipped). Rediscovered at every full pass, so new repos are picked up.
- **Repos**: bare-layout repos (`.bare`) at `root/<group>/<repo>` for configured groups only; see
`docs/phase6.md` (Daemon scope and snapshot privacy). Rediscovered at every full pass, so new repos
are picked up.
- **Watching**: inotify (crate `notify`), recursive per repo. Changes under `.git`, `.bare`,
`.grove-stage` and anything matching `sync.ignore_extra` (exact component name or `*suffix`) are
ignored. If a watch cannot be set (typically `ENOSPC`, raise `fs.inotify.max_user_watches`) it is
@@ -58,7 +59,7 @@ socket is refused; a stale socket file left by a crash is replaced.
JSON lines in `<state dir>/activity.jsonl` (rotated at 5 MiB to `.jsonl.1`), the last 500 events in
memory, and live via `subscribe`. Kinds: `start`, `stop`, `snapshot`, `fast_forward`, `applied`,
`declined`, `state` (worktree state changed), `materialized`, `archived`, `error`, `watch_error`,
`declined`, `snapshots_withheld`, `snapshots_enabled`, `snapshots_purged`, `state` (worktree state changed), `materialized`, `archived`, `error`, `watch_error`,
`pause`, `resume`.
## CLI
+82 -1
View File
@@ -61,4 +61,85 @@ is the broad-scope `tea`/`gh` token; use `grove login` with a narrower token to
## Not verified
- Pull mirror creation on the real Gitea and push to a real GitHub org (mock-tested only).
- The daemon still syncs every repo under `root.path`, whether or not its directory is a group.
- Daemon scope and snapshot privacy (below) are verified with local bare remotes and mocks only, not against a real forge.
## Daemon scope and snapshot privacy
### Scope
`groved` manages only repos in the bare + worktrees layout (a `.bare` directory) at
`<root>/<group>/<repo>` for groups present in the config. Everything else under the root is
ignored: plain clones (never migrated with `grove add`), directories that are not configured
groups, repos directly under the root. Ignored plain clones inside a configured group are listed as
"not migrated (run grove add)" by `grove daemon status` and `grove doctor`. Discovery reads one
directory per configured group, so it stays cheap.
**Breaking change:** group names must now be plain directory names (non-empty, no `/`, no leading
`.`); a config with other names no longer loads.
### Snapshot policy
WIP snapshots (`refs/sync/<machine>/<branch>`) contain uncommitted work, so on a public repo anyone
could read them. New key, global default under `[sync]` and optional override per group:
```toml
[sync]
snapshots = "private-only" # default: "private-only" | "all" | "none"
[[groups]]
name = "Zenvairo"
primary = "gitea"
snapshots = "all" # optional per-group override
```
- `private-only`: push snapshots only when the forge says the repo is private.
- `all`: always push. `none`: never push.
- When snapshots are withheld the daemon neither takes nor pushes them for that repo. Fetching, fast
forwarding and applying other machines' snapshots are unaffected. The reason shows in
`grove daemon status` ("snapshots withheld: ...") and once per change in the daemon log
(`snapshots_withheld` / `snapshots_enabled`).
- `grove sync` (manual) still pushes snapshots regardless of this setting.
### How visibility is resolved
Under `private-only` snapshots are pushed only if **every place the push reaches** is known to be
private:
1. Every push URL of `origin` (`git remote get-url --push --all origin`, so `pushurl`, several
urls and `pushInsteadOf` count). Each is matched to exactly one configured provider by host,
port (http/https; an ssh port is ignored) and the provider URL's path prefix; zero or several
matching providers mean unknown. The token comes from `token::resolve` (tea/gh fallback) and the
lookup is `GET /repos/{owner}/{repo}` (`Provider::get_repo`). On GitHub only
`visibility = "private"` counts (internal repos do not; a reply without the field is unknown); on Gitea only `private: true`.
2. The group's mirror targets for the same repo name: every provider in `mirror_to` of the group's
private and public routes, under the group's `owners` entry or else the token's login. Gitea
push/pull mirrors copy `refs/sync/*`. A mirror that exists and is not private, or a failed
lookup, withholds; a 404 (no mirror) is fine.
Answers are cached in `<state dir>/visibility.json` (mode 0600), keyed by provider id, provider URL, owner
and name (lowercase, no `.git`). A "private" answer is trusted for 1 hour (a repo can be made public at
any time) and so is an "absent" mirror answer; only "not private" (which merely withholds) is kept 6 hours, a cache timestamp in the future counts as expired, and an
expired entry is never reused when the refresh fails. A failed lookup is retried at most every 5
minutes. Unknown counts as **public**: no or several matching providers, no token, network error,
404 on the repo itself, a reply without the `private` flag, no push URL. Offline (backoff) passes do
no lookup: they use the last verdict, and take no snapshot when there is none.
When snapshots are withheld, the daemon deletes this machine's snapshot refs
(`refs/sync/<machine>/*` only, never other machines' refs or branches). It lists them on every
push URL with `ls-remote` (so refs without a local copy are found too), pushes the deletions per
URL, and counts a URL as clean only when a fresh `ls-remote` shows none left; only then are the
local copies removed. It logs `snapshots_purged` as a warning; any failure (also a server saying
the repository does not exist) is logged as `error` and retried on the next pass. Git runs with
`LC_ALL=C`, and snapshot pushes use `push.recurseSubmodules=no`.
Residual risks: when matching a provider, an ssh URL's port is ignored (it says nothing about the
web port), so two forges on one host that differ only by port cannot be told apart by an ssh remote;
and mirrors made by hand outside grove's config (a push mirror set up in the forge UI,
a second remote) are unknown to the daemon. Use `snapshots = "none"` for repos where that matters.
### auto_materialize
`auto_materialize` (default `true`) makes the daemon create a worktree directory for every remote
branch of a repo, including long-merged ones, and archive worktrees whose branch is gone. It is
decided **per group** (it used to apply only when every group enabled it): set
`auto_materialize = false` in a group to stop that for its repos. The default is unchanged.