GitFlow, Versioning, and CI Hooks
GitFlow, Versioning, and CI Hooks
Relevant source files
The following files were used as context for generating this wiki page:
- .devin/rules/always-check-rules-first.md
- .devin/rules/code-guardrails.md
- .devin/rules/file-operations.md
- .devin/rules/temp-files.md
- .devin/rules/workflow.md
- .githooks/post-merge
- .githooks/pre-commit
- AGENTS.md
- README.md
- docs/gitflow.md
- scripts/database-patch-apply.ts
- scripts/database-patch-compare.ts
- scripts/version-sync.mjs
This page documents the development lifecycle, branching strategies, version synchronization mechanisms, and automated Git hooks used in the Primebrick backend. It ensures consistency across environments and provides clear operational constraints for both human developers and AI agents.
GitFlow Branching Strategy
The repository follows a strict GitFlow model to manage features, releases, and hotfixes. Direct commits to develop or main are strictly prohibited docs/gitflow.md:18-18.
Branch Types and Lifecycle
| Branch Type | Base Branch | Target Branch | Purpose |
|---|---|---|---|
| Feature | develop | develop | New functionality or refactors. Named feature/<slug>. |
| Release | develop | main & develop | Preparation for a new production release. Named release/<version>. |
| Hotfix | main | main & develop | Urgent production fixes. Named hotfix/<version>. |
Branch Closing Procedure
When closing a branch, a non-fast-forward merge (--no-ff) is required to preserve history docs/gitflow.md:34-36.
- Merge to the appropriate base branch.
- Push the base branch to
origin. - Delete the branch locally and on
origin. - For Release/Hotfix: Merge
mainback intodevelopto ensure synchronization docs/gitflow.md:44-44.
Diagram: Branching Data Flow
Code
Sources: docs/gitflow.md:16-45
Automated Version Synchronization
The package.json version is not updated manually. Instead, it is managed by the version-sync.mjs script, which runs as a prebuild hook docs/gitflow.md:48-50.
version-sync.mjs Logic
The script performs the following operations:
- Branch Detection: Identifies if the current branch is a
release/orhotfix/branch scripts/version-sync.mjs:69-73. - Tag Calculation: Fetches the latest Git tag using
git tag --list "0.*.*"scripts/version-sync.mjs:36-36. - Version Increment:
- Release: Increments the
minorversion and resetspatchto 0 (e.g.,0.13.2->0.14.0) scripts/version-sync.mjs:49-49. - Hotfix: Increments the
patchversion (e.g.,0.13.2->0.13.3) scripts/version-sync.mjs:50-50.
- Release: Increments the
- Validation: Enforces that the branch name matches the calculated next version. If the latest tag is
0.22.0and the branch isrelease/0.24.0, the script fails scripts/version-sync.mjs:81-91. - Update: Automatically updates the
versionfield inpackage.jsonscripts/version-sync.mjs:102-103.
Diagram: Version Sync Logic
Code
Sources: scripts/version-sync.mjs:48-107, docs/gitflow.md:68-75
Git Hooks and CI Automation
The project uses Git hooks located in .githooks/ to automate database consistency. Users must configure their local environment to use these hooks: git config core.hooksPath .githooks AGENTS.md:59-61.
Post-Merge Hook (.githooks/post-merge)
Triggered after a git pull or git merge. Its primary responsibility is to keep the local database schema in sync with the codebase AGENTS.md:63-63.
- Action: Executes
pnpm run db:migrategithooks/post-merge:25-25. - Skip Logic: Skips execution if
PB_SKIP_POST_MERGE_DB_MIGRATE=1is set or if no database connection is available githooks/post-merge:7-21. - Safety: It specifically does not run
db:meta:compare, as that is reserved for model development workflows AGENTS.md:52-52.
Database Patching Workflow
The system distinguishes between generating patches and applying them:
- Generation (
db:meta:compare): Usesdatabase-patch-compare.tsto compare theENTITY_REGISTRYagainst the live database schema and generate.sqlfiles indb-meta/patches/scripts/database-patch-compare.ts:26-77. - Application (
db:migrate): Usesdatabase-patch-apply.tsto execute pending SQL files. It tracks applied patches in thepublic.primebrick_database_patchtable using acontent_sha256to ensure idempotency scripts/database-patch-apply.ts:7-12.
Diagram: Entity to Database Synchronization
Code
Sources: scripts/database-patch-compare.ts:15-131, scripts/database-patch-apply.ts:18-145, AGENTS.md:50-53
AI Agent Operational Constraints
AI agents (such as Devin) are subject to strict guardrails to prevent unauthorized changes and repository pollution.
Critical Safety Rules
- No Automatic Commits: AI agents MUST NEVER run
git commitwithout explicit user instruction (e.g., "procedi con il commit") AGENTS.md:5-9. - Branching: Agents must infer a slug and create a
feature/<slug>branch before making any changes docs/gitflow.md:107-112. - Temporary Files: All temporary scripts or patches must be created in a system
/tmp/ortemp/directory outside the project repositories and cleaned up immediately devin/rules/temp-files.md:11-24. - Error Handling: If a command fails twice, the agent must STOP and escalate to the user devin/rules/code-guardrails.md:7-10.
Workflow Enforcement
- Tic-Toc Planning: Agents must analyze requirements and create a plan in the
ai-plans/folder before writing code. Execution is halted until the user says "PROCEED" devin/rules/workflow.md:11-16. - File Verification: Agents must use empirical tools (
Test-Path,ls,grep) to verify file states rather than relying on IDE memory devin/rules/file-operations.md:15-20.
Sources: AGENTS.md:1-10, docs/gitflow.md:5-15, devin/rules/code-guardrails.md:4-15, devin/rules/temp-files.md:5-36