Skip to content

⬆️ chore(deps): migrate to git2 0.21 (#169)#207

Merged
kbrdn1 merged 2 commits into
devfrom
chore/#169-migrate-git2-0-21
Jun 1, 2026
Merged

⬆️ chore(deps): migrate to git2 0.21 (#169)#207
kbrdn1 merged 2 commits into
devfrom
chore/#169-migrate-git2-0-21

Conversation

@kbrdn1
Copy link
Copy Markdown
Owner

@kbrdn1 kbrdn1 commented Jun 1, 2026

Description

Migrate git2 0.200.21. This is the deferred follow-up to Dependabot #157: the bump is a breaking source migration, not a mechanical version change, so it was kept out of the v0.8.0-rc.3 cut (house rule: follow-up issues beat scope creep) and tracked as #169.

Closes #169

Type of change

  • ✨ Feature (new functionality)
  • 🐛 Fix (bug fix)
  • 🚑️ Hotfix (critical production fix)
  • ♻️ Refactor (no behaviour change)
  • 📝 Docs
  • ✅ Tests
  • ⚡ Perf
  • 🔧 Chore / CI / build

Changes

git2 0.21 reworks its UTF-8 accessors from Option to Result. Adapted every call site, collapsing the new Err arm to None with .ok() so observable behaviour is unchanged (a non-UTF-8 / absent name still reads as "missing"):

  • Reference::shorthand / Reference::name / Remote::url / Buf::as_str: Option<&str>Result<&str, git2::Error>.
  • Commit::summary: Option<&str>Result<Option<&str>, _> (now .ok().flatten()).
  • StringArray::iter: yields Result<Option<&str>, _> → the worktree-listing loops gain a second .flatten().
  • Oid::zero (deprecated) → Oid::ZERO_SHA1 constant.
  • Touched: src/cli.rs, src/github.rs, src/sync.rs, src/tui/app.rs, src/tui/commit_graph.rs, src/worktree.rs.
  • Side effect: git2 0.21 drops its url dependency, pruning the whole idna / icu_* transitive tree from Cargo.lock (−294 lines, lock only).

Tests

  • cargo test passes locally (all suites green, incl. tests/worktree_integration.rs)
  • cargo fmt --check passes
  • cargo clippy -- -D warnings passes
  • New tests added under tests/ (TDD: a PR adding behaviour without tests is sent back)

TDD note. Per CLAUDE.md, a behaviour-preserving dependency migration is the one carve-out where CI green is the test. The accessor changes are covered by the existing tests/worktree_integration.rs suite. No new test was added because the migration is observably a no-op: the new Err arm (non-UTF-8 ref / remote URL) collapses to the same None the 0.20 API already returned, so no new code path is reachable from the public surface. Confirmed the full suite passes against a stripped CI-like PATH.

Screenshots / TUI captures

N/A — no rendering change.

Checklist

  • Branch follows <type>/#<issue>-<description>
  • Commits follow Gitmoji + Conventional Commits (see CONTRIBUTING.md)
  • CHANGELOG.md updated under ## [Unreleased]
  • README updated if CLI surface changed (n/a — no surface change)
  • examples/gwm.toml.example updated if config schema changed (n/a)
  • No unwrap() on user-facing paths (return GwmError instead)
  • No println! in TUI render code (status bar only)

MSRV

  • cargo clippy --all-targets -- -W clippy::incompatible_msrv clean against MSRV 1.82 — git2 0.21 introduces no newer-than-1.82 API on the paths we touch.

Linked issues / docs

Notes for reviewers

  • The .ok() conversions are deliberately behaviour-preserving; the alternative (propagating the new Err) would change the "non-UTF-8 ref → treated as absent" contract that several call sites rely on.
  • The large Cargo.lock delta is entirely the url/idna/icu_* tree that git2 0.21 no longer pulls — no first-party crate was downgraded.

git2 0.21 reworks its UTF-8 accessors from `Option` to `Result`, a
breaking source migration deferred out of v0.8.0-rc.3 (Dependabot #157):

- `Reference::shorthand` / `Reference::name` / `Remote::url` /
  `Buf::as_str` now return `Result<&str, git2::Error>` (was
  `Option<&str>`).
- `Commit::summary` now returns `Result<Option<&str>, _>`.
- `StringArray::iter` now yields `Result<Option<&str>, _>` — the
  worktree-listing loops gain a second `.flatten()`.
- `Oid::zero` is deprecated → use the `Oid::ZERO_SHA1` constant.

Every call site collapses the new `Err` arm to `None` via `.ok()`, so
the observable behaviour (a non-UTF-8 / absent name reads as missing) is
unchanged — the existing tests/worktree_integration.rs suite is the
regression gate (TDD: behaviour-preserving dep migration, CI green is
the test per CLAUDE.md).

Touches src/cli.rs, src/github.rs, src/sync.rs, src/tui/app.rs,
src/tui/commit_graph.rs, src/worktree.rs. Side effect: git2 0.21 drops
its `url` dependency, pruning the idna / icu_* transitive tree from
Cargo.lock.

cargo build / test / fmt --check / clippy -D warnings all green;
clippy -W clippy::incompatible_msrv clean against MSRV 1.82.

Closes #169. Closes #157.
Copilot AI review requested due to automatic review settings June 1, 2026 20:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the codebase to git2 v0.21, adapting to the breaking accessor API changes (notably UTF-8 accessors shifting from Option to Result) while keeping observable behavior the same by collapsing new Err paths to None.

Changes:

  • Bump git2 dependency 0.20 → 0.21 and update lockfile accordingly (including removal of url/idna/icu_* transitive deps).
  • Update call sites for Reference::shorthand / Reference::name / Remote::url / Buf::as_str / Commit::summary / StringArray::iter to handle Result-based APIs.
  • Replace deprecated Oid::zero() with Oid::ZERO_SHA1.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/worktree.rs Updates branch/ref/worktree name accessors and commit summary handling for git2 0.21.
src/tui/commit_graph.rs Replaces deprecated Oid::zero() with Oid::ZERO_SHA1.
src/tui/app.rs Updates remote URL and branch shorthand accessors to Result-based APIs.
src/sync.rs Updates HEAD/ref/upstream name and remote resolution logic for new accessor signatures.
src/github.rs Updates origin remote URL retrieval to the new Result-based accessor.
src/cli.rs Updates branch shorthand and origin URL retrieval for git2 0.21 accessors.
CHANGELOG.md Documents the git2 migration and its behavioral intent/side-effects.
Cargo.toml Bumps git2 to 0.21.
Cargo.lock Reflects updated dependency graph after the git2 bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/worktree.rs
Comment on lines 205 to 207
let names = repo.worktrees()?;
for name in names.iter().flatten() {
for name in names.iter().flatten().flatten() {
let wt = match repo.find_worktree(name) {
Comment thread src/worktree.rs
Comment on lines 397 to 400
let names = repo.worktrees()?;
let mut out = Vec::new();
for name in names.iter().flatten() {
for name in names.iter().flatten().flatten() {
let wt = match repo.find_worktree(name) {
Addresses Copilot review on PR #207: the `names.iter().flatten().flatten()`
double-flatten relied on `Result`/`Option` implementing `IntoIterator`
and was non-obvious. Replace both worktree-listing loops with
`filter_map(|r| r.ok().flatten())` plus a one-line comment so "skip the
`Err` (non-UTF-8) and `None` arms" reads at a glance. Behaviour is
identical — same entries kept, same entries dropped.

PR #207
@kbrdn1 kbrdn1 merged commit c44c7a4 into dev Jun 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants