Skip to content

Commit f8c414c

Browse files
authored
Merge pull request #8 from eugener/develop
Comprehensive diff operations API
2 parents 3b4ca8a + a8ecb4b commit f8c414c

File tree

15 files changed

+4220
-17
lines changed

15 files changed

+4220
-17
lines changed

CLAUDE.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,51 @@
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)
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)
6060
- **Utility functions**: git(args, working_dir) -> Result<String>, git_raw(args, working_dir) -> Result<Output>
61-
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs, config.rs (in src/commands/)
62-
- **Testing**: 106+ tests covering all functionality with comprehensive edge cases
61+
- **Remote management**: Full remote operations with network support
62+
- Repository::add_remote(name, url) -> Result<()> - add remote repository
63+
- Repository::remove_remote(name) -> Result<()> - remove remote
64+
- Repository::rename_remote(old_name, new_name) -> Result<()> - rename remote
65+
- Repository::list_remotes() -> Result<RemoteList> - list all remotes with URLs
66+
- Repository::get_remote_url(name) -> Result<String> - get remote URL
67+
- Repository::fetch(remote) -> Result<()> - fetch from remote repository
68+
- Repository::fetch_with_options(remote, options) -> Result<()> - fetch with FetchOptions
69+
- Repository::push(remote, branch) -> Result<()> - push to remote repository
70+
- Repository::push_with_options(remote, branch, options) -> Result<()> - push with PushOptions
71+
- Repository::clone(url, path) -> Result<Repository> - clone repository (static method)
72+
- Remote struct: name, fetch_url, push_url with proper URL handling
73+
- RemoteList: Vec<Remote> with search methods (find, iter, len, is_empty)
74+
- FetchOptions: prune, tags, all_remotes with builder pattern (with_prune, with_tags, with_all_remotes)
75+
- PushOptions: force, tags, set_upstream with builder pattern (with_force, with_tags, with_set_upstream)
76+
- **File lifecycle operations**: Comprehensive file management with advanced options
77+
- Repository::checkout_file(path) -> Result<()> - restore file from HEAD
78+
- Repository::restore(paths, options) -> Result<()> - advanced restore with RestoreOptions
79+
- Repository::reset_file(path) -> Result<()> - unstage specific file
80+
- Repository::rm(paths) -> Result<()> - remove files from repository
81+
- Repository::rm_with_options(paths, options) -> Result<()> - remove with RemoveOptions
82+
- Repository::mv(source, destination) -> Result<()> - move/rename files
83+
- Repository::mv_with_options(source, dest, options) -> Result<()> - move with MoveOptions
84+
- Repository::ignore_add(patterns) -> Result<()> - add patterns to .gitignore
85+
- Repository::ignore_check(path) -> Result<bool> - check if file is ignored
86+
- Repository::ignore_list() -> Result<Vec<String>> - list current ignore patterns
87+
- RestoreOptions: with_source(), with_staged(), with_worktree() - builder for restore configuration
88+
- RemoveOptions: with_force(), with_recursive(), with_cached(), with_ignore_unmatch() - builder for remove configuration
89+
- MoveOptions: with_force(), with_verbose(), with_dry_run() - builder for move configuration
90+
- **Diff operations**: Multi-level API for comprehensive change comparison
91+
- Repository::diff() -> Result<DiffOutput> - working directory vs index (unstaged changes)
92+
- Repository::diff_staged() -> Result<DiffOutput> - index vs HEAD (staged changes)
93+
- Repository::diff_head() -> Result<DiffOutput> - working directory vs HEAD (all changes)
94+
- Repository::diff_commits(from, to) -> Result<DiffOutput> - between specific commits
95+
- Repository::diff_with_options(options) -> Result<DiffOutput> - advanced diff with DiffOptions
96+
- DiffOutput: files, stats with immutable collections and comprehensive filtering
97+
- FileDiff: path, old_path, status, chunks, additions, deletions with change details
98+
- DiffStatus enum: Added, Modified, Deleted, Renamed, Copied with const char conversion
99+
- DiffOptions: context_lines, whitespace handling, path filtering, output formats (name-only, stat, numstat)
100+
- DiffStats: files_changed, insertions, deletions with aggregate statistics
101+
- Complete filtering: files_with_status(), iter(), is_empty(), len() for result analysis
102+
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs, config.rs, remote.rs, files.rs, diff.rs (in src/commands/)
103+
- **Testing**: 144+ tests covering all functionality with comprehensive edge cases
63104
- Run `cargo fmt && cargo build && cargo test && cargo clippy --all-targets --all-features -- -D warnings` after code changes
64105
- Make sure all examples are running
65106

