Skip to content

Release v0.5.1

Bug 修复

修复空仓库错误 (#11)

修复了一个关键 bug:在空仓库(尚未有任何 commit)中运行 gcop commitgcop stats 会报 UnbornBranch 错误并崩溃。

修复前:

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

修复后:

bash
$ git init
$ gcop commit
 No staged changes found. Use 'git add' first.

# 有暂存文件时,可以正常工作:
$ echo "test" > test.txt
$ git add test.txt
$ gcop commit
[1/4] Analyzed 1 file(s), 1 change(s)
[2/4] Generating commit message...
# ... 正常继续

修复内容:

  1. get_staged_diff():现在可以正确处理空仓库,通过对比空树(empty tree)而不是失败
  2. get_current_branch():对于 unborn branch 返回 None 而不是崩溃
  3. get_commit_history():对于没有 commit 的仓库返回空列表
  4. 新增 is_empty() 方法:通过捕获 UnbornBranch 错误来检测 unborn branch 状态

影响:

  • 首次使用的用户现在可以在新仓库中立即使用 gcop commit
  • gcop stats 在空仓库中显示友好警告而不是崩溃
  • 支持在新仓库中创建首次 commit

技术细节

本次修复在 GitOperations trait 中引入了新的 is_empty() 方法,用于检测 unborn branch 状态(即仓库尚未有任何 commit)。该方法被三个核心函数使用,以优雅地处理空仓库:

  • 空仓库现在将暂存的更改与空树(None)对比,而不是与 HEAD 对比
  • 分支检测对 unborn branch 返回 None
  • Commit 历史对空仓库返回空向量

所有现有测试均通过,并且已通过空仓库的手动测试验证。

升级说明

从 v0.5.0 升级无需任何操作。这是一个纯 bug 修复版本,没有破坏性更改。

安装

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

# pipx (Python 用户,推荐)
pipx upgrade gcop-rs

# cargo-binstall (无需编译)
cargo binstall gcop-rs

# cargo install (从源码编译)
cargo install gcop-rs --force

或从 Releases 下载预编译二进制。

反馈

如有问题或建议,欢迎提交 Issue