Skip to content

Commit 7038d1d

Browse files
committed
feat(stash): add comprehensive stash management API
Add complete stash operations implementation including save, apply, pop, list, show, drop, and clear functionality with advanced options support. Includes type-safe filtering, builder patterns, and comprehensive example.
1 parent 2896794 commit 7038d1d

File tree

8 files changed

+1499
-23
lines changed

8 files changed

+1499
-23
lines changed

CLAUDE.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
- Author struct: name, email, timestamp with Display implementation
5757
- CommitMessage: subject and optional body parsing
5858
- CommitDetails: full commit info including file changes and diff stats
59-
- **Core types**: Hash (in src/types.rs), IndexStatus, WorktreeStatus, FileEntry (in src/commands/status.rs), Branch, BranchList, BranchType (in src/commands/branch.rs), Commit, CommitLog, Author, CommitMessage, CommitDetails, LogOptions (in src/commands/log.rs), RepoConfig (in src/commands/config.rs), Remote, RemoteList, FetchOptions, PushOptions (in src/commands/remote.rs), RestoreOptions, RemoveOptions, MoveOptions (in src/commands/files.rs), DiffOutput, FileDiff, DiffStatus, DiffOptions, DiffStats, DiffChunk, DiffLine, DiffLineType (in src/commands/diff.rs), Tag, TagList, TagType, TagOptions (in src/commands/tag.rs)
59+
- **Core types**: Hash (in src/types.rs), IndexStatus, WorktreeStatus, FileEntry (in src/commands/status.rs), Branch, BranchList, BranchType (in src/commands/branch.rs), Commit, CommitLog, Author, CommitMessage, CommitDetails, LogOptions (in src/commands/log.rs), RepoConfig (in src/commands/config.rs), Remote, RemoteList, FetchOptions, PushOptions (in src/commands/remote.rs), RestoreOptions, RemoveOptions, MoveOptions (in src/commands/files.rs), DiffOutput, FileDiff, DiffStatus, DiffOptions, DiffStats, DiffChunk, DiffLine, DiffLineType (in src/commands/diff.rs), Tag, TagList, TagType, TagOptions (in src/commands/tag.rs), Stash, StashList, StashOptions, StashApplyOptions (in src/commands/stash.rs)
6060
- **Utility functions**: git(args, working_dir) -> Result<String>, git_raw(args, working_dir) -> Result<Output>
6161
- **Remote management**: Full remote operations with network support
6262
- Repository::add_remote(name, url) -> Result<()> - add remote repository
@@ -110,8 +110,21 @@
110110
- TagList: Box<[Tag]> with iterator methods (iter, lightweight, annotated), search (find, find_containing, for_commit), counting (len, lightweight_count, annotated_count)
111111
- TagOptions builder: annotated, force, message, sign with builder pattern (with_annotated, with_force, with_message, with_sign)
112112
- Author struct: name, email, timestamp for annotated tag metadata
113-
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs, config.rs, remote.rs, files.rs, diff.rs, tag.rs (in src/commands/)
114-
- **Testing**: 152+ tests covering all functionality with comprehensive edge cases
113+
- **Stash operations**: Complete stash management with type-safe API
114+
- Repository::stash_list() -> Result<StashList> - list all stashes with comprehensive filtering
115+
- Repository::stash_save(message) -> Result<Stash> - create simple stash
116+
- Repository::stash_push(message, options) -> Result<Stash> - create stash with options
117+
- Repository::stash_apply(index, options) -> Result<()> - apply stash without removing it
118+
- Repository::stash_pop(index, options) -> Result<()> - apply and remove stash
119+
- Repository::stash_show(index) -> Result<String> - show stash contents
120+
- Repository::stash_drop(index) -> Result<()> - remove specific stash
121+
- Repository::stash_clear() -> Result<()> - remove all stashes
122+
- Stash struct: index, message, hash, branch, timestamp
123+
- StashList: Box<[Stash]> with iterator methods (iter), search (find_containing, for_branch), access (latest, get), counting (len, is_empty)
124+
- StashOptions builder: untracked, keep_index, patch, staged_only, paths with builder pattern (with_untracked, with_keep_index, with_patch, with_staged_only, with_paths)
125+
- StashApplyOptions builder: restore_index, quiet with builder pattern (with_index, with_quiet)
126+
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs, config.rs, remote.rs, files.rs, diff.rs, tag.rs, stash.rs (in src/commands/)
127+
- **Testing**: 161+ tests covering all functionality with comprehensive edge cases
115128
- Run `cargo fmt && cargo build && cargo test && cargo clippy --all-targets --all-features -- -D warnings` after code changes
116129
- Make sure all examples are running
117130

