Skip to content

refactor: simplify FetchBadge component and improve animation handling#51

Merged
ruru-m07 merged 9 commits into
devfrom
ruru-minor-fixes-tier-hello-kitty
Feb 27, 2026
Merged

refactor: simplify FetchBadge component and improve animation handling#51
ruru-m07 merged 9 commits into
devfrom
ruru-minor-fixes-tier-hello-kitty

Conversation

@ruru-m07

@ruru-m07 ruru-m07 commented Feb 25, 2026

Copy link
Copy Markdown
Owner
sequenceDiagram
    participant UI as React UI
    participant Hook as useStash Hook
    participant State as StashState
    participant Cmd as Tauri Command
    participant Svc as StashService
    participant Git as Git CLI
    participant Cache as Cache Layer

    Note over UI,Cache: Stash List Query
    UI->>Hook: useStashList()
    Hook->>State: stash.list()
    State->>Cache: Check cache
    alt Cache Hit
        Cache-->>State: Return cached data
    else Cache Miss
        State->>Cmd: stashList()
        Cmd->>Svc: service.stash().list()
        Svc->>Git: git stash list
        Git-->>Svc: Raw output
        Svc->>Svc: parse_stash_list()
        Svc-->>Cache: Store in cache
        Svc-->>Cmd: Vec[StashEntry]
        Cmd-->>State: Result
    end
    State-->>Hook: StashEntry[]
    Hook-->>UI: Display stash list

    Note over UI,Cache: Stash Pop Mutation
    UI->>Hook: useStashPop().mutate()
    Hook->>State: stash.pop(reference)
    State->>Cmd: stashPop(reference)
    Cmd->>Svc: service.stash().pop(reference)
    Svc->>Svc: Acquire repo lock
    Svc->>Git: git stash pop
    Git-->>Svc: Success or Error
    alt Success
        Svc->>Cache: invalidate_all()
        Svc-->>Cmd: Success message
    else Conflict
        Svc-->>Cmd: Error with conflict details
    end
    Cmd-->>State: Result
    State-->>Hook: Result
    Hook->>Hook: onSuccess: invalidate queries
    Hook-->>UI: Toast notification

    Note over UI,Cache: Branch Switch with Stash
    UI->>Svc: switchBranch with StashOnCurrentBranch
    Svc->>Svc: push_gitru_stash(from, to)
    Svc->>Git: git stash push with Gitru marker
    Git-->>Svc: Stash created
    Svc->>Git: git checkout branch
    alt Checkout Success
        Git-->>Svc: Success
        Svc->>Cache: invalidate_all()
    else Checkout Fail
        Git-->>Svc: Error
        Svc->>Svc: Rollback: pop stash
        Svc-->>UI: Error message
    end
Loading

- Added stash management commands in Tauri: list, quick stat, show, push, pop, apply, drop, clear, and branch.
- Created models for stash entries, quick stats, and detailed stash responses.
- Implemented parsing logic for stash output from Git commands.
- Introduced a new utility function for formatting numbers.
- Added a new icon for stashed items in the icon package.
- Updated the icon index to export the new Stashed icon.
- Updated `DiffState` to support fetching diffs from stashed references.
- Introduced `restoreFile` method in `StashState` for restoring individual files from stash.
- Enhanced `useAppStore` to manage Git view states, including stash references and filters.
- Modified `get_patch_by_file_path` in `DiffService` to handle stash references.
- Implemented `stashRestoreFile` command for restoring files from stash.
- Added validation for stash references in `stash.rs`.
- Updated UI components for improved alert dialog and resizable handle interactions.
@ruru-m07 ruru-m07 requested a review from Copilot February 26, 2026 17:19
@ruru-m07

Copy link
Copy Markdown
Owner Author

@codex[agent] could you pls review this PR?

@Codex

Codex AI commented Feb 26, 2026

Copy link
Copy Markdown

@ruru-m07 I've opened a new pull request, #52, to work on those changes. Once the pull request is ready, I'll request review from you.

This comment was marked as resolved.

@ruru-m07

Copy link
Copy Markdown
Owner Author