@@ -73,6 +114,10 @@ The `examples/` directory contains comprehensive demonstrations of library funct
73114
- **commit_workflows.rs**: Commit operations and Hash type - commit(), commit_with_author(), Hash methods
74115
- **branch_operations.rs**: Complete branch management - create/delete/checkout branches, BranchList filtering, branch type handling, search operations
75116
- **commit_history.rs**: Comprehensive commit history & log operations - demonstrates all commit querying APIs, filtering, analysis, and advanced LogOptions usage
117+
- **config_operations.rs**: Repository configuration management - user setup, configuration values, repository-scoped settings
118+
- **remote_operations.rs**: Complete remote management - add/remove/rename remotes, fetch/push operations with options, network operations, error handling
119+
- **file_lifecycle_operations.rs**: Comprehensive file management - restore/reset/remove/move operations, .gitignore management, advanced file lifecycle workflows, staging area manipulation
120+
- **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
76121
- **error_handling.rs**: Comprehensive error handling patterns - GitError variants, recovery strategies
77122

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

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustic-git"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2024"
55
license = "MIT"
66
description = "A Rustic Git - clean type-safe API over git cli"

PLAN.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Rustic Git - Development Plan
2+
3+
## Current Status
4+
5+
**Completed Core Features**
6+
- Repository initialization and opening
7+
- Enhanced file status checking with staged/unstaged tracking
8+
- Staging operations (add, add_all, add_update)
9+
- Commit operations with custom authors
10+
- Branch operations (create, checkout, delete, list)
11+
- Configuration management (user settings, repository config)
12+
- Commit history and log operations with filtering
13+
- Error handling with comprehensive GitError types
14+
- Cross-platform compatibility (OS-agnostic temp directories)
15+
- **Remote management with full CRUD operations**
16+
- **Network operations (fetch, push, clone) with advanced options**
17+
- **File lifecycle operations (restore, reset, remove, move, .gitignore management)**
18+
19+
## ✅ Phase 1: Essential Remote Operations (COMPLETED)
20+
21+
### ✅ Remote Management
22+
- [x] `repo.add_remote(name, url)` - Add remote repository
23+
- [x] `repo.remove_remote(name)` - Remove remote
24+
- [x] `repo.list_remotes()` - List all remotes with URLs
25+
- [x] `repo.rename_remote(old_name, new_name)` - Rename remote
26+
- [x] `repo.get_remote_url(name)` - Get remote URL
27+
28+
### ✅ Network Operations
29+
- [x] `repo.fetch(remote)` / `repo.fetch_with_options()` - Fetch from remotes
30+
- [x] `repo.push(remote, branch)` / `repo.push_with_options()` - Push changes
31+
- [x] `repo.clone(url, path)` - Clone repository (static method)
32+
- [x] Advanced options with FetchOptions and PushOptions
33+
- [x] Type-safe builder patterns for network operations
34+
35+
## ✅ Phase 2: File Lifecycle Operations (COMPLETED)
36+
37+
### ✅ File Management
38+
- [x] `repo.checkout_file(path)` - Restore file from HEAD
39+
- [x] `repo.reset_file(path)` - Unstage specific file
40+
- [x] `repo.rm(paths)` - Remove files from repository
41+
- [x] `repo.rm_with_options(paths, options)` - Remove with advanced options
42+
- [x] `repo.mv(from, to)` - Move/rename files in repository
43+
- [x] `repo.mv_with_options(source, dest, options)` - Move with advanced options
44+
- [x] `repo.restore(paths, options)` - Restore files from specific commit with advanced options
45+
46+
### ✅ Ignore Management
47+
- [x] `repo.ignore_add(patterns)` - Add patterns to .gitignore
48+
- [x] `repo.ignore_check(file)` - Check if file is ignored
49+
- [x] `repo.ignore_list()` - List current ignore patterns
50+
51+
### ✅ Advanced File Operations
52+
- [x] RestoreOptions with source, staged, and worktree control
53+
- [x] RemoveOptions with force, recursive, cached, and ignore-unmatch
54+
- [x] MoveOptions with force, verbose, and dry-run modes
55+
- [x] Type-safe builder patterns for all file operations
56+
57+
### 🔄 Remote Branch Tracking (Future Enhancement)
58+
- [ ] `repo.branch_set_upstream(branch, remote_branch)` - Set tracking
59+
- [ ] `repo.branch_track(local, remote)` - Track remote branch
60+
- [ ] Remote branch listing and status
61+
- [ ] Pull operations (fetch + merge)
62+
63+
64+
## Phase 3: Release Management (Medium Priority)
65+
66+
### Tag Operations
67+
- [ ] `repo.create_tag(name, message)` - Create annotated tag
68+
- [ ] `repo.create_lightweight_tag(name)` - Create lightweight tag
69+
- [ ] `repo.list_tags()` - List tags with filtering options
70+
- [ ] `repo.delete_tag(name)` - Delete tag
71+
- [ ] `repo.tag_info(name)` - Get tag details
72+
- [ ] `repo.push_tags()` - Push tags to remote
73+
74+
### Archive & Export
75+
- [ ] `repo.archive(format, output_path)` - Create repository archive
76+
- [ ] `repo.export_commit(hash, path)` - Export specific commit
77+
78+
## Phase 4: Development Workflow (Medium Priority)
79+
80+
### Stash Management
81+
- [ ] `repo.stash_save(message)` - Save current changes
82+
- [ ] `repo.stash_push(files, message)` - Stash specific files
83+
- [ ] `repo.stash_list()` - List all stashes
84+
- [ ] `repo.stash_pop()` / `repo.stash_apply(index)` - Apply stashes
85+
- [ ] `repo.stash_drop(index)` / `repo.stash_clear()` - Remove stashes
86+
- [ ] `repo.stash_show(index)` - Show stash contents
87+
88+
### Merge & Rebase
89+
- [ ] `repo.merge(branch)` / `repo.merge_commit(hash)` - Merge operations
90+
- [ ] `repo.rebase(onto_branch)` - Rebase current branch
91+
- [ ] `repo.cherry_pick(hash)` - Cherry-pick commit
92+
- [ ] Conflict resolution helpers and status
93+
- [ ] `repo.abort_merge()` / `repo.abort_rebase()` - Abort operations
94+
95+
## Phase 5: Advanced Configuration (Medium Priority)
96+
97+
### Enhanced Configuration
98+
- [ ] `Config::global()` - Global git configuration
99+
- [ ] `Config::system()` - System-wide configuration
100+
- [ ] Config scopes (system, global, local)
101+
- [ ] `repo.config().list_all()` - List all config with scopes
102+
- [ ] `repo.config().edit()` - Interactive config editing
103+
104+
### Hook Management
105+
- [ ] `repo.hooks().install(hook_type, script)` - Install git hooks
106+
- [ ] `repo.hooks().list()` - List installed hooks
107+
- [ ] `repo.hooks().remove(hook_type)` - Remove hooks
108+
- [ ] Pre-built common hooks (pre-commit, pre-push, etc.)
109+
110+
## Phase 6: Repository Analysis (Low Priority)
111+
112+
### History & Inspection
113+
- [ ] `repo.show(hash)` - Show commit with full diff
114+
- [ ] `repo.blame(file, line_range)` - File annotation
115+
- [ ] `repo.diff(from, to)` - Diff between commits/branches
116+
- [ ] `repo.diff_files(from, to, paths)` - Diff specific files
117+
118+
### Repository Health
119+
- [ ] `repo.statistics()` - Commit count, contributors, file stats
120+
- [ ] `repo.health_check()` - Repository integrity check
121+
- [ ] `repo.size_analysis()` - Large files, repository size analysis
122+
- [ ] `repo.gc()` / `repo.fsck()` - Maintenance operations
123+
124+
## Phase 7: Advanced Features (Low Priority)
125+
126+
### Worktree Support
127+
- [ ] `repo.worktree_add(path, branch)` - Add worktree
128+
- [ ] `repo.worktree_list()` - List worktrees
129+
- [ ] `repo.worktree_remove(path)` - Remove worktree
130+
131+
### Batch Operations
132+
- [ ] `repo.batch()` - Transaction-like operations
133+
- [ ] Bulk file operations with progress callbacks
134+
- [ ] Atomic multi-step operations
135+
136+
### Integration Helpers
137+
- [ ] Workspace detection (Cargo.toml, package.json, etc.)
138+
- [ ] CI/CD integration helpers
139+
- [ ] Git flow / GitHub flow shortcuts
140+
- [ ] Semantic versioning helpers
141+
142+
## API Design Principles
143+
144+
### Consistency
145+
- Repository-centric design: operations as methods on `Repository`
146+
- Consistent error handling with `Result<T, GitError>`
147+
- Type-safe enums for status, branch types, etc.
148+
- Builder patterns for complex operations with options
149+
150+
### Performance
151+
- Lazy evaluation where possible
152+
- Streaming for large operations
153+
- Progress callbacks for long-running operations
154+
- Efficient caching of git command results
155+
156+
### Ergonomics
157+
- Sensible defaults for common use cases
158+
- Method chaining where appropriate
159+
- Clear, descriptive method names
160+
- Comprehensive documentation with examples
161+
162+
## Quality Standards
163+
164+
### Testing
165+
- Unit tests for all public APIs
166+
- Integration tests with real git repositories
167+
- Cross-platform testing (Windows, macOS, Linux)
168+
- Performance benchmarks for critical operations
169+
170+
### Documentation
171+
- Comprehensive rustdoc for all public APIs
172+
- Example code in documentation
173+
- Example programs in `examples/` directory
174+
- Clear error messages and recovery suggestions
175+
176+
### Compatibility
177+
- Support latest stable Rust (currently 1.89+)
178+
- Cross-platform file path handling
179+
- Graceful handling of different git versions
180+
- Consistent behavior across operating systems
181+
182+
## Implementation Notes
183+
184+
### Technical Decisions
185+
- Continue using `std::process::Command` for git operations
186+
- Maintain clean separation between core types and command modules
187+
- Use `PathBuf` for all path operations for cross-platform compatibility
188+
- Implement `From` traits for ergonomic type conversions
189+
190+
### Breaking Changes
191+
- Follow semantic versioning strictly
192+
- Deprecate before removing APIs
193+
- Provide migration guides for major version updates
194+
- Maintain backwards compatibility within major versions
195+
196+
## Success Metrics
197+
198+
### Adoption
199+
- Crates.io download counts
200+
- GitHub stars and forks
201+
- Community contributions and issues
202+
- Integration in other Rust projects
203+
204+
### Quality
205+
- Test coverage > 90%
206+
- Documentation coverage 100%
207+
- Zero clippy warnings
208+
- Fast CI/CD pipeline (< 5 minutes)
209+
210+
---
211+
212+
*This plan will be updated as features are implemented and priorities shift based on community feedback.*

0 commit comments

Comments
 (0)