Skip to content

Commit 6600ded

Browse files
committed
docs: add git integration demo example
1 parent 7efd685 commit 6600ded

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

examples/git_integration_demo.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Code-Guardian Git Integration Demo
2+
3+
This document demonstrates the new git integration features in Code-Guardian.
4+
5+
## Features
6+
7+
### 1. Pre-commit Hook Installation
8+
9+
Install the pre-commit hook to automatically run Code-Guardian before each commit:
10+
11+
```bash
12+
# Install the hook
13+
code-guardian git install-hook
14+
15+
# The hook will now run automatically on every commit
16+
git commit -m "Your commit message"
17+
```
18+
19+
### 2. Staged Files Scanning
20+
21+
Scan only staged files instead of the entire repository:
22+
23+
```bash
24+
# Scan only staged files
25+
code-guardian pre-commit --staged-only
26+
27+
# Fast scan of staged files (critical issues only)
28+
code-guardian pre-commit --staged-only --fast
29+
```
30+
31+
### 3. Git Integration Commands
32+
33+
```bash
34+
# List currently staged files
35+
code-guardian git staged
36+
37+
# Install pre-commit hook
38+
code-guardian git install-hook
39+
40+
# Uninstall pre-commit hook
41+
code-guardian git uninstall-hook
42+
```
43+
44+
## Workflow Integration
45+
46+
### Typical Developer Workflow
47+
48+
1. **One-time setup**: Install the pre-commit hook
49+
```bash
50+
code-guardian git install-hook
51+
```
52+
53+
2. **Daily development**: Work normally - the hook runs automatically
54+
```bash
55+
# Make changes
56+
vim src/main.rs
57+
58+
# Stage changes
59+
git add src/main.rs
60+
61+
# Commit (hook runs automatically)
62+
git commit -m "Add new feature"
63+
```
64+
65+
3. **Manual scanning**: Check staged files before committing
66+
```bash
67+
# See what files are staged
68+
code-guardian git staged
69+
70+
# Run manual pre-commit check
71+
code-guardian pre-commit --staged-only --fast
72+
```
73+
74+
### CI/CD Integration
75+
76+
The git integration works seamlessly with CI/CD pipelines:
77+
78+
```yaml
79+
# .github/workflows/code-quality.yml
80+
- name: Run Code-Guardian on changed files
81+
run: |
82+
# Get list of changed files in PR
83+
git fetch origin main
84+
git diff --name-only origin/main... > changed_files.txt
85+
86+
# Run Code-Guardian on changed files
87+
code-guardian scan --files-from changed_files.txt
88+
```
89+
90+
## Benefits
91+
92+
- **Faster feedback**: Catch issues at commit time, not in CI
93+
- **Focused scanning**: Only scan files you're actually changing
94+
- **Team adoption**: Automatic enforcement through git hooks
95+
- **Flexible**: Works with both individual commits and CI/CD pipelines
96+
97+
## Technical Implementation
98+
99+
The git integration uses:
100+
- `git diff --cached --name-only` to get staged files
101+
- `git rev-parse --show-toplevel` to find repository root
102+
- Native git commands for maximum compatibility
103+
- Graceful fallback to directory scanning when not in a git repo
104+
105+
## Configuration
106+
107+
The pre-commit hook uses these default settings:
108+
- `--staged-only`: Only scan staged files
109+
- `--fast`: Quick scan mode (critical issues only)
110+
111+
You can customize by editing the hook file directly or using a configuration file.

0 commit comments

Comments
 (0)