bgit 0.4.2

User-friendly Git wrapper for beginners, automating essential tasks like adding, committing, and pushing changes. It includes smart rules to avoid common pitfalls, such as accidentally adding sensitive files or directories and has exclusive support for portable hooks!
# 📘 Git Rule Specification: Ensure Git User Name and Email Are Configured

**Rule ID**: `RULE_git-name-email-setup`  
**Status**: Draft  
**Author**: Himanshu Sharma | bgit Team  
**Created**: 2025-04-26  
**Updated**: 2025-04-26  
**Version**: v1.0.0  
**RuleLevel**: Error

<!--  
RuleLevel determines how strictly the rule is enforced:

- `Skip`: The rule is not checked or enforced. Useful for opt-out rules.
- `Warning`: Violations produce a warning and optionally attempt auto-fix, but the operation continues.
- `Error`: Violations cause the operation to fail unless auto-fixed successfully.
-->

---

## 1. Summary

> Verify that both `user.name` and `user.email` are set in Git configuration before allowing commits.

## 2. Scope

### Applies To:
- [x] Developers (local)  
- [x] CI/CD pipelines  
- [ ] GitHub/GitLab Web UI  
- [x] Hooks (pre-commit, pre-push, etc.)  
- [ ] Git config/templates  

### Affects:
- [x] Commits  
- [ ] Branching  
- [ ] Merges  
- [ ] Pushes  
- [ ] Repository layout  
- [ ] Miscellaneous  

### Trigger Point (When to Check):
Before `git commit` is executed, either locally or in automated pipelines.

---

## 3. Motivation

### Problem Statement:
Commits without a configured user name or email may lead to anonymous or incorrect attribution, complicating code ownership tracking and audit trails.

### Objectives:
- Ensure that every commit is properly attributed to a real author.  
- Prevent anonymous or placeholder commits in shared repositories.  
- Enforce consistent commit metadata across all environments.

### Common Pitfall:
A developer clones a repository on a new machine and runs `git commit` without first configuring `user.name` and `user.email`, resulting in an anonymous commit with no clear author.

---

## 4. Rule Definition

### Description:
This rule checks for the presence of both `user.name` and `user.email` in the Git configuration at commit time.

**Allowed:**  
- Commits when both `git config --get user.name` and `git config --get user.email` return non-empty values.

**Forbidden:**  
- Commits when either `user.name` or `user.email` is unset or empty.

---

## 5. Examples

### ✅ Correct Usage
```bash
$ git config --get user.name
Alice Developer
$ git config --get user.email
alice@example.com
$ git commit -m "Add new feature"
[main abc123] Add new feature
```
### ❌ Incorrect Usage
```bash
$ git config --get user.name
$ git config --get user.email
$ git commit -m "Fix bug"
Error: Git user.name and/or user.email is not configured. Please set them before committing.
```

## 6. Impact Assessment

### Frequency of Violation:
- [x] Rare  
- [ ] Occasional  
- [ ] Frequent  

### Severity When Violated:
- [ ] Pedantic (nice to have)  
- [ ] Low (minor inconvenience)  
- [x] Medium (requires cleanup)  
- [ ] High (code breakage, data loss)  
- [ ] Critical (security/legal risk)  

---

## 7. Enforcement Strategy

### Pseudocode / Workflow
```bash
# In pre-commit hook or commit wrapper
if [ -z "$(git config --get user.name)" ] || [ -z "$(git config --get user.email)" ]; then
  echo "Error: Git user.name and/or user.email is not configured."
  echo "Run:"
  echo "  git config --global user.name \"Your Name\""
  echo "  git config --global user.email \"you@example.com\""
  exit 1
fi
```

### Suggested Tooling:
* POSIX-shell pre-commit hook
* CI pipeline step before build/tests
* Custom CLI wrapper around `git commit`

## 8. Possible Fixes

### Manual Fix:
```bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```

### Automated Fix Suggestions:
None (requires user-provided identity information).

## 9. Exceptions & Edge Cases
* Bypass allowed in ephemeral or CI contexts where commits are generated by automation and a machine identity is pre-configured.
* Projects with monorepo workflows that explicitly inject commit metadata via environment variables may exempt this check.

## 10. Drawbacks
Enforcing this rule may block automated scripts that generate commits unless they explicitly configure a service identity in advance.

## 11. Related Rules / RFCs
* `RULE_git-version-consistency`
* `RULE_protect-main-branch`

## 12. Revision History
| Date | Version | Author | Notes |
|------|---------|--------|-------|
| 2025-04-26 | 1.0.0 | Himanshu Sharma | Initial draft |

## 13. Glossary
| Term | Definition |
|------|------------|
| CI | Continuous Integration |
| Hook | Git hook script (e.g. `pre-commit`, `pre-push`) |

## 14. References
* https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
* https://git-scm.com/docs/git-config#Documentation/git-config.txt---getltnamegt