# Release v0.5.1

## Bug Fixes

### Fixed Empty Repository Error (#11)

Fixed a critical bug where `gcop commit` and `gcop stats` would crash with `UnbornBranch` error when run in an empty repository (no commits yet).

**Before:**
```bash
$ git init
$ gcop commit
✗ Error: Git error: reference 'refs/heads/master' not found
         class=Reference (4); code=UnbornBranch (-9)
```

**After:**
```bash
$ git init
$ gcop commit
✗ No staged changes found. Use 'git add' first.

# With staged files, it works normally:
$ echo "test" > test.txt
$ git add test.txt
$ gcop commit
[1/4] Analyzed 1 file(s), 1 change(s)
[2/4] Generating commit message...
# ... continues normally
```

**What was fixed:**

1. **`get_staged_diff()`**: Now correctly handles empty repositories by comparing against an empty tree instead of failing
2. **`get_current_branch()`**: Returns `None` for unborn branches instead of crashing
3. **`get_commit_history()`**: Returns empty list for repositories with no commits
4. **Added `is_empty()` method**: Detects unborn branch state by catching `UnbornBranch` error

**Impact:**

- First-time users can now use `gcop commit` immediately in new repositories
- `gcop stats` shows a friendly warning instead of crashing in empty repos
- Supports creating the first commit in a new repository

## Technical Details

The fix introduces a new `is_empty()` method to the `GitOperations` trait that detects unborn branch state (when a repository has no commits yet). This method is used by three core functions to handle empty repositories gracefully:

- Empty repositories now compare staged changes against an empty tree (None) instead of HEAD
- Branch detection returns None for unborn branches
- Commit history returns an empty vector for empty repositories

All existing tests pass, and the fix has been validated with manual testing in empty repositories.

## Upgrade Notes

Upgrading from v0.5.0 requires **no action**. This is a pure bug fix release with no breaking changes.

## Installation

```bash
# Homebrew (macOS/Linux)
brew tap AptS-1547/gcop-rs
brew upgrade gcop-rs

# pipx (Python users, recommended)
pipx upgrade gcop-rs

# cargo-binstall (no compilation)
cargo binstall gcop-rs

# cargo install (compile from source)
cargo install gcop-rs --force
```

Or download pre-built binaries from [Releases](https://github.com/AptS-1547/gcop-rs/releases).

## Feedback

If you have any issues or suggestions, please submit an [Issue](https://github.com/AptS-1547/gcop-rs/issues).