@codex[agent] review this PR

@Codex

Codex AI commented Feb 26, 2026

Copy link
Copy Markdown

@ruru-m07 I've opened a new pull request, #53, to work on those changes. Once the pull request is ready, I'll request review from you.

@ruru-m07

Copy link
Copy Markdown
Owner Author

@claude[agent] review this PR

@Claude

Claude AI commented Feb 26, 2026

Copy link
Copy Markdown

@ruru-m07 I've opened a new pull request, #54, to work on those changes. Once the pull request is ready, I'll request review from you.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@ruru-m07

Copy link
Copy Markdown
Owner Author

@codex review

@greptile-apps

greptile-apps Bot commented Feb 26, 2026

Copy link
Copy Markdown

Greptile Summary

This PR implements comprehensive git stash management functionality across the entire stack - from Rust backend services to React frontend UI. The changes include a complete StashService with all CRUD operations, stash parsers with extensive unit tests, Tauri command bindings, React hooks and state management, and an animated stash viewer UI with panel transitions.

Key additions:

  • Complete stash backend: list, show, push, pop, apply, drop, clear, branch, and restore-file operations
  • Gitru-managed branch stashing with !!Gitru<from> -> <to> message pattern for automatic stash/restore on branch switches
  • Git runner improvements: per-repository async locking and index.lock retry logic with exponential backoff
  • UI enhancements: Badge and AlertDialog component updates (including migration from @base-ui-components/react to @base-ui/react), VirtualizedFileList with section modes and contextual actions
  • Animated stash panel view with motion transitions
  • Stash diff viewing support in the diff service

Note: The PR title "refactor: simplify FetchBadge component and improve animation handling" doesn't accurately reflect the scope - this is a major feature addition (~3,200 lines added, ~700 removed) implementing full stash management, not just a simple refactor.

Confidence Score: 4/5

  • Safe to merge with minor concerns about scope and library migration
  • High-quality implementation with comprehensive error handling, unit tests, and proper cache management. The stash service is well-architected with good separation between parsing, service layer, and commands. The retry logic for git index.lock conflicts is a solid improvement. However, the PR's large scope (~3,200 lines added across 43 files), component library migration from @base-ui-components/react to @base-ui/react, and substantial UI changes warrant thorough testing before merge
  • Pay close attention to apps/desktop/src/routes/app/git/route.tsx (major UI changes with animations), crates/git/runner.rs (new async locking mechanism), and the component library migration in packages/ui/src/components/badge.tsx and alert-dialog.tsx

Important Files Changed

Filename Overview
apps/desktop/src/components/VirtualizedFileList.tsx Enhanced with sectionMode prop (accordion/flat), added contextual actions support, improved type safety with section types
apps/desktop/src/components/statusBar.tsx Major refactor with improved branch display, status indicators, and stash badge integration
apps/desktop/src/hooks/useStash.ts Created comprehensive stash hooks for queries (list, quickStat, show) and mutations (push, clear, pop, apply, drop, branch, restoreFile)
apps/desktop/src/routes/app/git/route.tsx Major feature addition with stash view panel, animated transitions, stash management UI, and filtering improvements
crates/git/parsers/stash.rs Comprehensive stash parser implementation with thorough unit tests for parsing git stash output, stats, file status, and Gitru stash messages
crates/git/runner.rs Added index.lock retry logic with exponential backoff and per-repository command locking using AsyncMutex
crates/git/service/diff.rs Enhanced to support diffing stash entries with single-file extraction logic
crates/git/service/stash.rs Comprehensive stash service with all CRUD operations, Gitru-managed branch stashing, and robust error handling for conflicts
packages/ui/src/components/alert-dialog.tsx Updated imports from @base-ui-components/react to @base-ui/react, restructured component layout with viewport, improved mobile UX
packages/ui/src/components/badge.tsx Updated imports from @base-ui-components/react to @base-ui/react, restructured variant definitions with improved sizing, added responsive size adjustments

Sequence Diagram

