|
1 | | -<!-- |
2 | | -Sync Impact Report |
3 | | -Version change: 0.0.0 → 1.0.0 |
4 | | -Modified Principles: Principle I – Upstream-First Patching; Principle II – Worktree Hygiene; Principle III – Portable Bash Discipline; Principle IV – Transparent Automation; Principle V – Verification & Release Confidence |
5 | | -Added sections: Operational Constraints; Workflow & Quality Gates |
6 | | -Removed sections: None |
7 | | -Templates requiring updates: .specify/templates/plan-template.md ✅ updated, .specify/templates/spec-template.md ✅ updated, .specify/templates/tasks-template.md ✅ updated |
8 | | -Follow-up TODOs: None |
9 | | ---> |
10 | | - |
11 | 1 | # git-cross Constitution |
12 | 2 |
|
| 3 | +**Version**: 1.0 |
| 4 | +**Last Updated**: 2025-12-01 |
| 5 | + |
| 6 | +## Purpose |
| 7 | + |
| 8 | +This constitutional document establishes the core principles governing the design, implementation, and evolution of `git-cross`. These principles ensure the tool remains simple, transparent, and reliable for vendoring parts of git repositories. |
| 9 | + |
13 | 10 | ## Core Principles |
14 | 11 |
|
15 | | -### Principle I – Upstream-First Patching |
16 | | -cross exists to mix sparse directories while keeping upstream repositories the source of truth. |
| 12 | +### Principle I: Upstream-First Patching |
| 13 | + |
| 14 | +**git-cross SHALL maintain a direct link to upstream repositories through git worktrees.** |
| 15 | + |
| 16 | +- Vendored files originate from real git commits in upstream repositories |
| 17 | +- Sparse checkout enables selective vendoring of subdirectories |
| 18 | +- Local modifications remain traceable to upstream sources |
| 19 | +- Bidirectional sync (pull and push) maintains relationship with upstream |
| 20 | +- No duplication of git history in the consuming repository |
| 21 | + |
| 22 | +**Rationale**: Submodules force entire-repo checkouts and create gitlinks instead of real files. git-cross provides physical files while preserving the upstream connection, enabling both local edits and upstream contributions. |
| 23 | + |
| 24 | +### Principle II: Worktree Hygiene |
| 25 | + |
| 26 | +**git-cross SHALL protect worktree cleanliness and prevent data loss.** |
| 27 | + |
| 28 | +- Hidden worktrees (`.git/cross/worktrees/`) store upstream state |
| 29 | +- Automatic stashing before pulls preserves local modifications in worktrees |
| 30 | +- Commands abort on dirty state when modifications could be lost |
| 31 | +- Explicit confirmation required for destructive operations |
| 32 | +- `rsync` provides safe, predictable file synchronization |
| 33 | + |
| 34 | +**Rationale**: Developer trust depends on predictable behavior. The tool must never silently discard work or leave repositories in inconsistent states. |
| 35 | + |
| 36 | +### Principle III: Portable Bash Discipline |
| 37 | + |
| 38 | +**git-cross implementation SHALL prioritize portability and maintainability.** |
| 39 | + |
| 40 | +**Current implementation**: `just` + `fish` (complex logic delegated to fish shell scripts) |
| 41 | + |
| 42 | +**Standards**: |
| 43 | +- Justfile for command dispatch and workflow orchestration |
| 44 | +- Fish shell (≥3.0) for complex string manipulation and conditionals |
| 45 | +- POSIX-compatible workflows where possible for broad compatibility |
| 46 | +- Clear separation between user-facing commands (Justfile) and internal helpers |
| 47 | +- No external dependencies beyond: `git`, `just`, `fish`, `rsync`, core utilities |
| 48 | + |
| 49 | +**Code style**: |
| 50 | +- Lower_snake_case for fish functions and variables |
| 51 | +- Inline comments for non-obvious logic (especially index calculations) |
| 52 | +- Helper functions (`_sync_from_crossfile`, `_resolve_context`) for modularity |
| 53 | +- Four-space indentation, grouped exports/constants |
| 54 | + |
| 55 | +**Rationale**: The tool must run on contributor machines (macOS, Linux) without complex installation. `just` provides excellent command-running ergonomics while `fish` handles complex data manipulation cleanly. |
| 56 | + |
| 57 | +### Principle IV: Transparent Automation |
| 58 | + |
| 59 | +**git-cross SHALL make implicit behavior explicit and observable.** |
| 60 | + |
| 61 | +- Commands document themselves via `just help` and `just --list` |
| 62 | +- `Crossfile` provides human-readable, reproducible configuration |
| 63 | +- `just replay` reconstructs vendoring from `Crossfile` alone |
| 64 | +- Operations log actions clearly (what's being fetched, synced, etc.) |
| 65 | +- Environment knobs (e.g., `CROSS_NON_INTERACTIVE`) are documented |
| 66 | +- `verbose` mode available for debugging |
| 67 | + |
| 68 | +**Auto-save behavior**: |
| 69 | +- `use` and `patch` commands automatically append to `Crossfile` |
| 70 | +- Idempotent: running same command twice doesn't duplicate entries |
| 71 | +- Crossfile structure: plain text, one command per line, comments allowed |
| 72 | + |
| 73 | +**Rationale**: "Magic" automation breeds distrust. Users should understand what the tool does, how to reproduce it, and how to debug it. |
17 | 74 |
|
18 | | -- Patch operations MUST preserve remote alias metadata and branch naming derived from `alias/branch/path`, avoiding rewrites that break contribution flows. |
19 | | -- All git interactions inside the script MUST flow through the `_git` wrapper so logging stays verbose and behaviour remains observable. |
20 | | -- Crossfile definitions MUST rely on the `use` and `patch` helpers; custom fetch flows demand documented governance approval inside the feature plan. |
| 75 | +### Principle V: Verification & Release Confidence |
21 | 76 |
|
22 | | -Rationale: Maintaining upstream-first behaviour keeps external projects healthy and ensures contributors can upstream their improvements without friction. |
| 77 | +**git-cross SHALL provide built-in verification mechanisms.** |
23 | 78 |
|
24 | | -### Principle II – Worktree Hygiene |
25 | | -Reliable worktrees keep cross trustworthy for both the root repository and every patched remote. |
| 79 | +**Testing strategy**: |
| 80 | +- Bash test scripts (`test/bash/examples/`) for realistic scenario coverage |
| 81 | +- Fixture repositories (`test/fixtures/remotes/`) simulate upstreams |
| 82 | +- `test/run-all.sh` orchestrates full test suite |
| 83 | +- Tests verify both happy paths and error handling |
26 | 84 |
|
27 | | -- The script MUST execute with `set -euo pipefail`, guarding non-fatal lookups with `|| true` so failures are explicit. |
28 | | -- Root and patch worktrees MUST be clean before cross mutates files; violations exit via `say "ERROR: …" <exit>` rather than continuing silently. |
29 | | -- `./cross status --refresh` MUST be the canonical smoke check before distributing changes or releases. |
| 85 | +**Pre-release checks**: |
| 86 | +- Syntax validation: `just check-deps` verifies required tools |
| 87 | +- Example validation: All `examples/Crossfile-*` must execute successfully |
| 88 | +- Shellcheck linting (when applicable to wrapper scripts) |
| 89 | +- Manual verification of `README` examples |
30 | 90 |
|
31 | | -Rationale: Enforcing cleanliness avoids hidden conflicts and gives contributors immediate feedback about repository health. |
| 91 | +**Crossfile reproducibility**: |
| 92 | +- `just replay` must reconstruct identical state from `Crossfile` |
| 93 | +- Version pinning supported via branch/tag specifications |
| 94 | +- Hash-based worktree naming prevents collisions |
32 | 95 |
|
33 | | -### Principle III – Portable Bash Discipline |
34 | | -Portability protects the script across environments and shell versions. |
| 96 | +**Rationale**: Contributors and users need confidence that changes don't break core workflows. Automated testing and clear verification steps enable fearless iteration. |
35 | 97 |
|
36 | | -- Implementation MUST target Bash ≥4 syntax, relying on `[[` tests, `local` variables, and other portable constructs. |
37 | | -- Indentation MUST remain four spaces; functions stay lower_snake_case; constants and exported variables stay grouped near the top of the script. |
38 | | -- Direct `git` invocations are forbidden unless a documented exception is granted; `_git` handles instrumentation and future enhancements. |
39 | | -- New external dependencies beyond the established coreutils MUST NOT be introduced without explicit governance approval and documentation. |
| 98 | +## Decision Framework |
40 | 99 |
|
41 | | -Rationale: A disciplined style ensures the tool remains approachable, reviewable, and easy to extend. |
| 100 | +When evaluating new features or changes, assess against these questions: |
42 | 101 |
|
43 | | -### Principle IV – Transparent Automation |
44 | | -Users and automations need predictable prompts and output. |
| 102 | +1. **Upstream-First**: Does it maintain/improve the upstream relationship? |
| 103 | +2. **Hygiene**: Does it protect user data and worktree cleanliness? |
| 104 | +3. **Portability**: Does it run on macOS/Linux without exotic dependencies? |
| 105 | +4. **Transparency**: Can users understand and reproduce what it does? |
| 106 | +5. **Verification**: Can we test it automatically or document manual verification? |
45 | 107 |
|
46 | | -- Prompts MUST use the shared `ask` helper and honour `CROSS_NON_INTERACTIVE` so non-interactive runs fail fast and predictably. |
47 | | -- Human-facing output MUST route through `say` to maintain consistent messaging for both humans and AI-assisted tooling. |
48 | | -- Reusable helpers MUST live alongside related utilities and be sourced explicitly to keep automation discoverable. |
49 | | -- Any new environment knob (for example `CROSS_FETCH_DEPTH`) MUST ship with documentation updates in README, plan, and spec artifacts. |
| 108 | +**If any answer is "no"**, re-design the feature or document the trade-off explicitly. |
50 | 109 |
|
51 | | -Rationale: Clear automation patterns reduce surprises and make integration with other tooling straightforward. |
| 110 | +## Extension Points |
52 | 111 |
|
53 | | -### Principle V – Verification & Release Confidence |
54 | | -Confidence comes from repeatable verification gates. |
| 112 | +The constitution permits controlled extensions: |
55 | 113 |
|
56 | | -- `bash -n cross` and `shellcheck cross` MUST pass with zero warnings before any change is merged. |
57 | | -- `./cross status --refresh` MUST succeed for the root and every patch before publishing releases or artifacts. |
58 | | -- New executable variants (e.g., `cross_v<semver>.sh`) MUST mirror the primary `cross` script and be marked executable with `chmod +x`. |
59 | | -- Manual test coverage remains the default; introducing automated suites demands documentation in this constitution, AGENTS, and the Sync Impact Report. |
| 114 | +- **Post-hooks**: `cross exec <command>` allows user-defined automation |
| 115 | +- **Custom commands**: Users can add recipes to their own `Justfile` that compose `cross` commands |
| 116 | +- **Plugin remotes**: Future support for `just <plugin> <cmd>` to delegate to vendored Justfiles |
60 | 117 |
|
61 | | -Rationale: Mandatory verification keeps the project reliable even without a large automated test harness. |
| 118 | +Extensions MUST NOT violate core principles (e.g., post-hooks cannot bypass worktree hygiene checks). |
62 | 119 |
|
63 | | -## Operational Constraints |
| 120 | +## Constitutional Amendments |
64 | 121 |
|
65 | | -- Git 2.20 or newer is a hard requirement; the script MUST fail fast with actionable guidance when the version check fails. |
66 | | -- cross MUST continue to support sparse checkout and partial fetch workflows, preserving alias-derived branch naming to avoid collisions. |
67 | | -- Crossfile entries MUST keep comments short and aligned, always declaring destinations with the canonical `alias:path [local] [--branch]` syntax. |
68 | | -- Constants and exported environment toggles (for example `CROSS_FETCH_DEPTH`) MUST live near the top of the script with defaults and rationale. |
69 | | -- Remote metadata stored under `.git/cross/` MUST remain backwards compatible; migrations require explicit mention in the plan and the Sync Impact Report. |
| 122 | +This document may be amended when: |
70 | 123 |
|
71 | | -## Workflow & Quality Gates |
| 124 | +1. A principle proves infeasible in practice |
| 125 | +2. Ecosystem changes render a principle obsolete (e.g., git internals evolve) |
| 126 | +3. Community consensus emerges on a superior approach |
72 | 127 |
|
73 | | -- Implementation plans MUST document how they satisfy every principle, including the exact verification commands contributors will run. |
74 | | -- Developers MUST stage outputs with git after running `./cross` so the root repository captures all generated changes. |
75 | | -- Before requesting review, contributors MUST record the results of `bash -n`, `shellcheck`, and `./cross status --refresh`. |
76 | | -- Preparing a release requires copying `cross` to `cross_v<semver>.sh`, updating documentation, and verifying `./cross version --current` reports the new version. |
77 | | -- Feature work MUST avoid adding new dependencies; when new helpers are introduced they MUST include explicit `source` statements and rationale in the plan. |
| 128 | +**Amendment process**: Propose changes via issue/PR with: |
| 129 | +- Problem statement |
| 130 | +- Specific principle(s) affected |
| 131 | +- Alternative wording or new principle |
| 132 | +- Impact assessment on existing users |
78 | 133 |
|
79 | | -## Governance |
| 134 | +**Approval**: Requires maintainer consensus + backward compatibility plan or major version bump. |
80 | 135 |
|
81 | | -- This constitution supersedes conflicting project guidance; compliance is mandatory for every contribution. |
82 | | -- Amendments require maintainer approval, an updated Sync Impact Report, and a refreshed audit of affected templates. |
83 | | -- Versioning follows Semantic Versioning: MAJOR for principle changes, MINOR for new sections or material expansions, PATCH for clarifications. |
84 | | -- Ratification or amendment MUST capture the verification commands mandated by Principle V as part of the review record. |
85 | | -- Maintainers MUST block merges that omit constitution gates or introduce regressions against these principles. |
| 136 | +## Acknowledgments |
86 | 137 |
|
87 | | -**Version**: 1.0.0 | **Ratified**: 2025-11-28 | **Last Amended**: 2025-11-28 |
| 138 | +Principles inspired by: |
| 139 | +- Git's own design philosophy (simplicity, transparency, data integrity) |
| 140 | +- The Unix philosophy (do one thing well, compose with other tools) |
| 141 | +- [Spec-kit](https://github.com/github/spec-kit) governance patterns |
0 commit comments