Skip to content

Commit 31eeac4

Browse files
committed
feat(merge): implement comprehensive merge operations
Add complete merge functionality including fast-forward/no-fast-forward merges, conflict detection and handling, merge status tracking, and abort operations with comprehensive example and documentation updates
1 parent c0d5308 commit 31eeac4

File tree

7 files changed

+1081
-121
lines changed

7 files changed

+1081
-121
lines changed

CLAUDE.md

Lines changed: 14 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), Stash, StashList, StashOptions, StashApplyOptions (in src/commands/stash.rs), ResetMode (in src/commands/reset.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), ResetMode (in src/commands/reset.rs), MergeStatus, MergeOptions, FastForwardMode, MergeStrategy (in src/commands/merge.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
@@ -131,8 +131,18 @@
131131
- Repository::reset_file(path) -> Result<()> - unstage specific file (already exists in files.rs)
132132
- ResetMode enum: Soft, Mixed, Hard with const as_str() methods
133133
- Complete error handling for invalid commits and references
134-
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs, config.rs, remote.rs, files.rs, diff.rs, tag.rs, stash.rs, reset.rs (in src/commands/)
135-
- **Testing**: 178+ tests covering all functionality with comprehensive edge cases
134+
- **Merge operations**: Complete merge functionality with comprehensive conflict handling
135+
- Repository::merge(branch) -> Result<MergeStatus> - merge branch into current branch
136+
- Repository::merge_with_options(branch, options) -> Result<MergeStatus> - merge with advanced options
137+
- Repository::merge_in_progress() -> Result<bool> - check if merge is currently in progress
138+
- Repository::abort_merge() -> Result<()> - cancel ongoing merge operation
139+
- MergeStatus enum: Success(Hash), FastForward(Hash), UpToDate, Conflicts(Vec<PathBuf>) with comprehensive status tracking
140+
- MergeOptions builder: fast_forward, strategy, commit_message, no_commit with builder pattern (with_fast_forward, with_strategy, with_message, with_no_commit)
141+
- FastForwardMode enum: Auto, Only, Never with const as_str() methods
142+
- MergeStrategy enum: Recursive, Ours, Theirs with const as_str() methods
143+
- Complete conflict detection with file-level granularity
144+
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs, config.rs, remote.rs, files.rs, diff.rs, tag.rs, stash.rs, reset.rs, merge.rs (in src/commands/)
145+
- **Testing**: 187+ tests covering all functionality with comprehensive edge cases
136146
- Run `cargo fmt && cargo build && cargo test && cargo clippy --all-targets --all-features -- -D warnings` after code changes
137147
- Make sure all examples are running
138148

@@ -153,6 +163,7 @@ The `examples/` directory contains comprehensive demonstrations of library funct
153163
- **tag_operations.rs**: Complete tag management - create/delete/list tags, lightweight vs annotated tags, TagOptions builder, tag filtering and search, comprehensive tag workflows
154164
- **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
155165
- **reset_operations.rs**: Complete reset management - soft/mixed/hard resets, commit targeting, file-specific resets, error handling for invalid commits, comprehensive reset workflows
166+
- **merge_operations.rs**: Complete merge management - fast-forward/no-fast-forward merges, conflict detection and handling, merge status checking, abort operations, comprehensive merge workflows
156167
- **error_handling.rs**: Comprehensive error handling patterns - GitError variants, recovery strategies
157168

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

PLAN.md

Lines changed: 102 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Current Status
44

5-
**Completed Core Features**
5+
**Completed Core Features**
66
- Repository initialization and opening
77
- Enhanced file status checking with staged/unstaged tracking
88
- Staging operations (add, add_all, add_update)
@@ -20,108 +20,120 @@
2020
- **Stash operations with comprehensive management and filtering**
2121
- **Reset operations with comprehensive reset modes and error handling**
2222

23-
## Phase 1: Essential Remote Operations (COMPLETED)
24-
25-
### Remote Management
26-
- [x] `repo.add_remote(name, url)` - Add remote repository
27-
- [x] `repo.remove_remote(name)` - Remove remote
28-
- [x] `repo.list_remotes()` - List all remotes with URLs
29-
- [x] `repo.rename_remote(old_name, new_name)` - Rename remote
30-
- [x] `repo.get_remote_url(name)` - Get remote URL
31-
32-
### Network Operations
33-
- [x] `repo.fetch(remote)` / `repo.fetch_with_options()` - Fetch from remotes
34-
- [x] `repo.push(remote, branch)` / `repo.push_with_options()` - Push changes
35-
- [x] `repo.clone(url, path)` - Clone repository (static method)
36-
- [x] Advanced options with FetchOptions and PushOptions
37-
- [x] Type-safe builder patterns for network operations
38-
39-
## Phase 2: File Lifecycle Operations (COMPLETED)
40-
41-
### File Management
42-
- [x] `repo.checkout_file(path)` - Restore file from HEAD
43-
- [x] `repo.reset_file(path)` - Unstage specific file
44-
- [x] `repo.rm(paths)` - Remove files from repository
45-
- [x] `repo.rm_with_options(paths, options)` - Remove with advanced options
46-
- [x] `repo.mv(from, to)` - Move/rename files in repository
47-
- [x] `repo.mv_with_options(source, dest, options)` - Move with advanced options
48-
- [x] `repo.restore(paths, options)` - Restore files from specific commit with advanced options
49-
50-
### Ignore Management
51-
- [x] `repo.ignore_add(patterns)` - Add patterns to .gitignore
52-
- [x] `repo.ignore_check(file)` - Check if file is ignored
53-
- [x] `repo.ignore_list()` - List current ignore patterns
54-
55-
### Advanced File Operations
56-
- [x] RestoreOptions with source, staged, and worktree control
57-
- [x] RemoveOptions with force, recursive, cached, and ignore-unmatch
58-
- [x] MoveOptions with force, verbose, and dry-run modes
59-
- [x] Type-safe builder patterns for all file operations
60-
61-
### 🔄 Remote Branch Tracking (Future Enhancement)
23+
##Phase 1: Essential Remote Operations (COMPLETED)
24+
25+
###Remote Management
26+
- [x]`repo.add_remote(name, url)` - Add remote repository
27+
- [x]`repo.remove_remote(name)` - Remove remote
28+
- [x]`repo.list_remotes()` - List all remotes with URLs
29+
- [x]`repo.rename_remote(old_name, new_name)` - Rename remote
30+
- [x]`repo.get_remote_url(name)` - Get remote URL
31+
32+
###Network Operations
33+
- [x]`repo.fetch(remote)` / `repo.fetch_with_options()` - Fetch from remotes
34+
- [x]`repo.push(remote, branch)` / `repo.push_with_options()` - Push changes
35+
- [x]`repo.clone(url, path)` - Clone repository (static method)
36+
- [x]Advanced options with FetchOptions and PushOptions
37+
- [x]Type-safe builder patterns for network operations
38+
39+
##Phase 2: File Lifecycle Operations (COMPLETED)
40+
41+
###File Management
42+
- [x]`repo.checkout_file(path)` - Restore file from HEAD
43+
- [x]`repo.reset_file(path)` - Unstage specific file
44+
- [x]`repo.rm(paths)` - Remove files from repository
45+
- [x]`repo.rm_with_options(paths, options)` - Remove with advanced options
46+
- [x]`repo.mv(from, to)` - Move/rename files in repository
47+
- [x]`repo.mv_with_options(source, dest, options)` - Move with advanced options
48+
- [x]`repo.restore(paths, options)` - Restore files from specific commit with advanced options
49+
50+
###Ignore Management
51+
- [x]`repo.ignore_add(patterns)` - Add patterns to .gitignore
52+
- [x]`repo.ignore_check(file)` - Check if file is ignored
53+
- [x]`repo.ignore_list()` - List current ignore patterns
54+
55+
###Advanced File Operations
56+
- [x]RestoreOptions with source, staged, and worktree control
57+
- [x]RemoveOptions with force, recursive, cached, and ignore-unmatch
58+
- [x]MoveOptions with force, verbose, and dry-run modes
59+
- [x]Type-safe builder patterns for all file operations
60+
61+
### Remote Branch Tracking (Future Enhancement)
6262
- [ ] `repo.branch_set_upstream(branch, remote_branch)` - Set tracking
6363
- [ ] `repo.branch_track(local, remote)` - Track remote branch
6464
- [ ] Remote branch listing and status
6565
- [ ] Pull operations (fetch + merge)
6666

6767

68-
## ✅ Phase 3: Tag Operations (COMPLETED)
69-
70-
### ✅ Tag Management
71-
- [x] `repo.tags()` - List all tags with comprehensive filtering
72-
- [x] `repo.create_tag(name, target)` - Create lightweight tag
73-
- [x] `repo.create_tag_with_options(name, target, options)` - Create tag with options
74-
- [x] `repo.delete_tag(name)` - Delete tag
75-
- [x] `repo.show_tag(name)` - Get detailed tag information
76-
- [x] TagList with filtering (lightweight, annotated, find_containing, for_commit)
77-
- [x] TagOptions builder with force, message, sign, annotated options
78-
- [x] Type-safe TagType enum (Lightweight, Annotated)
79-
- [x] Complete tag metadata support (message, tagger, timestamp)
80-
81-
## ✅ Phase 4: Stash Operations (COMPLETED)
82-
83-
### ✅ Stash Management
84-
- [x] `repo.stash_save(message)` - Save current changes
85-
- [x] `repo.stash_push(message, options)` - Stash with advanced options
86-
- [x] `repo.stash_list()` - List all stashes with comprehensive filtering
87-
- [x] `repo.stash_apply(index, options)` - Apply stash without removing it
88-
- [x] `repo.stash_pop(index, options)` - Apply and remove stash
89-
- [x] `repo.stash_drop(index)` / `repo.stash_clear()` - Remove stashes
90-
- [x] `repo.stash_show(index)` - Show stash contents
91-
- [x] StashList with filtering (find_containing, for_branch, latest, get)
92-
- [x] StashOptions builder with untracked, keep_index, patch, staged_only, paths
93-
- [x] StashApplyOptions builder with restore_index, quiet options
94-
- [x] Complete stash metadata support (index, message, hash, branch, timestamp)
95-
96-
## ✅ Phase 5: Reset Operations (COMPLETED)
97-
98-
### ✅ Reset Management
99-
- [x] `repo.reset_soft(commit)` - Move HEAD, keep index and working tree
100-
- [x] `repo.reset_mixed(commit)` - Move HEAD, reset index, keep working tree (default)
101-
- [x] `repo.reset_hard(commit)` - Reset HEAD, index, and working tree to commit state
102-
- [x] `repo.reset_with_mode(commit, mode)` - Flexible reset with explicit ResetMode
103-
- [x] `repo.reset_file(path)` - Unstage specific file (already exists in files.rs)
104-
- [x] ResetMode enum with type-safe mode selection (Soft, Mixed, Hard)
105-
- [x] Complete error handling for invalid commits and references
106-
- [x] Comprehensive reset workflows with file-specific operations
107-
- [x] Cross-platform temporary directory handling for tests
108-
109-
## Phase 6: Release Management (Medium Priority)
68+
##Phase 3: Tag Operations (COMPLETED)
69+
70+
###Tag Management
71+
- [x]`repo.tags()` - List all tags with comprehensive filtering
72+
- [x]`repo.create_tag(name, target)` - Create lightweight tag
73+
- [x]`repo.create_tag_with_options(name, target, options)` - Create tag with options
74+
- [x]`repo.delete_tag(name)` - Delete tag
75+
- [x]`repo.show_tag(name)` - Get detailed tag information
76+
- [x]TagList with filtering (lightweight, annotated, find_containing, for_commit)
77+
- [x]TagOptions builder with force, message, sign, annotated options
78+
- [x]Type-safe TagType enum (Lightweight, Annotated)
79+
- [x]Complete tag metadata support (message, tagger, timestamp)
80+
81+
##Phase 4: Stash Operations (COMPLETED)
82+
83+
###Stash Management
84+
- [x]`repo.stash_save(message)` - Save current changes
85+
- [x]`repo.stash_push(message, options)` - Stash with advanced options
86+
- [x]`repo.stash_list()` - List all stashes with comprehensive filtering
87+
- [x]`repo.stash_apply(index, options)` - Apply stash without removing it
88+
- [x]`repo.stash_pop(index, options)` - Apply and remove stash
89+
- [x]`repo.stash_drop(index)` / `repo.stash_clear()` - Remove stashes
90+
- [x]`repo.stash_show(index)` - Show stash contents
91+
- [x]StashList with filtering (find_containing, for_branch, latest, get)
92+
- [x]StashOptions builder with untracked, keep_index, patch, staged_only, paths
93+
- [x]StashApplyOptions builder with restore_index, quiet options
94+
- [x]Complete stash metadata support (index, message, hash, branch, timestamp)
95+
96+
##Phase 5: Reset Operations (COMPLETED)
97+
98+
###Reset Management
99+
- [x]`repo.reset_soft(commit)` - Move HEAD, keep index and working tree
100+
- [x]`repo.reset_mixed(commit)` - Move HEAD, reset index, keep working tree (default)
101+
- [x]`repo.reset_hard(commit)` - Reset HEAD, index, and working tree to commit state
102+
- [x]`repo.reset_with_mode(commit, mode)` - Flexible reset with explicit ResetMode
103+
- [x]`repo.reset_file(path)` - Unstage specific file (already exists in files.rs)
104+
- [x]ResetMode enum with type-safe mode selection (Soft, Mixed, Hard)
105+
- [x]Complete error handling for invalid commits and references
106+
- [x]Comprehensive reset workflows with file-specific operations
107+
- [x]Cross-platform temporary directory handling for tests
108+
109+
##Phase 6: Merge Operations (COMPLETED)
110+
111+
###Merge Management
112+
- [x]`repo.merge(branch)` - Merge branch into current branch
113+
- [x]`repo.merge_with_options(branch, options)` - Merge with advanced options
114+
- [x]`repo.merge_in_progress()` - Check if merge is currently in progress
115+
- [x]`repo.abort_merge()` - Cancel ongoing merge operation
116+
- [x]MergeStatus enum with Success, FastForward, UpToDate, Conflicts variants
117+
- [x]MergeOptions builder with fast_forward, strategy, commit_message, no_commit options
118+
- [x]FastForwardMode enum: Auto, Only, Never with const as_str() methods
119+
- [x]MergeStrategy enum: Recursive, Ours, Theirs with const as_str() methods
120+
- [x]Complete conflict detection with file-level granularity
121+
- [x]Comprehensive merge workflows with error handling
122+
123+
## Phase 7: Release Management (Medium Priority)
110124

111125
### Archive & Export
112126
- [ ] `repo.archive(format, output_path)` - Create repository archive
113127
- [ ] `repo.export_commit(hash, path)` - Export specific commit
114128

115-
## Phase 7: Development Workflow (Medium Priority)
129+
## Phase 8: Development Workflow (Medium Priority)
116130

117-
### Merge & Rebase
118-
- [ ] `repo.merge(branch)` / `repo.merge_commit(hash)` - Merge operations
131+
### Rebase & Cherry-pick
119132
- [ ] `repo.rebase(onto_branch)` - Rebase current branch
120133
- [ ] `repo.cherry_pick(hash)` - Cherry-pick commit
121-
- [ ] Conflict resolution helpers and status
122-
- [ ] `repo.abort_merge()` / `repo.abort_rebase()` - Abort operations
134+
- [ ] `repo.abort_rebase()` - Abort rebase operations
123135

124-
## Phase 8: Advanced Configuration (Medium Priority)
136+
## Phase 9: Advanced Configuration (Medium Priority)
125137

126138
### Enhanced Configuration
127139
- [ ] `Config::global()` - Global git configuration
@@ -136,7 +148,7 @@
136148
- [ ] `repo.hooks().remove(hook_type)` - Remove hooks
137149
- [ ] Pre-built common hooks (pre-commit, pre-push, etc.)
138150

139-
## Phase 9: Repository Analysis (Low Priority)
151+
## Phase 10: Repository Analysis (Low Priority)
140152

141153
### History & Inspection
142154
- [ ] `repo.show(hash)` - Show commit with full diff
@@ -150,7 +162,7 @@
150162
- [ ] `repo.size_analysis()` - Large files, repository size analysis
151163
- [ ] `repo.gc()` / `repo.fsck()` - Maintenance operations
152164

153-
## Phase 10: Advanced Features (Low Priority)
165+
## Phase 11: Advanced Features (Low Priority)
154166

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

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@ Rustic Git provides a simple, ergonomic interface for common Git operations. It
1616

1717
## Features
1818

19-
- ✅ Repository initialization and opening
20-
-**Enhanced file status checking** with separate staged/unstaged tracking
21-
-**Precise Git state representation** using IndexStatus and WorktreeStatus enums
22-
- ✅ File staging (add files, add all, add updates)
23-
- ✅ Commit creation with hash return
24-
-**Complete branch operations** with type-safe Branch API
25-
-**Branch management** (create, delete, checkout, list)
26-
-**Commit history & log operations** with multi-level API
27-
-**Advanced commit querying** with filtering and analysis
28-
-**Repository configuration management** with type-safe API
29-
-**Remote management** with full CRUD operations and network support
30-
-**Network operations** (fetch, push, clone) with advanced options
31-
-**File lifecycle operations** (restore, reset, remove, move, .gitignore management)
32-
-**Diff operations** with multi-level API and comprehensive options
33-
-**Tag management** with comprehensive operations and filtering
34-
-**Lightweight and annotated tags** with type-safe API
35-
-**Stash operations** with comprehensive stash management and filtering
36-
-**Advanced stash options** (untracked files, keep index, specific paths)
37-
-**Reset operations** with comprehensive soft/mixed/hard reset support
38-
-**Repository history management** with type-safe ResetMode API
39-
- ✅ Type-safe error handling with custom GitError enum
40-
- ✅ Universal `Hash` type for Git objects
41-
-**Immutable collections** (Box<[T]>) for memory efficiency
42-
-**Const enum conversions** with zero runtime cost
43-
- ✅ Comprehensive test coverage (161+ tests)
19+
-Repository initialization and opening
20+
-**Enhanced file status checking** with separate staged/unstaged tracking
21+
-**Precise Git state representation** using IndexStatus and WorktreeStatus enums
22+
-File staging (add files, add all, add updates)
23+
-Commit creation with hash return
24+
-**Complete branch operations** with type-safe Branch API
25+
-**Branch management** (create, delete, checkout, list)
26+
-**Commit history & log operations** with multi-level API
27+
-**Advanced commit querying** with filtering and analysis
28+
-**Repository configuration management** with type-safe API
29+
-**Remote management** with full CRUD operations and network support
30+
-**Network operations** (fetch, push, clone) with advanced options
31+
-**File lifecycle operations** (restore, reset, remove, move, .gitignore management)
32+
-**Diff operations** with multi-level API and comprehensive options
33+
-**Tag management** with comprehensive operations and filtering
34+
-**Lightweight and annotated tags** with type-safe API
35+
-**Stash operations** with comprehensive stash management and filtering
36+
-**Advanced stash options** (untracked files, keep index, specific paths)
37+
-**Reset operations** with comprehensive soft/mixed/hard reset support
38+
-**Repository history management** with type-safe ResetMode API
39+
-**Merge operations** with comprehensive branch merging and conflict handling
40+
-**Advanced merge options** (fast-forward control, merge strategies, conflict detection)
41+
-Type-safe error handling with custom GitError enum
42+
-Universal `Hash` type for Git objects
43+
-**Immutable collections** (Box<[T]>) for memory efficiency
44+
-**Const enum conversions** with zero runtime cost
45+
-Comprehensive test coverage (187+ tests)
4446

4547
## Installation
4648

0 commit comments

Comments
 (0)