sequenceDiagram
    participant UI as React UI
    participant Hook as useStash Hook
    participant State as StashState
    participant Cmd as Tauri Command
    participant Svc as StashService (Rust)
    participant Git as Git CLI
    participant Cache as Cache Layer

    Note over UI,Cache: Stash List Query Flow
    UI->>Hook: useStashList()
    Hook->>State: stash.list()
    State->>Cache: Check cache
    alt Cache Hit
        Cache-->>State: Return cached data
    else Cache Miss
        State->>Cmd: stashList()
        Cmd->>Svc: service.stash().list()
        Svc->>Git: git stash list --format=%gd%x1f%gs
        Git-->>Svc: Raw output
        Svc->>Svc: parse_stash_list()
        Svc-->>Cache: Store in cache
        Svc-->>Cmd: Vec<StashEntry>
        Cmd-->>State: Result
    end
    State-->>Hook: StashEntry[]
    Hook-->>UI: Display stash list

    Note over UI,Cache: Stash Pop Mutation Flow
    UI->>Hook: useStashPop().mutate()
    Hook->>State: stash.pop(reference)
    State->>Cmd: stashPop({reference})
    Cmd->>Svc: service.stash().pop(reference)
    Svc->>Svc: Acquire repo lock
    Svc->>Git: git stash pop --quiet stash@{N}
    Git-->>Svc: Success/Conflict/Error
    alt Success
        Svc->>Cache: invalidate_all()
        Svc-->>Cmd: "Popped stash@{N}"
    else Conflict
        Svc-->>Cmd: Error with conflict details
    end
    Cmd-->>State: Result
    State-->>Hook: Result
    Hook->>Hook: onSuccess: invalidate queries
    Hook-->>UI: Toast notification
Loading

Last reviewed commit: 20b6e50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20b6e5060b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/git/service/branch.rs Outdated
.ctx
.runner
.run_with_options(&["stash", "pop"], GitRunOptions::default_read());
let _ = self.stash().pop(None).await;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid popping top stash when rollback has no new stash

This rollback path unconditionally calls pop(None), which resolves to stash@{0} and can remove/apply an unrelated stash if stash push created no entry (Git returns success with "No local changes to save") or if another stash is at the top. In a failed branch switch/create (for example, target branch creation/switch fails after the stash step), this can unexpectedly mutate the working tree and drop the user's existing stash instead of rolling back only the stash created for this operation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

could you fix this pls?

