gitgatekeeper 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitgatekeeper/__init__.py +10 -0
- gitgatekeeper/cli/main.py +1074 -0
- gitgatekeeper/config/__init__.py +18 -0
- gitgatekeeper/config/loader.py +100 -0
- gitgatekeeper/config/models.py +205 -0
- gitgatekeeper/core/__init__.py +46 -0
- gitgatekeeper/core/buffer.py +125 -0
- gitgatekeeper/core/commit_engine.py +900 -0
- gitgatekeeper/core/detector.py +154 -0
- gitgatekeeper/core/discovery.py +172 -0
- gitgatekeeper/core/doctor.py +220 -0
- gitgatekeeper/core/events.py +89 -0
- gitgatekeeper/core/filters.py +79 -0
- gitgatekeeper/core/grouping.py +139 -0
- gitgatekeeper/core/inactivity.py +154 -0
- gitgatekeeper/core/instance.py +202 -0
- gitgatekeeper/core/locking.py +85 -0
- gitgatekeeper/core/migrate.py +134 -0
- gitgatekeeper/core/monitor.py +408 -0
- gitgatekeeper/core/project_manager.py +141 -0
- gitgatekeeper/core/push_engine.py +441 -0
- gitgatekeeper/core/service.py +703 -0
- gitgatekeeper/core/systemd.py +223 -0
- gitgatekeeper/core/undo.py +104 -0
- gitgatekeeper/git/__init__.py +43 -0
- gitgatekeeper/git/analyzer.py +96 -0
- gitgatekeeper/git/diff.py +252 -0
- gitgatekeeper/git/ignore.py +36 -0
- gitgatekeeper/git/models.py +118 -0
- gitgatekeeper/git/repository.py +123 -0
- gitgatekeeper/git/secrets.py +150 -0
- gitgatekeeper/git/sensitive.py +114 -0
- gitgatekeeper/git/status_parser.py +134 -0
- gitgatekeeper/intelligence/__init__.py +23 -0
- gitgatekeeper/intelligence/analysis.py +358 -0
- gitgatekeeper/intelligence/context.py +57 -0
- gitgatekeeper/intelligence/message.py +117 -0
- gitgatekeeper/intelligence/profile.py +213 -0
- gitgatekeeper/intelligence/provider.py +65 -0
- gitgatekeeper/intelligence/rules.py +561 -0
- gitgatekeeper/logging_setup.py +122 -0
- gitgatekeeper/storage/__init__.py +16 -0
- gitgatekeeper/storage/database.py +235 -0
- gitgatekeeper/storage/history.py +440 -0
- gitgatekeeper/storage/models.py +78 -0
- gitgatekeeper/storage/recorder.py +178 -0
- gitgatekeeper-0.1.1.dist-info/METADATA +671 -0
- gitgatekeeper-0.1.1.dist-info/RECORD +52 -0
- gitgatekeeper-0.1.1.dist-info/WHEEL +5 -0
- gitgatekeeper-0.1.1.dist-info/entry_points.txt +2 -0
- gitgatekeeper-0.1.1.dist-info/licenses/LICENSE +21 -0
- gitgatekeeper-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitgatekeeper
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Local-first Git automation agent: watches repos and writes safe, specific commits
|
|
5
|
+
Author: robertofilho0
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/robertofilho0/GitGatekeeper
|
|
8
|
+
Project-URL: Issues, https://github.com/robertofilho0/GitGatekeeper/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/robertofilho0/GitGatekeeper/releases
|
|
10
|
+
Keywords: git,automation,commit,conventional-commits,local-first
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: watchdog>=7.1
|
|
23
|
+
Requires-Dist: pydantic>=2.11
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Requires-Dist: typer>=0.15
|
|
26
|
+
Requires-Dist: rich>=14.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=6.0; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.11; extra == "dev"
|
|
31
|
+
Provides-Extra: release
|
|
32
|
+
Requires-Dist: build>=1.2; extra == "release"
|
|
33
|
+
Requires-Dist: twine>=6.1; extra == "release"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# GitGatekeeper
|
|
37
|
+
|
|
38
|
+
GitGatekeeper is a local Git automation agent. It watches your repositories, waits
|
|
39
|
+
until you stop working on one, and then commits the changes with a
|
|
40
|
+
[Conventional Commit](https://www.conventionalcommits.org/) message. Pushing is
|
|
41
|
+
optional and **off by default**.
|
|
42
|
+
|
|
43
|
+
It is built to be boring and safe: it never rewrites history, never forces
|
|
44
|
+
anything, never touches what you staged yourself, and when it is not sure what
|
|
45
|
+
belongs in a commit, it does nothing and writes down why.
|
|
46
|
+
|
|
47
|
+
> Status: alpha (`0.1.0`). Linux only (developed and tested on Ubuntu 24.04).
|
|
48
|
+
|
|
49
|
+
**Local-first and open source.** GitGatekeeper makes no network requests of its own,
|
|
50
|
+
has no telemetry, and uses no external API or hosted AI model. Your code and
|
|
51
|
+
diffs never leave your machine. The only traffic is the `git push` you opt into
|
|
52
|
+
and the read-only `git ls-remote` that `gitgatekeeper check` runs against your own
|
|
53
|
+
remotes (skip it with `--offline`), both done by Git itself. Commit messages are written by transparent, deterministic
|
|
54
|
+
rules you can read in [`src/gitgatekeeper/intelligence/`](https://github.com/robertofilho0/GitGatekeeper/tree/main/src/gitgatekeeper/intelligence).
|
|
55
|
+
Tests enforce this (see [Tests](#tests)).
|
|
56
|
+
|
|
57
|
+
## Contents
|
|
58
|
+
|
|
59
|
+
- [How it works](#how-it-works)
|
|
60
|
+
- [Architecture](#architecture)
|
|
61
|
+
- [Installation](#installation)
|
|
62
|
+
- [Configuration](#configuration)
|
|
63
|
+
- [Command line](#command-line)
|
|
64
|
+
- [Running on Ubuntu](#running-on-ubuntu)
|
|
65
|
+
- [Running as a systemd user service](#running-as-a-systemd-user-service)
|
|
66
|
+
- [Security model](#security-model)
|
|
67
|
+
- [Commit messages](#commit-messages)
|
|
68
|
+
- [Data and logs](#data-and-logs)
|
|
69
|
+
- [Tests](#tests)
|
|
70
|
+
- [Known limitations](#known-limitations)
|
|
71
|
+
- [Roadmap](#roadmap)
|
|
72
|
+
- [Releasing](#releasing)
|
|
73
|
+
- [Contributing](#contributing)
|
|
74
|
+
- [License](#license)
|
|
75
|
+
|
|
76
|
+
## How it works
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
file change -> monitor -> inactivity detector --(quiet for N minutes)--> cycle
|
|
80
|
+
|
|
81
|
+
cycle: commit engine -> [push engine, only if auto_push] -> history (SQLite)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
1. A file watcher (Watchdog) reports changes per project, ignoring `.git/` and
|
|
85
|
+
anything Git ignores.
|
|
86
|
+
2. Each project has its own inactivity timer (default 10 minutes). Every new
|
|
87
|
+
change restarts it.
|
|
88
|
+
3. When a project has been quiet long enough, GitGatekeeper inspects it with the Git
|
|
89
|
+
CLI, selects the files it may commit, builds a message with deterministic
|
|
90
|
+
rules, and commits only those files.
|
|
91
|
+
4. If `auto_push` is enabled for that project, it pushes the current branch to
|
|
92
|
+
its configured upstream.
|
|
93
|
+
5. Every outcome is recorded in a local SQLite database.
|
|
94
|
+
|
|
95
|
+
On start, GitGatekeeper also scans each project: work left over from before a restart
|
|
96
|
+
(uncommitted changes, or with `auto_push` unpublished commits) is queued again.
|
|
97
|
+
|
|
98
|
+
## Architecture
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
src/gitgatekeeper/
|
|
102
|
+
config/ Pydantic models and YAML loading/saving
|
|
103
|
+
core/
|
|
104
|
+
project_manager.py add / remove / enable / disable projects
|
|
105
|
+
monitor.py Watchdog-based repository monitor (debounced)
|
|
106
|
+
inactivity.py per-project inactivity timers
|
|
107
|
+
detector.py runs a callback when a project becomes eligible
|
|
108
|
+
commit_engine.py safe selection, secret scan, commit, rollback
|
|
109
|
+
push_engine.py safe push of the current branch
|
|
110
|
+
locking.py per-repository file locks
|
|
111
|
+
instance.py single running instance, safe stop
|
|
112
|
+
service.py the orchestrator behind `gitgatekeeper start`
|
|
113
|
+
git/ Git CLI wrapper, status parser, analyzer, diff reader,
|
|
114
|
+
sensitive-file and secret detection
|
|
115
|
+
intelligence/ commit messages: rules, project profile, code context
|
|
116
|
+
profile.py detects how a project is organised (modules)
|
|
117
|
+
context.py which functions/classes a change touched
|
|
118
|
+
rules.py the message generator
|
|
119
|
+
storage/ SQLite database, history store, recorder
|
|
120
|
+
cli/ Typer commands
|
|
121
|
+
logging_setup.py JSON-lines logging with credential masking
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Design choices worth knowing:
|
|
125
|
+
|
|
126
|
+
- **Git CLI, not a Git library.** Behaviour matches what you get in a terminal,
|
|
127
|
+
including your hooks and configuration. Every call has a timeout, never uses
|
|
128
|
+
a shell, and a timed-out process group is killed as a whole.
|
|
129
|
+
- **Deterministic, local messages.** Messages come from rules, so the same change
|
|
130
|
+
always yields the same message, and nothing is sent anywhere.
|
|
131
|
+
`intelligence/provider.py` validates any generator's output and falls back to
|
|
132
|
+
the built-in rules, so a custom generator can be plugged in without risk.
|
|
133
|
+
- **History is best effort and fails safe.** If the database cannot be written,
|
|
134
|
+
GitGatekeeper never assumes a commit is its own and never skips a duplicate check
|
|
135
|
+
in a way that could publish something it should not.
|
|
136
|
+
|
|
137
|
+
## Installation
|
|
138
|
+
|
|
139
|
+
Requirements: Linux, Python 3.12+, Git.
|
|
140
|
+
|
|
141
|
+
To use it, install it from PyPI (`pipx` keeps it in its own environment):
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pipx install gitgatekeeper
|
|
145
|
+
gitgatekeeper --help
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
To work on it, clone the repository:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
git clone git@github.com:robertofilho0/GitGatekeeper.git
|
|
152
|
+
cd GitGatekeeper
|
|
153
|
+
python3 -m venv .venv
|
|
154
|
+
source .venv/bin/activate
|
|
155
|
+
pip install -e ".[dev]"
|
|
156
|
+
gitgatekeeper --help
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Configuration
|
|
160
|
+
|
|
161
|
+
GitGatekeeper reads one YAML file. It is found in this order:
|
|
162
|
+
|
|
163
|
+
1. `--config <path>` on the command line
|
|
164
|
+
2. `$GITGATEKEEPER_CONFIG`
|
|
165
|
+
3. `./config/projects.yaml`
|
|
166
|
+
4. `~/.config/gitgatekeeper/projects.yaml`
|
|
167
|
+
|
|
168
|
+
A `./config/projects.yaml` that has no enabled project (such as the template in
|
|
169
|
+
a fresh checkout) is skipped while `~/.config/gitgatekeeper/projects.yaml` exists, so
|
|
170
|
+
running `gitgatekeeper` from inside a checkout does not hide your real config. A
|
|
171
|
+
local file that cannot be parsed is still used, so its error is shown.
|
|
172
|
+
`gitgatekeeper start` prints the file in use on its `Config:` line.
|
|
173
|
+
|
|
174
|
+
See [`config/projects.example.yaml`](https://github.com/robertofilho0/GitGatekeeper/blob/main/config/projects.example.yaml):
|
|
175
|
+
|
|
176
|
+
```yaml
|
|
177
|
+
inactivity_minutes: 10 # global default
|
|
178
|
+
auto_push: false # global default
|
|
179
|
+
projects:
|
|
180
|
+
- name: my-project
|
|
181
|
+
path: /home/you/projects/my-project
|
|
182
|
+
enabled: true
|
|
183
|
+
- name: notes
|
|
184
|
+
path: /home/you/notes
|
|
185
|
+
inactivity_minutes: 30 # per-project override
|
|
186
|
+
auto_push: true
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Protected branches and split commits
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
protected_branches: [main, master] # default; names or globs ("release/*")
|
|
193
|
+
split_commits: true # default
|
|
194
|
+
max_files_per_commit: 50 # default; a cycle with more files commits nothing
|
|
195
|
+
projects:
|
|
196
|
+
- name: my-project
|
|
197
|
+
path: /home/you/projects/my-project
|
|
198
|
+
protected_branches: [main, "release/*"] # per-project override
|
|
199
|
+
split_commits: false
|
|
200
|
+
max_files_per_commit: 150 # per-project override (1-2000)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- **Protected branches.** GitGatekeeper never commits on a protected branch, and
|
|
204
|
+
never pushes a protected branch, nor a feature branch whose upstream is a
|
|
205
|
+
protected branch. The cycle is skipped and logged (`protected-branch`), and
|
|
206
|
+
your files are left untouched. Work on a feature branch, or set
|
|
207
|
+
`protected_branches: []` to switch the protection off. `gitgatekeeper status`
|
|
208
|
+
shows the current branch (with `↑N` for unpushed commits) and marks
|
|
209
|
+
protected ones. Run `gitgatekeeper check` once before turning `auto_push` on.
|
|
210
|
+
- **Split commits.** One cycle can produce several commits: each module's code
|
|
211
|
+
together with its tests, then documentation, then build/configuration files.
|
|
212
|
+
Each commit gets its own message. If a group cannot be committed (for example
|
|
213
|
+
a possible secret), the cycle stops there and the remaining files are retried
|
|
214
|
+
next time. When there would be more than six groups (typical of layered
|
|
215
|
+
folders such as `Models/`, `Actions/`), GitGatekeeper falls back to broad areas:
|
|
216
|
+
database, code, tests, docs, config. A single group means one commit.
|
|
217
|
+
|
|
218
|
+
### End-of-day commit
|
|
219
|
+
|
|
220
|
+
Once a day, at `daily_commit_time` (local time, default `23:55` so the commit
|
|
221
|
+
still lands on the day it is for), GitGatekeeper looks at every project and runs the
|
|
222
|
+
normal commit cycle for those that:
|
|
223
|
+
|
|
224
|
+
- have pending changes,
|
|
225
|
+
- were worked on today (activity seen while GitGatekeeper ran, or a changed file
|
|
226
|
+
written today),
|
|
227
|
+
- have no GitGatekeeper commit yet today,
|
|
228
|
+
- are not on a protected branch.
|
|
229
|
+
|
|
230
|
+
Everything else applies as always: split commits, the file limit, the secret
|
|
231
|
+
scan and `auto_push`. It is on by default; set `daily_commit: false` globally or
|
|
232
|
+
per project to turn it off. Apply a change to a running service with
|
|
233
|
+
`gitgatekeeper reload` (see [Reloading the configuration](#reloading-the-configuration)).
|
|
234
|
+
|
|
235
|
+
### Approving commits
|
|
236
|
+
|
|
237
|
+
With `require_approval: true` (globally or per project) GitGatekeeper does all the
|
|
238
|
+
work of a normal cycle (the same checks, the same message, the same split into
|
|
239
|
+
groups) but stops short of committing. The prepared commits wait in the local
|
|
240
|
+
history database:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
gitgatekeeper pending --files # what is waiting, with the files of each
|
|
244
|
+
gitgatekeeper approve 3 # commit proposal #3
|
|
245
|
+
gitgatekeeper approve --all # commit everything that waits, oldest first
|
|
246
|
+
gitgatekeeper reject 4 # discard proposal #4; the files stay as they are
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
What approving guarantees:
|
|
250
|
+
|
|
251
|
+
- The commit is made only if the files are **byte-for-byte what was proposed**
|
|
252
|
+
and the repository is on the **same branch**. Otherwise nothing is committed
|
|
253
|
+
and the proposal is closed as stale; GitGatekeeper prepares a new one at the next
|
|
254
|
+
cycle.
|
|
255
|
+
- The commit message is the one you were shown.
|
|
256
|
+
- Every guard still applies at approval time: protected branches, the secret
|
|
257
|
+
scan, conflict markers and the repository lock. Your own staged files are left
|
|
258
|
+
alone.
|
|
259
|
+
- If `auto_push` is on for the project, approving also pushes, with the usual
|
|
260
|
+
push rules.
|
|
261
|
+
|
|
262
|
+
A rejection holds until the files change: the same change set is not proposed
|
|
263
|
+
again. Committing by hand closes the matching proposal on its own. Nothing is
|
|
264
|
+
ever committed without your decision on a project that requires approval,
|
|
265
|
+
including the end-of-day commit. `gitgatekeeper status` tells you when commits are
|
|
266
|
+
waiting. Apply a change to `require_approval` with `gitgatekeeper reload`.
|
|
267
|
+
|
|
268
|
+
### Conflict markers
|
|
269
|
+
|
|
270
|
+
A file whose staged lines contain a `<<<<<<<` ... `>>>>>>>` block is never
|
|
271
|
+
committed (`blocked`, with `path:line`): that is an unresolved merge or stash
|
|
272
|
+
conflict. Resolve the file and the next cycle commits it.
|
|
273
|
+
|
|
274
|
+
### Secret scan and false positives
|
|
275
|
+
|
|
276
|
+
Before every commit GitGatekeeper scans the added lines. Well-known token formats
|
|
277
|
+
(AWS, GitHub, Slack, private keys, URLs with passwords) and secret-looking file
|
|
278
|
+
names always stop the cycle, and so does a hard-coded `password = "..."`-style
|
|
279
|
+
assignment. The log says where to look (`path:line (rule)`), never the value.
|
|
280
|
+
|
|
281
|
+
If a file legitimately holds example or test values (a README with a `curl`
|
|
282
|
+
sample, a test factory), list it for that project:
|
|
283
|
+
|
|
284
|
+
```yaml
|
|
285
|
+
projects:
|
|
286
|
+
- name: my-project
|
|
287
|
+
path: /home/you/projects/my-project
|
|
288
|
+
secret_scan_allow:
|
|
289
|
+
- README.md
|
|
290
|
+
- "api/*/Factories/*.php"
|
|
291
|
+
- tests/ # a trailing slash means "everything below"
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
This relaxes only the `password = "..."` heuristic in those files. Real token
|
|
295
|
+
formats, credentials in URLs and sensitive file names are still checked there.
|
|
296
|
+
|
|
297
|
+
Only the first 2000 added lines of a file are scanned, and a file longer than
|
|
298
|
+
that is not committed (`unverifiable-content`). Generated dependency lockfiles
|
|
299
|
+
(`package-lock.json`, `composer.lock`, `yarn.lock`, `Cargo.lock`...) are the
|
|
300
|
+
exception: what can be read is still scanned, and the rest is let through.
|
|
301
|
+
|
|
302
|
+
URLs with credentials are judged on their own. These never count as secrets:
|
|
303
|
+
a placeholder or stock password (`password`, `postgres`, `changeme`, `${TOKEN}`,
|
|
304
|
+
`<password>`...) and, inside `.env.example`-style templates only, a password on
|
|
305
|
+
a local host (`localhost`, `127.0.0.1`, `host.docker.internal` or a bare service
|
|
306
|
+
name such as `db`). A real-looking password on a public host stops the cycle
|
|
307
|
+
anywhere, templates included.
|
|
308
|
+
|
|
309
|
+
You rarely need to edit it by hand: `gitgatekeeper add <path>` registers a repository.
|
|
310
|
+
Keep your real `config/projects.yaml` out of version control.
|
|
311
|
+
|
|
312
|
+
### Reloading the configuration
|
|
313
|
+
|
|
314
|
+
After editing the file (or after `gitgatekeeper add`, `remove`, `enable`, `disable`),
|
|
315
|
+
tell the running service to re-read it, without stopping:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
gitgatekeeper reload
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
- A file that cannot be read, or that enables no project, is **refused**: the
|
|
322
|
+
running configuration stays in force and the command exits 1 with the reason.
|
|
323
|
+
- A change of settings only (`auto_push`, `require_approval`, protected
|
|
324
|
+
branches, limits...) applies at once and does not interrupt the watchers.
|
|
325
|
+
- Adding, removing or moving a project, or changing an inactivity window,
|
|
326
|
+
restarts the watchers. A commit cycle that is running finishes first; the
|
|
327
|
+
history, the waiting approvals and the push retries are kept.
|
|
328
|
+
- If the new watchers cannot start, the previous configuration is restored.
|
|
329
|
+
- It works through `SIGUSR1`, sent only to a process that is verifiably
|
|
330
|
+
GitGatekeeper. A service started before this feature existed does not know the
|
|
331
|
+
signal and would be killed by it, so `gitgatekeeper reload` refuses and asks you to
|
|
332
|
+
restart it once.
|
|
333
|
+
|
|
334
|
+
State (database, logs, locks, pid file) lives in `$GITGATEKEEPER_STATE_DIR`, else
|
|
335
|
+
`$XDG_STATE_HOME/gitgatekeeper`, else `~/.local/state/gitgatekeeper`. Every command that
|
|
336
|
+
needs it also accepts `--state-dir`.
|
|
337
|
+
|
|
338
|
+
### Taking a commit back
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
gitgatekeeper undo my-project # shows the commit and asks first
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
`undo` removes the last commit GitGatekeeper made in that project from the
|
|
345
|
+
branch and leaves **every file exactly as it is**: the changes simply go back to
|
|
346
|
+
being unstaged. Under the hood it is `git reset --mixed <parent>`, never
|
|
347
|
+
`--hard`. It refuses, and says why, when:
|
|
348
|
+
|
|
349
|
+
- the commit was already pushed (GitGatekeeper never rewrites published history;
|
|
350
|
+
it points you to `git revert` instead);
|
|
351
|
+
- it is no longer the latest commit of the branch;
|
|
352
|
+
- you have staged changes of your own, which the reset would drop;
|
|
353
|
+
- a merge, rebase, cherry-pick or similar is in progress, or Git is busy;
|
|
354
|
+
- GitGatekeeper is in the middle of a cycle on that repository (try again).
|
|
355
|
+
|
|
356
|
+
The same set of changes is **not committed again automatically**; once you edit
|
|
357
|
+
the files, the new version is committed after the usual inactivity. The undone
|
|
358
|
+
commit stays in Git's reflog, and `undo` prints the command that puts it back
|
|
359
|
+
(`git reset <oid>`). `gitgatekeeper history` shows it as undone.
|
|
360
|
+
|
|
361
|
+
## Command line
|
|
362
|
+
|
|
363
|
+
| Command | What it does |
|
|
364
|
+
| --- | --- |
|
|
365
|
+
| `gitgatekeeper version` | Print the version. |
|
|
366
|
+
| `gitgatekeeper projects` | List registered projects and whether each path is a valid repository. |
|
|
367
|
+
| `gitgatekeeper init [--root PATH]... [--depth N] [--yes]` | First-time setup: find repositories under your code folders and register the ones you choose. |
|
|
368
|
+
| `gitgatekeeper migrate` | Copy your configuration and history from the old name (GitPilot). Copies only; never deletes. |
|
|
369
|
+
| `gitgatekeeper add <path> [--name N]` | Register the repository that contains `<path>`. |
|
|
370
|
+
| `gitgatekeeper remove <name>` | Unregister a project. The repository is never touched. |
|
|
371
|
+
| `gitgatekeeper enable <name>` | Turn monitoring of a project on. |
|
|
372
|
+
| `gitgatekeeper disable <name>` | Turn monitoring of a project off. |
|
|
373
|
+
| `gitgatekeeper profile <name> [-p FILE]` | Show how GitGatekeeper sees a project's architecture, and which module a file belongs to. |
|
|
374
|
+
| `gitgatekeeper start` | Run in the foreground until Ctrl+C or `gitgatekeeper stop`. |
|
|
375
|
+
| `gitgatekeeper stop` | Ask the running instance to stop (SIGTERM only, never SIGKILL). |
|
|
376
|
+
| `gitgatekeeper check [name] [--offline]` | Read-only readiness check per project: Git identity, protected branch, upstream, `auto_push`, commits behind/ahead, each problem with the command that fixes it. Also asks the remote once (`git ls-remote`, never prompting) whether it is reachable and accepts you; `--offline` skips that. Exits 1 on a blocking problem. |
|
|
377
|
+
| `gitgatekeeper reload [--timeout S]` | Make the running service re-read its configuration without a restart. An invalid file is refused and the old configuration stays. |
|
|
378
|
+
| `gitgatekeeper status` | Whether it is running, and per project: state, idle time, time to next cycle, pending files, last commit. |
|
|
379
|
+
| `gitgatekeeper history [-p NAME] [-n N] [--files]` | Commits GitGatekeeper made, and whether each was pushed. |
|
|
380
|
+
| `gitgatekeeper pending [-p NAME] [--files]` | Commits prepared and held for your approval (see [Approving commits](#approving-commits)). |
|
|
381
|
+
| `gitgatekeeper approve <id>... \| --all [-p NAME]` | Commit what was prepared, if the files are still exactly as proposed. |
|
|
382
|
+
| `gitgatekeeper reject <id>... \| --all [-p NAME]` | Discard prepared commits. Your files are not touched. |
|
|
383
|
+
| `gitgatekeeper service install [--no-start] [--force]` | Install and enable GitGatekeeper as a systemd user service (see [below](#running-as-a-systemd-user-service)). |
|
|
384
|
+
| `gitgatekeeper service uninstall` | Stop, disable and remove that service. |
|
|
385
|
+
| `gitgatekeeper service status` | Whether the service is installed, enabled and running. |
|
|
386
|
+
| `gitgatekeeper undo <project> [--yes]` | Take back the last commit GitGatekeeper made in a project; your files are left exactly as they are. Refused if it was pushed (see [Taking a commit back](#taking-a-commit-back)). |
|
|
387
|
+
| `gitgatekeeper logs [-p NAME] [--kind commit\|push] [-n N] [--raw]` | Recent cycle events; `--raw` tails the JSON log file. |
|
|
388
|
+
|
|
389
|
+
`start` runs in the foreground on purpose. To keep it running in the background
|
|
390
|
+
use a supervisor such as systemd (below). Only one instance can run per state
|
|
391
|
+
directory.
|
|
392
|
+
|
|
393
|
+
## Running on Ubuntu
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
cd ~/Agents/GitGatekeeper
|
|
397
|
+
source .venv/bin/activate
|
|
398
|
+
|
|
399
|
+
gitgatekeeper add ~/projects/my-project
|
|
400
|
+
gitgatekeeper projects
|
|
401
|
+
gitgatekeeper start # leave it running in a terminal
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
In another terminal:
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
gitgatekeeper status
|
|
408
|
+
gitgatekeeper history
|
|
409
|
+
gitgatekeeper stop
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Try it on a throwaway repository first.
|
|
413
|
+
|
|
414
|
+
## Running as a systemd user service
|
|
415
|
+
|
|
416
|
+
The easy way, after `gitgatekeeper init`:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
gitgatekeeper service install # writes ~/.config/systemd/user/gitgatekeeper.service, enables and starts it
|
|
420
|
+
gitgatekeeper service status
|
|
421
|
+
gitgatekeeper service uninstall # stops, disables and removes it
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
`install` uses the `gitgatekeeper` executable of the environment you run it from and
|
|
425
|
+
the configuration file in use, both as absolute paths, so run it with your
|
|
426
|
+
virtualenv active. It writes only that one file under your own config directory
|
|
427
|
+
(`$XDG_CONFIG_HOME/systemd/user`) and calls only `systemctl --user`. It refuses
|
|
428
|
+
to replace a different unit unless you add `--force`, and refuses to start while
|
|
429
|
+
a foreground `gitgatekeeper start` is running (stop it first or use `--no-start`).
|
|
430
|
+
If it finds your desktop's SSH agent socket it adds `SSH_AUTH_SOCK` to the unit.
|
|
431
|
+
It never changes anything system-wide. After you change the configuration, use
|
|
432
|
+
`gitgatekeeper reload`; after upgrading GitGatekeeper, run `gitgatekeeper service install
|
|
433
|
+
--force` only if the executable path changed.
|
|
434
|
+
|
|
435
|
+
To manage the unit by hand instead, GitGatekeeper ships a template,
|
|
436
|
+
[`deploy/systemd/gitgatekeeper.service`](https://github.com/robertofilho0/GitGatekeeper/blob/main/deploy/systemd/gitgatekeeper.service):
|
|
437
|
+
|
|
438
|
+
```bash
|
|
439
|
+
mkdir -p ~/.config/systemd/user
|
|
440
|
+
cp deploy/systemd/gitgatekeeper.service ~/.config/systemd/user/gitgatekeeper.service
|
|
441
|
+
$EDITOR ~/.config/systemd/user/gitgatekeeper.service # check the two paths
|
|
442
|
+
|
|
443
|
+
systemctl --user daemon-reload
|
|
444
|
+
systemctl --user enable --now gitgatekeeper.service
|
|
445
|
+
systemctl --user status gitgatekeeper.service
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
To stop and remove it by hand:
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
systemctl --user disable --now gitgatekeeper.service
|
|
452
|
+
rm ~/.config/systemd/user/gitgatekeeper.service
|
|
453
|
+
systemctl --user daemon-reload
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Notes:
|
|
457
|
+
|
|
458
|
+
- By default a user service runs only while you are logged in. To keep it running
|
|
459
|
+
without a login session, run `loginctl enable-linger $USER` yourself; GitGatekeeper
|
|
460
|
+
never does that.
|
|
461
|
+
- GitGatekeeper writes its own JSON log (`gitgatekeeper logs --raw`), so `journalctl
|
|
462
|
+
--user -u gitgatekeeper` shows little more than start and stop.
|
|
463
|
+
- Pushing over SSH needs a key GitGatekeeper can use without a prompt. GitGatekeeper never
|
|
464
|
+
asks for passwords and never changes your authentication setup. Either use a
|
|
465
|
+
key without a passphrase for that remote, or uncomment the `SSH_AUTH_SOCK`
|
|
466
|
+
line in the unit that matches your desktop's SSH agent (`service install`
|
|
467
|
+
already does this when it finds the socket).
|
|
468
|
+
- On stop, systemd sends SIGTERM and waits up to 60 seconds before escalating, so
|
|
469
|
+
a commit in progress can finish.
|
|
470
|
+
|
|
471
|
+
## Security model
|
|
472
|
+
|
|
473
|
+
These rules are enforced in code and covered by tests. They are not settings.
|
|
474
|
+
|
|
475
|
+
**Git operations**
|
|
476
|
+
|
|
477
|
+
- Never runs `git reset --hard`, `git clean` or `git push --force` (no `+` in
|
|
478
|
+
the push refspec either), and never overwrites existing changes.
|
|
479
|
+
- Never runs a commit during a merge, rebase, cherry-pick, revert or bisect, on
|
|
480
|
+
a detached HEAD, with conflicts, or while an `index.lock` exists.
|
|
481
|
+
- Never creates empty commits.
|
|
482
|
+
- Verifies repository state before and after every Git operation. If the state
|
|
483
|
+
changed underneath it, it rolls back its own staging and stops.
|
|
484
|
+
- Respects `.gitignore`.
|
|
485
|
+
|
|
486
|
+
**Your work stays yours**
|
|
487
|
+
|
|
488
|
+
- Files you staged yourself (including partially staged files) are never added
|
|
489
|
+
to a GitGatekeeper commit, and stay staged afterwards.
|
|
490
|
+
- GitGatekeeper commits only paths it selected, using literal pathspecs, so unusual
|
|
491
|
+
file names cannot widen a commit.
|
|
492
|
+
- It does not assume every change in a repository belongs to it. When it cannot
|
|
493
|
+
separate its changes safely, it skips the cycle and records the reason.
|
|
494
|
+
|
|
495
|
+
**Secrets**
|
|
496
|
+
|
|
497
|
+
- Files that commonly hold secrets (`.env`, private keys, tokens, credentials,
|
|
498
|
+
cloud and SSH config...) are never selected.
|
|
499
|
+
- Added lines are scanned for credential patterns. A match aborts the whole
|
|
500
|
+
cycle and the finding is recorded, without its value.
|
|
501
|
+
- Content that cannot be verified (too large, unreadable) is not committed.
|
|
502
|
+
|
|
503
|
+
**Push**
|
|
504
|
+
|
|
505
|
+
- Off by default (`auto_push: false`); enabled per project or globally.
|
|
506
|
+
- Pushes only the current branch to its already configured upstream. It never
|
|
507
|
+
creates an upstream, and skips when there is none or when the branch is behind.
|
|
508
|
+
- Pushes only commits GitGatekeeper itself recorded. Your own unpublished commits are
|
|
509
|
+
never published by it.
|
|
510
|
+
- Never changes your Git or SSH authentication configuration and never prompts.
|
|
511
|
+
If a push fails, the local commit is kept.
|
|
512
|
+
- Credentials embedded in URLs are masked in logs and errors.
|
|
513
|
+
|
|
514
|
+
**Process**
|
|
515
|
+
|
|
516
|
+
- No `shell=True`; every external process has a timeout.
|
|
517
|
+
- One lock per repository; a separate lock for push.
|
|
518
|
+
- Duplicate-commit protection through a content fingerprint.
|
|
519
|
+
- Single instance per state directory; `stop` signals only a process that holds
|
|
520
|
+
the instance lock and looks like GitGatekeeper.
|
|
521
|
+
- State, log and database files are private (`0600`, directories `0700`).
|
|
522
|
+
|
|
523
|
+
## Commit messages
|
|
524
|
+
|
|
525
|
+
Messages follow Conventional Commits: `type(scope): subject`, plus a body that
|
|
526
|
+
lists what changed in each file. They are built from what the diff and the code
|
|
527
|
+
actually show, never from guesses:
|
|
528
|
+
|
|
529
|
+
- **What changed.** For source files GitGatekeeper finds the functions, classes and
|
|
530
|
+
methods that contain the changed lines (`Cart.total`), for stylesheets the
|
|
531
|
+
selectors (`heatmap`, `stats`), and for Markdown the sections you edited.
|
|
532
|
+
- **Where it changed.** The scope is the module that owns most of the change
|
|
533
|
+
(`feat(activity): ...`). Modules are detected from your project's layout, for
|
|
534
|
+
example `src/<package>/<module>/` in Python, or `ActivityService.php` giving
|
|
535
|
+
`activity`.
|
|
536
|
+
- **Why (type).** `feat`, `fix`, `refactor`, `docs`, `test`, `style`, `perf`,
|
|
537
|
+
`build`, `ci` or `chore`, from the kinds of files, the structure of the change
|
|
538
|
+
and keywords. Every decision and its confidence are stored with the commit.
|
|
539
|
+
|
|
540
|
+
Examples of what you get:
|
|
541
|
+
|
|
542
|
+
```
|
|
543
|
+
feat(activity): add ActivityService and JsonStore
|
|
544
|
+
|
|
545
|
+
- added src/ActivityService.php (+203/-0): ActivityService, setDone, doneOn, grid
|
|
546
|
+
- added src/JsonStore.php (+129/-0): JsonStore, read, update
|
|
547
|
+
- modified style.css (+89/-2): heatmap, stats, shift
|
|
548
|
+
|
|
549
|
+
docs: document Testes and Calendário de constância section
|
|
550
|
+
fix(core): update ActivityService.streaks
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
When nothing specific can be said, the message stays plain rather than invented.
|
|
554
|
+
Secret files and lines are never read into a message.
|
|
555
|
+
|
|
556
|
+
### Telling GitGatekeeper about your architecture (optional)
|
|
557
|
+
|
|
558
|
+
Detection works without any setup. To name modules yourself, add a `modules`
|
|
559
|
+
block to a project in `projects.yaml` (folder prefixes or globs, relative to the
|
|
560
|
+
repository). The first matching module wins:
|
|
561
|
+
|
|
562
|
+
```yaml
|
|
563
|
+
projects:
|
|
564
|
+
- name: shop
|
|
565
|
+
path: /home/you/shop
|
|
566
|
+
modules:
|
|
567
|
+
payments: [src/billing, "app/**/*Invoice*.php"]
|
|
568
|
+
ui: [assets/css, resources/views]
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
Check what GitGatekeeper understood with:
|
|
572
|
+
|
|
573
|
+
```bash
|
|
574
|
+
gitgatekeeper profile shop -p src/billing/tax.py -p assets/css/site.css
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
## Data and logs
|
|
578
|
+
|
|
579
|
+
- `gitgatekeeper.db`: SQLite (WAL). Tables `commits` and `events`; old events are
|
|
580
|
+
pruned automatically.
|
|
581
|
+
- `logs/gitgatekeeper.log`: JSON lines, rotated (5 MB x 3).
|
|
582
|
+
- `status.json`: live snapshot used by `gitgatekeeper status`; removed on stop.
|
|
583
|
+
- `locks/`, `gitgatekeeper.pid`: coordination files.
|
|
584
|
+
|
|
585
|
+
## Tests
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
source .venv/bin/activate
|
|
589
|
+
ruff check .
|
|
590
|
+
ruff format --check .
|
|
591
|
+
pytest -q
|
|
592
|
+
pytest --cov=gitgatekeeper --cov-report=term-missing # coverage
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
Tests use temporary directories and isolated repositories with a hermetic Git
|
|
596
|
+
environment. They never touch your real repositories or your GitGatekeeper state.
|
|
597
|
+
|
|
598
|
+
Some tests guard the project's promises: no module may import network libraries,
|
|
599
|
+
runtime dependencies are limited to `watchdog`, `pydantic`, `pyyaml`, `typer` and
|
|
600
|
+
`rich`, and only the push engine (`git push`) and `gitgatekeeper check` (`git ls-remote`,
|
|
601
|
+
read-only) may talk to a remote.
|
|
602
|
+
|
|
603
|
+
## Known limitations
|
|
604
|
+
|
|
605
|
+
- A push that failed because of the network or a timeout is retried after 1, 5,
|
|
606
|
+
15 and then every 30 minutes (six retries); other failures (rejected, auth,
|
|
607
|
+
behind upstream) are not retried until the next cycle or restart.
|
|
608
|
+
- Approval is local: there is no e-mail or phone notification for waiting
|
|
609
|
+
commits yet; look at `gitgatekeeper pending` or `gitgatekeeper status`.
|
|
610
|
+
- If the process dies between creating a commit and recording it, that commit is
|
|
611
|
+
left unrecorded. GitGatekeeper will never push such a commit.
|
|
612
|
+
- Idle time and countdowns in `gitgatekeeper status` exist only while the service runs.
|
|
613
|
+
- Linux only.
|
|
614
|
+
|
|
615
|
+
## Roadmap
|
|
616
|
+
|
|
617
|
+
- A command to preview what the next commit of a project would contain.
|
|
618
|
+
- More languages in the code-context analysis (Java, C#, Ruby, Kotlin...).
|
|
619
|
+
- Tests and fixes for worktrees, submodules, Git LFS and very large repositories.
|
|
620
|
+
- macOS and Windows support.
|
|
621
|
+
- Desktop notifications.
|
|
622
|
+
|
|
623
|
+
## Releasing
|
|
624
|
+
|
|
625
|
+
Every push and pull request runs `ruff`, the format check and the tests on
|
|
626
|
+
Python 3.12 and 3.13, builds the package, checks it with `twine check --strict`
|
|
627
|
+
and installs the wheel in a clean environment (`.github/workflows/ci.yml`).
|
|
628
|
+
|
|
629
|
+
Releases are published to [PyPI](https://pypi.org/project/gitgatekeeper/) by
|
|
630
|
+
`.github/workflows/release.yml` using Trusted Publishing: there is no API token
|
|
631
|
+
or secret in the repository. Pushing a tag builds and checks the package, then
|
|
632
|
+
waits for the maintainer's approval before uploading it.
|
|
633
|
+
|
|
634
|
+
```bash
|
|
635
|
+
# 1. set `version` in pyproject.toml, update CHANGELOG.md, commit and push
|
|
636
|
+
# 2. tag it; the tag must match the version, or the workflow stops
|
|
637
|
+
git tag -a v0.1.1 -m "v0.1.1" && git push origin v0.1.1
|
|
638
|
+
# 3. approve the upload under Actions, then create the GitHub release
|
|
639
|
+
gh release create v0.1.1 --title "v0.1.1" --notes-file CHANGELOG.md
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
A manual run of the workflow (Actions > Release > Run workflow) uploads the same
|
|
643
|
+
files to TestPyPI instead, to rehearse a release.
|
|
644
|
+
|
|
645
|
+
## Similar projects
|
|
646
|
+
|
|
647
|
+
Other tools also commit automatically. These descriptions are the projects' own
|
|
648
|
+
one-line summaries as listed when this was written; read their pages for the
|
|
649
|
+
current picture.
|
|
650
|
+
|
|
651
|
+
- `gitpilot-ai`: "Local AI-powered Git auto-committer daemon".
|
|
652
|
+
- `smart-autocommit`: "deterministic gates decide what may enter history; the LLM
|
|
653
|
+
only writes messages and researches unknown paths, and never blocks a commit".
|
|
654
|
+
- `git-worklog`: generates worklogs, reports and changelogs from Git history.
|
|
655
|
+
|
|
656
|
+
GitGatekeeper's emphasis is different: the messages come from rules rather than a
|
|
657
|
+
language model, everything stays on your machine, and the safety model is the
|
|
658
|
+
point (protected branches, secret scan, an approval queue, `undo`, and nothing
|
|
659
|
+
destructive).
|
|
660
|
+
|
|
661
|
+
## Contributing
|
|
662
|
+
|
|
663
|
+
See [CONTRIBUTING.md](https://github.com/robertofilho0/GitGatekeeper/blob/main/CONTRIBUTING.md) for the setup, the checks every change
|
|
664
|
+
must pass and the rules that do not bend, [SECURITY.md](https://github.com/robertofilho0/GitGatekeeper/blob/main/SECURITY.md) to report a
|
|
665
|
+
vulnerability privately, and the [Code of Conduct](https://github.com/robertofilho0/GitGatekeeper/blob/main/CODE_OF_CONDUCT.md). Changes
|
|
666
|
+
that weaken a rule in the [Security model](#security-model) will not be accepted
|
|
667
|
+
without a very good reason and a test proving the new behaviour is safe.
|
|
668
|
+
|
|
669
|
+
## License
|
|
670
|
+
|
|
671
|
+
[MIT](https://github.com/robertofilho0/GitGatekeeper/blob/main/LICENSE).
|