@@ -130,6 +143,7 @@ The `examples/` directory contains comprehensive demonstrations of library funct
130143
- **file_lifecycle_operations.rs**: Comprehensive file management - restore/reset/remove/move operations, .gitignore management, advanced file lifecycle workflows, staging area manipulation
131144
- **diff_operations.rs**: Comprehensive diff operations showcase - unstaged/staged diffs, commit comparisons, advanced options (whitespace handling, path filtering), output formats (name-only, stat, numstat), and change analysis
132145
- **tag_operations.rs**: Complete tag management - create/delete/list tags, lightweight vs annotated tags, TagOptions builder, tag filtering and search, comprehensive tag workflows
146+
- **stash_operations.rs**: Complete stash management - save/apply/pop/list stashes, advanced options (untracked files, keep index, specific paths), stash filtering and search, comprehensive stash workflows
133147
- **error_handling.rs**: Comprehensive error handling patterns - GitError variants, recovery strategies
134148

135149
Run examples with: `cargo run --example <example_name>`

PLAN.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- **File lifecycle operations (restore, reset, remove, move, .gitignore management)**
1818
- **Diff operations with multi-level API and comprehensive options**
1919
- **Tag management with comprehensive operations and filtering**
20+
- **Stash operations with comprehensive management and filtering**
2021

2122
## ✅ Phase 1: Essential Remote Operations (COMPLETED)
2223

@@ -76,21 +77,28 @@
7677
- [x] Type-safe TagType enum (Lightweight, Annotated)
7778
- [x] Complete tag metadata support (message, tagger, timestamp)
7879

79-
## Phase 4: Release Management (Medium Priority)
80+
## Phase 5: Release Management (Medium Priority)
8081

8182
### Archive & Export
8283
- [ ] `repo.archive(format, output_path)` - Create repository archive
8384
- [ ] `repo.export_commit(hash, path)` - Export specific commit
8485

85-
## Phase 5: Development Workflow (Medium Priority)
86+
## Phase 4: Stash Operations (COMPLETED)
8687

87-
### Stash Management
88-
- [ ] `repo.stash_save(message)` - Save current changes
89-
- [ ] `repo.stash_push(files, message)` - Stash specific files
90-
- [ ] `repo.stash_list()` - List all stashes
91-
- [ ] `repo.stash_pop()` / `repo.stash_apply(index)` - Apply stashes
92-
- [ ] `repo.stash_drop(index)` / `repo.stash_clear()` - Remove stashes
93-
- [ ] `repo.stash_show(index)` - Show stash contents
88+
### ✅ Stash Management
89+
- [x] `repo.stash_save(message)` - Save current changes
90+
- [x] `repo.stash_push(message, options)` - Stash with advanced options
91+
- [x] `repo.stash_list()` - List all stashes with comprehensive filtering
92+
- [x] `repo.stash_apply(index, options)` - Apply stash without removing it
93+
- [x] `repo.stash_pop(index, options)` - Apply and remove stash
94+
- [x] `repo.stash_drop(index)` / `repo.stash_clear()` - Remove stashes
95+
- [x] `repo.stash_show(index)` - Show stash contents
96+
- [x] StashList with filtering (find_containing, for_branch, latest, get)
97+
- [x] StashOptions builder with untracked, keep_index, patch, staged_only, paths
98+
- [x] StashApplyOptions builder with restore_index, quiet options
99+
- [x] Complete stash metadata support (index, message, hash, branch, timestamp)
100+
101+
## Phase 6: Development Workflow (Medium Priority)
94102

95103
### Merge & Rebase
96104
- [ ] `repo.merge(branch)` / `repo.merge_commit(hash)` - Merge operations
@@ -99,7 +107,7 @@
99107
- [ ] Conflict resolution helpers and status
100108
- [ ] `repo.abort_merge()` / `repo.abort_rebase()` - Abort operations
101109

102-
## Phase 6: Advanced Configuration (Medium Priority)
110+
## Phase 7: Advanced Configuration (Medium Priority)
103111

104112
### Enhanced Configuration
105113
- [ ] `Config::global()` - Global git configuration
@@ -114,7 +122,7 @@
114122
- [ ] `repo.hooks().remove(hook_type)` - Remove hooks
115123
- [ ] Pre-built common hooks (pre-commit, pre-push, etc.)
116124

117-
## Phase 7: Repository Analysis (Low Priority)
125+
## Phase 8: Repository Analysis (Low Priority)
118126

119127
### History & Inspection
120128
- [ ] `repo.show(hash)` - Show commit with full diff
@@ -128,7 +136,7 @@
128136
- [ ] `repo.size_analysis()` - Large files, repository size analysis
129137
- [ ] `repo.gc()` / `repo.fsck()` - Maintenance operations
130138

131-
## Phase 8: Advanced Features (Low Priority)
139+
## Phase 9: Advanced Features (Low Priority)
132140

133141
### Worktree Support
134142
- [ ] `repo.worktree_add(path, branch)` - Add worktree

0 commit comments

Comments
 (0)