.find(|(start, end)| {
lines[*start..*end]
.iter()
.any(|line| path_markers.iter().any(|marker| line.contains(marker)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match stash diff section by exact file path

Using line.contains(marker) to select a stash diff section can pick the wrong file when one path is a prefix of another (for example src/a.ts vs src/a.tsx), because both headers contain a/src/a.ts. In that case the first matching section is returned, so the UI can display a patch for a different file than the one selected.

Useful? React with 👍 / 👎.

@ruru-m07 ruru-m07 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

hmmm

@ruru-m07 ruru-m07 marked this pull request as ready for review February 27, 2026 06:47
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@ruru-m07 ruru-m07 merged commit b06f308 into dev Feb 27, 2026
3 checks passed
@ruru-m07 ruru-m07 deleted the ruru-minor-fixes-tier-hello-kitty branch February 27, 2026 06:47
@greptile-apps

greptile-apps Bot commented Feb 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR implements a comprehensive git stash feature with full UI integration across the application. Despite the modest title suggesting only a badge component refactor, this is a major feature addition spanning 44 files with 3,400+ insertions and 880 deletions.

Key Changes:

  • Implemented complete stash service in Rust with list, push, pop, apply, drop, clear, branch, and restore operations
  • Added parsers for stash output with comprehensive test coverage
  • Integrated Gitru-managed stash system for automatic stashing during branch switches with proper rollback handling
  • Created React hooks and state management for stash queries and mutations with proper cache invalidation
  • Built stash UI panel with animations, filters, and file-level operations
  • Enhanced git runner with per-repository command locking and index.lock retry logic with exponential backoff
  • Improved FetchBadge animation from motion/react to CSS-based spinning for better performance
  • Added diff support for viewing changes in stash entries
  • Updated badge component package imports from @base-ui-components to @base-ui

Architecture:
The implementation follows a clean layered architecture from Rust backend (services, parsers, models) through Tauri commands to React frontend (hooks, state, UI). The caching strategy uses TTL-based invalidation with proper query management. The Gitru-managed stash feature (!!Gitru<from> -> <to> message pattern) seamlessly integrates with branch switching workflows.

Quality:
Code quality is high with comprehensive unit tests, proper error handling, defensive checks for edge cases (e.g., stash ref existence after git errors), and consistent patterns throughout the codebase.

Confidence Score: 5/5

  • This PR is safe to merge with very low risk
  • The implementation is well-structured with comprehensive tests, proper error handling, defensive programming practices, and follows established patterns. The stash operations are git-native commands with proper validation. Code includes rollback mechanisms for failed operations and handles edge cases like concurrent git operations with locking and retry logic.
  • No files require special attention - all implementations follow best practices with proper testing

Important Files Changed

Filename Overview
crates/git/service/stash.rs added comprehensive stash service with list, push, pop, apply, drop, clear, branch operations, and Gitru-managed stash for branch switching
crates/git/parsers/stash.rs added parsers for stash list, stat, file status, and Gitru stash messages with comprehensive test coverage
apps/desktop/src/hooks/useStash.ts added React hooks for stash queries and mutations with proper cache invalidation
apps/desktop/src/routes/app/git/route.tsx added stash panel view with animations, status filters, and integrated stash UI into git page
crates/git/service/branch.rs refactored to use StashService for Gitru-managed stash during branch switching, improved rollback handling
crates/git/runner.rs added per-repository command locking and index.lock retry logic with exponential backoff
apps/desktop/src/components/statusBar.tsx improved FetchBadge animation handling with CSS-based spinning and better state management
crates/git/service/diff.rs added support for viewing diffs from stash entries with proper caching and file extraction

Sequence Diagram

sequenceDiagram
    participant UI as React UI
    participant Hook as useStash Hook
    participant State as StashState
    participant Cmd as Tauri Command
    participant Svc as StashService
    participant Git as Git CLI
    participant Cache as Cache Layer

    Note over UI,Cache: Stash List Query
    UI->>Hook: useStashList()
    Hook->>State: stash.list()
    State->>Cache: Check cache
    alt Cache Hit
        Cache-->>State: Return cached data
    else Cache Miss
        State->>Cmd: stashList()
        Cmd->>Svc: service.stash().list()
        Svc->>Git: git stash list
        Git-->>Svc: Raw output
        Svc->>Svc: parse_stash_list()
        Svc-->>Cache: Store in cache
        Svc-->>Cmd: Vec[StashEntry]
        Cmd-->>State: Result
    end
    State-->>Hook: StashEntry[]
    Hook-->>UI: Display stash list

    Note over UI,Cache: Stash Pop Mutation
    UI->>Hook: useStashPop().mutate()
    Hook->>State: stash.pop(reference)
    State->>Cmd: stashPop(reference)
    Cmd->>Svc: service.stash().pop(reference)
    Svc->>Svc: Acquire repo lock
    Svc->>Git: git stash pop
    Git-->>Svc: Success or Error
    alt Success
        Svc->>Cache: invalidate_all()
        Svc-->>Cmd: Success message
    else Conflict
        Svc-->>Cmd: Error with conflict details
    end
    Cmd-->>State: Result
    State-->>Hook: Result
    Hook->>Hook: onSuccess: invalidate queries
    Hook-->>UI: Toast notification

    Note over UI,Cache: Branch Switch with Stash
    UI->>Svc: switchBranch with StashOnCurrentBranch
    Svc->>Svc: push_gitru_stash(from, to)
    Svc->>Git: git stash push with Gitru marker
    Git-->>Svc: Stash created
    Svc->>Git: git checkout branch
    alt Checkout Success
        Git-->>Svc: Success
        Svc->>Cache: invalidate_all()
    else Checkout Fail
        Git-->>Svc: Error
        Svc->>Svc: Rollback: pop stash
        Svc-->>UI: Error message
    end
Loading

Last reviewed commit: 823662d

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.

4 participants