# Git Hook Testing Guide

**Last Updated:** 2026-01-13

Guide for testing the blog post date detection git hook to ensure it correctly identifies content changes vs metadata changes.

## Test Scenarios

### Test Case 1: Content Change (Should Update Date)

**Steps:**

1. Edit `title` field in a blog post JSON file
2. Stage the file: `git add v2/data/blog/posts/ratgeber/test-post.json`
3. Commit: `git commit -m "test: Update title"`
4. Check git hook output

**Expected Result:**

- Hook detects content change
- `modified_date` updates to current time
- `_content_hash` updates
- File is automatically staged

**Verify:**

```bash
# Check modified_date was updated
grep modified_date v2/data/blog/posts/ratgeber/test-post.json

# Check _content_hash was updated
grep _content_hash v2/data/blog/posts/ratgeber/test-post.json
```

### Test Case 2: Metadata Change Only (Should NOT Update Date)

**Steps:**

1. Edit `related_posts` field (add/remove a post) in a blog post JSON file
2. Stage the file: `git add v2/data/blog/posts/ratgeber/test-post.json`
3. Commit: `git commit -m "test: Update related posts"`
4. Check git hook output

**Expected Result:**

- Hook detects no content change
- `modified_date` does NOT update
- `_content_hash` does NOT update
- Commit proceeds normally

**Verify:**

```bash
# Check modified_date was NOT updated (should be same as before)
grep modified_date v2/data/blog/posts/ratgeber/test-post.json

# Check _content_hash was NOT updated
grep _content_hash v2/data/blog/posts/ratgeber/test-post.json
```

### Test Case 3: Formatting Change Only (Should NOT Update Date)

**Steps:**

1. Reformat JSON file (change whitespace, indentation) without changing content
2. Stage the file: `git add v2/data/blog/posts/ratgeber/test-post.json`
3. Commit: `git commit -m "test: Reformat JSON"`
4. Check git hook output

**Expected Result:**

- Hook detects no content change
- `modified_date` does NOT update
- `_content_hash` does NOT update
- Commit proceeds normally

**Verify:**

```bash
# Check modified_date was NOT updated
grep modified_date v2/data/blog/posts/ratgeber/test-post.json
```

### Test Case 4: Field Addition Only (Should NOT Update Date)

**Steps:**

1. Add a new metadata field (e.g., `"_test_field": "test"`) to a blog post JSON file
2. Stage the file: `git add v2/data/blog/posts/ratgeber/test-post.json`
3. Commit: `git commit -m "test: Add test field"`
4. Check git hook output

**Expected Result:**

- Hook detects no content change
- `modified_date` does NOT update
- `_content_hash` does NOT update
- Commit proceeds normally

## Manual Testing

### Test Hook Execution

```bash
# Test hook manually (without committing)
bash scripts/blog/pre-commit-detect-changes.sh
```

### Test Content Detection Script

```bash
# Dry run to see what would change
php v2/scripts/blog/detect-content-changes.php --verbose

# Actually update (use with caution)
php v2/scripts/blog/detect-content-changes.php --update
```

### Check Hook Logs

```bash
# View content detection log
cat /tmp/blog-detect-changes.log
```

## Troubleshooting

### Hook Not Running

**Check:**

```bash
# Verify hook is executable
ls -l .git/hooks/pre-commit

# Make executable if needed
chmod +x .git/hooks/pre-commit
chmod +x scripts/blog/pre-commit-detect-changes.sh
```

### Dates Not Updating When They Should

**Check:**

1. Verify content actually changed (title, HTML, excerpt, meta, featured image)
2. Check content hash: `grep _content_hash v2/data/blog/posts/.../post.json`
3. Run detection script manually: `php v2/scripts/blog/detect-content-changes.php --verbose`
4. Check log file: `cat /tmp/blog-detect-changes.log`

### Dates Updating When They Shouldn't

**Check:**

1. Verify only metadata changed (related_posts, topics, etc.)
2. Check if content hash changed: `grep _content_hash v2/data/blog/posts/.../post.json`
3. Review what fields are tracked (title, HTML, excerpt, meta, featured image)
4. Ensure sync script is NOT running (it's removed from git hook)

## Related Documentation

- [Date Management Guide](DATE_MANAGEMENT_GUIDE.md) - Complete date management guide
- [Last Updated Date Review](../LAST_UPDATED_DATE_REVIEW.md) - System review and status
