⬆️ chore(deps): migrate to git2 0.21 (#169)#207
Merged
Conversation
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.
There was a problem hiding this comment.
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
git2dependency0.20 → 0.21and update lockfile accordingly (including removal ofurl/idna/icu_*transitive deps). - Update call sites for
Reference::shorthand/Reference::name/Remote::url/Buf::as_str/Commit::summary/StringArray::iterto handleResult-based APIs. - Replace deprecated
Oid::zero()withOid::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 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 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
This was referenced Jun 1, 2026
⬆️ chore(deps)(deps): bump git2 from 0.20.4 to 0.21.0 in the git-stack group across 1 directory
#157
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Migrate
git20.20→0.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
Changes
git2 0.21 reworks its UTF-8 accessors from
OptiontoResult. Adapted every call site, collapsing the newErrarm toNonewith.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: yieldsResult<Option<&str>, _>→ the worktree-listing loops gain a second.flatten().Oid::zero(deprecated) →Oid::ZERO_SHA1constant.src/cli.rs,src/github.rs,src/sync.rs,src/tui/app.rs,src/tui/commit_graph.rs,src/worktree.rs.urldependency, pruning the wholeidna/icu_*transitive tree fromCargo.lock(−294 lines, lock only).Tests
cargo testpasses locally (all suites green, incl.tests/worktree_integration.rs)cargo fmt --checkpassescargo clippy -- -D warningspassestests/(TDD: a PR adding behaviour without tests is sent back)Screenshots / TUI captures
N/A — no rendering change.
Checklist
<type>/#<issue>-<description>## [Unreleased]examples/gwm.toml.exampleupdated if config schema changed (n/a)unwrap()on user-facing paths (returnGwmErrorinstead)println!in TUI render code (status bar only)MSRV
cargo clippy --all-targets -- -W clippy::incompatible_msrvclean 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
.ok()conversions are deliberately behaviour-preserving; the alternative (propagating the newErr) would change the "non-UTF-8 ref → treated as absent" contract that several call sites rely on.Cargo.lockdelta is entirely theurl/idna/icu_*tree that git2 0.21 no longer pulls — no first-party crate was downgraded.