docs: document phase 1 design, decisions and lessons

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-11-16 12:07:26 +01:00
1 parent 81d8142c57
commit 938604193e
4 files changed
+57 -3

No files matched your search

+2 -2
View File
@@ -4,7 +4,7 @@
Linux tool that keeps chosen git repos continuously in sync across machines, including
uncommitted work, via snapshot refs (`refs/sync/<machine>/<branch>`) on a primary remote.
Planned as a Rust workspace (core, providers, daemon, CLI, Tauri GUI). Currently in
**Phase 0 done, Phase 1 in progress**: `gitsync-core` has the git runner, snapshots and state classification; config loading, worktree inspection and a minimal CLI (`status`, `snapshot`) exist; migration (`add`), receive logic, `doctor` and two-machine tests are pending. Do not start a
**Phase 0 done, Phase 1 implemented (pending real two-PC validation and review)**: `gitsync-core` + `gitsync` CLI (`status`, `snapshot`, `add`, `sync`, `doctor`); daemon, GUI and providers do not exist yet. Do not start a
new phase before its predecessor's results are written to `docs/`.
## Commands
@@ -13,7 +13,7 @@ new phase before its predecessor's results are written to `docs/`.
- Rust: `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `cargo test`
## Architecture
See `docs/` (`phase0-spike.md`, `DECISIONS.md`). Git is the storage layer; shell out to
See `docs/` (`phase0-spike.md`, `phase1.md`, `DECISIONS.md`). Git is the storage layer; shell out to
system `git`; snapshots use a temp `GIT_INDEX_FILE` + `commit-tree`, never touching the
user's branch or index.
+4
View File
@@ -1,3 +1,7 @@
# Lessons
- Forgejo push mirrors to localhost are blocked by default; set `ALLOW_LOCALNETWORKS` in throwaway test instances.
- `git clone --bare` sets no `remote.origin.fetch`; without it `fetch` never creates `refs/remotes/*`. Use `receive::ensure_fetch_refspec`.
- `Git::run` trims stdout, which also eats the leading space of the first `status --porcelain` line (` M x` becomes `M x`). Don't assert on that format via `run`.
- Fetch other machines' snapshots into `refs/sync-remote/*`, never into `refs/sync/*`, or a fetch can clobber this machine's own refs.
- Run tests that create many temp repos with unique dir names (pid + nanos); the shared `tests/common` helper does this.
+3 -1
View File
@@ -1,4 +1,6 @@
# Decisions
1. Custom refs on Gitea/Forgejo: supported on Forgejo 11, no fallback needed (see `phase0-spike.md`). Also confirmed on git.zenvairo.es (Gitea 1.25.4); mirror exclusion still to verify there.
2-5. Open.
2. Snapshots are auto-applied only when the target worktree is clean, has no unpushed commits and HEAD can fast-forward to the snapshot's base; otherwise declined and reported (implemented in `receive::apply_snapshot`).
3. Config: TOML for user intent (implemented); runtime state storage still open.
4-5. Open.
+48
View File
@@ -0,0 +1,48 @@
# Phase 1: core + CLI
Crates: `gitsync-core` (library) and `gitsync` (CLI). Everything shells out to the system `git`.
## CLI
| Command | What it does |
|---|---|
| `gitsync status [path]` | State of every worktree (`Synced`, `Dirty`, `Ahead`, `Behind`, `BehindDirty`, `Diverged`, `Error`) |
| `gitsync snapshot [path]` | Snapshot the worktree into `refs/sync/<machine>/<branch>` (local only) |
| `gitsync add <path>` | Migrate a plain clone to `.bare/` + one worktree per branch, in place |
| `gitsync sync [path] [--offline]` | One full pass (below) |
| `gitsync doctor` | Checks git, config, root, repo remotes and refspecs, inotify limit |
Config: `~/.config/gitsync/config.toml` (or `--config`). Machine names are embedded in ref names, so
they may only contain letters, digits, `-` and `_`.
## Sync pass (`sync_repo`)
1. `fetch --prune` plus `+refs/sync/*:refs/sync-remote/*` (other machines' snapshots land in a
separate namespace so a machine's own `refs/sync/*` is never overwritten).
2. Bare layout only: archive worktrees whose upstream branch is gone, then materialize worktrees for
new remote branches.
3. Per worktree: snapshot (if dirty, or if an older snapshot ref exists so a stale WIP never lingers)
and force-push the machine's own snapshot ref; fast-forward if clean and strictly behind;
apply another machine's snapshot as working changes if clean, not ahead, and HEAD can fast-forward
to the snapshot's base commit.
4. Step failures are reported per worktree and never abort the pass. Dirty or diverged worktrees
are never modified.
## Safety mechanisms
- `add`: full tar backup + `refs/sync-backup/<machine>/<ts>` first; refuses detached HEAD, no commits,
merge/rebase/cherry-pick/bisect in progress, submodules, existing linked worktrees, backup dir
inside the repo. Staged state, stashes, untracked and ignored files are preserved (the index is
carried over). Status, stashes and refs are compared before/after; any failure triggers rollback
to the original layout (tested by injecting a failure after every step).
- Every operation that rewrites a worktree writes a backup ref first.
- `apply_snapshot` declines (changing nothing) on any local work; `read-tree -m -u` additionally
refuses to overwrite untracked files.
- `archive_gone` keeps dirty worktrees and writes a backup ref before deleting a branch.
## Not done yet (later phases)
- 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).
- Resolve actions for `Diverged` (Phase 5): today it is only detected and left intact.