pub struct MergeOptions { /* private fields */ }
Expand description
Options for merge operations
Implementations§
Source§impl MergeOptions
impl MergeOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new MergeOptions with default settings
Examples found in repository?
examples/merge_operations.rs (line 128)
96fn demonstrate_no_fast_forward_merge(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
97 println!("\n--- Demonstrating No-Fast-Forward Merge ---\n");
98
99 // Add a commit to master to prevent fast-forward
100 println!("1. Adding commit to master...");
101 let readme_path = temp_dir.join("README.md");
102 fs::write(
103 &readme_path,
104 "# Project\n\nInitial content\n\n## Updates\nAdded documentation",
105 )?;
106 repo.add(&["README.md"])?;
107 let master_commit = repo.commit("Update documentation")?;
108 println!(" Master commit: {}", master_commit);
109
110 // Create another feature branch
111 println!("\n2. Creating another feature branch...");
112 repo.checkout_new("feature/no-ff", None)?;
113
114 let config_path = temp_dir.join("config.yaml");
115 fs::write(&config_path, "app:\n name: example\n version: 1.0")?;
116 repo.add(&["config.yaml"])?;
117 let config_commit = repo.commit("Add configuration file")?;
118 println!(" Config commit: {}", config_commit);
119
120 // Switch back to master
121 println!("\n3. Switching back to master...");
122 let branches = repo.branches()?;
123 let master_branch = branches.find("master").unwrap();
124 repo.checkout(master_branch)?;
125
126 // Perform no-fast-forward merge
127 println!("\n4. Performing no-fast-forward merge...");
128 let options = MergeOptions::new()
129 .with_fast_forward(FastForwardMode::Never)
130 .with_message("Merge feature/no-ff into master".to_string());
131
132 let merge_status = repo.merge_with_options("feature/no-ff", options)?;
133
134 match merge_status {
135 MergeStatus::Success(hash) => {
136 println!(" ✓ Merge commit created!");
137 println!(" Merge commit: {}", hash);
138 println!(" Created explicit merge commit preserving branch history");
139 }
140 _ => println!(" Unexpected merge result: {:?}", merge_status),
141 }
142
143 // Show the commit history
144 println!("\n5. Recent commit history:");
145 let commits = repo.recent_commits(3)?;
146 for (i, commit) in commits.iter().enumerate() {
147 println!(
148 " {}: {} - {}",
149 i + 1,
150 commit.hash.short(),
151 commit.message.subject
152 );
153 }
154
155 Ok(())
156}
157
158fn demonstrate_merge_conflicts(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
159 println!("\n--- Demonstrating Merge Conflicts ---\n");
160
161 // Create conflicting branch
162 println!("1. Creating branch with conflicting changes...");
163 repo.checkout_new("feature/conflict", None)?;
164
165 // Modify the same file differently
166 let readme_path = temp_dir.join("README.md");
167 fs::write(
168 &readme_path,
169 "# Project\n\nFeature branch changes\n\n## Updates\nAdded documentation",
170 )?;
171 repo.add(&["README.md"])?;
172 let feature_commit = repo.commit("Update README from feature branch")?;
173 println!(" Feature commit: {}", feature_commit);
174
175 // Switch back to master and make conflicting change
176 println!("\n2. Making conflicting change on master...");
177 let branches = repo.branches()?;
178 let master_branch = branches.find("master").unwrap();
179 repo.checkout(master_branch)?;
180
181 fs::write(
182 &readme_path,
183 "# Project\n\nMaster branch changes\n\n## Updates\nAdded documentation",
184 )?;
185 repo.add(&["README.md"])?;
186 let master_conflict_commit = repo.commit("Update README from master")?;
187 println!(" Master commit: {}", master_conflict_commit);
188
189 // Attempt merge (will have conflicts)
190 println!("\n3. Attempting merge (will have conflicts)...");
191 let merge_status = repo.merge("feature/conflict")?;
192
193 match merge_status {
194 MergeStatus::Conflicts(files) => {
195 println!(" ⚠️ Merge conflicts detected!");
196 println!(" Conflicted files:");
197 for file in &files {
198 println!(" - {}", file.display());
199 }
200
201 // Check merge in progress
202 if repo.merge_in_progress()? {
203 println!(" ✓ Merge in progress status detected");
204 }
205
206 // Show conflict markers in file
207 println!("\n4. Conflict markers in README.md:");
208 let content = fs::read_to_string(&readme_path)?;
209 for (i, line) in content.lines().enumerate() {
210 if line.starts_with("<<<<<<< ")
211 || line.starts_with("======= ")
212 || line.starts_with(">>>>>>> ")
213 {
214 println!(" {}: {} <-- conflict marker", i + 1, line);
215 } else {
216 println!(" {}: {}", i + 1, line);
217 }
218 }
219
220 // Abort the merge
221 println!("\n5. Aborting merge...");
222 repo.abort_merge()?;
223 println!(" ✓ Merge aborted successfully");
224
225 // Verify merge is no longer in progress
226 if !repo.merge_in_progress()? {
227 println!(" ✓ Repository is back to clean state");
228 }
229 }
230 _ => println!(" Unexpected merge result: {:?}", merge_status),
231 }
232
233 Ok(())
234}
235
236fn demonstrate_merge_status_and_abort(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
237 println!("\n--- Demonstrating Merge Status and Options ---\n");
238
239 // Create a simple feature branch
240 println!("1. Creating simple feature branch...");
241 repo.checkout_new("feature/simple", None)?;
242
243 let simple_path = temp_dir.join("simple.txt");
244 fs::write(&simple_path, "Simple feature content")?;
245 repo.add(&["simple.txt"])?;
246 repo.commit("Add simple feature")?;
247
248 // Switch back to master
249 let branches = repo.branches()?;
250 let master_branch = branches.find("master").unwrap();
251 repo.checkout(master_branch)?;
252
253 // Test merge with different options
254 println!("\n2. Testing merge with custom options...");
255 let options = MergeOptions::new()
256 .with_fast_forward(FastForwardMode::Auto)
257 .with_message("Integrate simple feature".to_string());
258
259 let merge_status = repo.merge_with_options("feature/simple", options)?;
260
261 match merge_status {
262 MergeStatus::FastForward(hash) => {
263 println!(" ✓ Fast-forward merge completed: {}", hash);
264 }
265 MergeStatus::Success(hash) => {
266 println!(" ✓ Merge commit created: {}", hash);
267 }
268 MergeStatus::UpToDate => {
269 println!(" ✓ Already up to date");
270 }
271 MergeStatus::Conflicts(_) => {
272 println!(" ⚠️ Unexpected conflicts");
273 }
274 }
275
276 // Show final repository state
277 println!("\n3. Final repository state:");
278 let status = repo.status()?;
279 println!(
280 " Working directory clean: {}",
281 status.staged_files().count() == 0 && status.unstaged_files().count() == 0
282 );
283
284 let commits = repo.recent_commits(5)?;
285 println!(" Recent commits:");
286 for (i, commit) in commits.iter().enumerate() {
287 println!(
288 " {}: {} - {}",
289 i + 1,
290 commit.hash.short(),
291 commit.message.subject
292 );
293 }
294
295 Ok(())
296}
Sourcepub fn with_fast_forward(self, mode: FastForwardMode) -> Self
pub fn with_fast_forward(self, mode: FastForwardMode) -> Self
Set the fast-forward mode
Examples found in repository?
examples/merge_operations.rs (line 129)
96fn demonstrate_no_fast_forward_merge(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
97 println!("\n--- Demonstrating No-Fast-Forward Merge ---\n");
98
99 // Add a commit to master to prevent fast-forward
100 println!("1. Adding commit to master...");
101 let readme_path = temp_dir.join("README.md");
102 fs::write(
103 &readme_path,
104 "# Project\n\nInitial content\n\n## Updates\nAdded documentation",
105 )?;
106 repo.add(&["README.md"])?;
107 let master_commit = repo.commit("Update documentation")?;
108 println!(" Master commit: {}", master_commit);
109
110 // Create another feature branch
111 println!("\n2. Creating another feature branch...");
112 repo.checkout_new("feature/no-ff", None)?;
113
114 let config_path = temp_dir.join("config.yaml");
115 fs::write(&config_path, "app:\n name: example\n version: 1.0")?;
116 repo.add(&["config.yaml"])?;
117 let config_commit = repo.commit("Add configuration file")?;
118 println!(" Config commit: {}", config_commit);
119
120 // Switch back to master
121 println!("\n3. Switching back to master...");
122 let branches = repo.branches()?;
123 let master_branch = branches.find("master").unwrap();
124 repo.checkout(master_branch)?;
125
126 // Perform no-fast-forward merge
127 println!("\n4. Performing no-fast-forward merge...");
128 let options = MergeOptions::new()
129 .with_fast_forward(FastForwardMode::Never)
130 .with_message("Merge feature/no-ff into master".to_string());
131
132 let merge_status = repo.merge_with_options("feature/no-ff", options)?;
133
134 match merge_status {
135 MergeStatus::Success(hash) => {
136 println!(" ✓ Merge commit created!");
137 println!(" Merge commit: {}", hash);
138 println!(" Created explicit merge commit preserving branch history");
139 }
140 _ => println!(" Unexpected merge result: {:?}", merge_status),
141 }
142
143 // Show the commit history
144 println!("\n5. Recent commit history:");
145 let commits = repo.recent_commits(3)?;
146 for (i, commit) in commits.iter().enumerate() {
147 println!(
148 " {}: {} - {}",
149 i + 1,
150 commit.hash.short(),
151 commit.message.subject
152 );
153 }
154
155 Ok(())
156}
157
158fn demonstrate_merge_conflicts(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
159 println!("\n--- Demonstrating Merge Conflicts ---\n");
160
161 // Create conflicting branch
162 println!("1. Creating branch with conflicting changes...");
163 repo.checkout_new("feature/conflict", None)?;
164
165 // Modify the same file differently
166 let readme_path = temp_dir.join("README.md");
167 fs::write(
168 &readme_path,
169 "# Project\n\nFeature branch changes\n\n## Updates\nAdded documentation",
170 )?;
171 repo.add(&["README.md"])?;
172 let feature_commit = repo.commit("Update README from feature branch")?;
173 println!(" Feature commit: {}", feature_commit);
174
175 // Switch back to master and make conflicting change
176 println!("\n2. Making conflicting change on master...");
177 let branches = repo.branches()?;
178 let master_branch = branches.find("master").unwrap();
179 repo.checkout(master_branch)?;
180
181 fs::write(
182 &readme_path,
183 "# Project\n\nMaster branch changes\n\n## Updates\nAdded documentation",
184 )?;
185 repo.add(&["README.md"])?;
186 let master_conflict_commit = repo.commit("Update README from master")?;
187 println!(" Master commit: {}", master_conflict_commit);
188
189 // Attempt merge (will have conflicts)
190 println!("\n3. Attempting merge (will have conflicts)...");
191 let merge_status = repo.merge("feature/conflict")?;
192
193 match merge_status {
194 MergeStatus::Conflicts(files) => {
195 println!(" ⚠️ Merge conflicts detected!");
196 println!(" Conflicted files:");
197 for file in &files {
198 println!(" - {}", file.display());
199 }
200
201 // Check merge in progress
202 if repo.merge_in_progress()? {
203 println!(" ✓ Merge in progress status detected");
204 }
205
206 // Show conflict markers in file
207 println!("\n4. Conflict markers in README.md:");
208 let content = fs::read_to_string(&readme_path)?;
209 for (i, line) in content.lines().enumerate() {
210 if line.starts_with("<<<<<<< ")
211 || line.starts_with("======= ")
212 || line.starts_with(">>>>>>> ")
213 {
214 println!(" {}: {} <-- conflict marker", i + 1, line);
215 } else {
216 println!(" {}: {}", i + 1, line);
217 }
218 }
219
220 // Abort the merge
221 println!("\n5. Aborting merge...");
222 repo.abort_merge()?;
223 println!(" ✓ Merge aborted successfully");
224
225 // Verify merge is no longer in progress
226 if !repo.merge_in_progress()? {
227 println!(" ✓ Repository is back to clean state");
228 }
229 }
230 _ => println!(" Unexpected merge result: {:?}", merge_status),
231 }
232
233 Ok(())
234}
235
236fn demonstrate_merge_status_and_abort(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
237 println!("\n--- Demonstrating Merge Status and Options ---\n");
238
239 // Create a simple feature branch
240 println!("1. Creating simple feature branch...");
241 repo.checkout_new("feature/simple", None)?;
242
243 let simple_path = temp_dir.join("simple.txt");
244 fs::write(&simple_path, "Simple feature content")?;
245 repo.add(&["simple.txt"])?;
246 repo.commit("Add simple feature")?;
247
248 // Switch back to master
249 let branches = repo.branches()?;
250 let master_branch = branches.find("master").unwrap();
251 repo.checkout(master_branch)?;
252
253 // Test merge with different options
254 println!("\n2. Testing merge with custom options...");
255 let options = MergeOptions::new()
256 .with_fast_forward(FastForwardMode::Auto)
257 .with_message("Integrate simple feature".to_string());
258
259 let merge_status = repo.merge_with_options("feature/simple", options)?;
260
261 match merge_status {
262 MergeStatus::FastForward(hash) => {
263 println!(" ✓ Fast-forward merge completed: {}", hash);
264 }
265 MergeStatus::Success(hash) => {
266 println!(" ✓ Merge commit created: {}", hash);
267 }
268 MergeStatus::UpToDate => {
269 println!(" ✓ Already up to date");
270 }
271 MergeStatus::Conflicts(_) => {
272 println!(" ⚠️ Unexpected conflicts");
273 }
274 }
275
276 // Show final repository state
277 println!("\n3. Final repository state:");
278 let status = repo.status()?;
279 println!(
280 " Working directory clean: {}",
281 status.staged_files().count() == 0 && status.unstaged_files().count() == 0
282 );
283
284 let commits = repo.recent_commits(5)?;
285 println!(" Recent commits:");
286 for (i, commit) in commits.iter().enumerate() {
287 println!(
288 " {}: {} - {}",
289 i + 1,
290 commit.hash.short(),
291 commit.message.subject
292 );
293 }
294
295 Ok(())
296}
Sourcepub fn with_strategy(self, strategy: MergeStrategy) -> Self
pub fn with_strategy(self, strategy: MergeStrategy) -> Self
Set the merge strategy
Sourcepub fn with_message(self, message: String) -> Self
pub fn with_message(self, message: String) -> Self
Set a custom commit message for the merge
Examples found in repository?
examples/merge_operations.rs (line 130)
96fn demonstrate_no_fast_forward_merge(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
97 println!("\n--- Demonstrating No-Fast-Forward Merge ---\n");
98
99 // Add a commit to master to prevent fast-forward
100 println!("1. Adding commit to master...");
101 let readme_path = temp_dir.join("README.md");
102 fs::write(
103 &readme_path,
104 "# Project\n\nInitial content\n\n## Updates\nAdded documentation",
105 )?;
106 repo.add(&["README.md"])?;
107 let master_commit = repo.commit("Update documentation")?;
108 println!(" Master commit: {}", master_commit);
109
110 // Create another feature branch
111 println!("\n2. Creating another feature branch...");
112 repo.checkout_new("feature/no-ff", None)?;
113
114 let config_path = temp_dir.join("config.yaml");
115 fs::write(&config_path, "app:\n name: example\n version: 1.0")?;
116 repo.add(&["config.yaml"])?;
117 let config_commit = repo.commit("Add configuration file")?;
118 println!(" Config commit: {}", config_commit);
119
120 // Switch back to master
121 println!("\n3. Switching back to master...");
122 let branches = repo.branches()?;
123 let master_branch = branches.find("master").unwrap();
124 repo.checkout(master_branch)?;
125
126 // Perform no-fast-forward merge
127 println!("\n4. Performing no-fast-forward merge...");
128 let options = MergeOptions::new()
129 .with_fast_forward(FastForwardMode::Never)
130 .with_message("Merge feature/no-ff into master".to_string());
131
132 let merge_status = repo.merge_with_options("feature/no-ff", options)?;
133
134 match merge_status {
135 MergeStatus::Success(hash) => {
136 println!(" ✓ Merge commit created!");
137 println!(" Merge commit: {}", hash);
138 println!(" Created explicit merge commit preserving branch history");
139 }
140 _ => println!(" Unexpected merge result: {:?}", merge_status),
141 }
142
143 // Show the commit history
144 println!("\n5. Recent commit history:");
145 let commits = repo.recent_commits(3)?;
146 for (i, commit) in commits.iter().enumerate() {
147 println!(
148 " {}: {} - {}",
149 i + 1,
150 commit.hash.short(),
151 commit.message.subject
152 );
153 }
154
155 Ok(())
156}
157
158fn demonstrate_merge_conflicts(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
159 println!("\n--- Demonstrating Merge Conflicts ---\n");
160
161 // Create conflicting branch
162 println!("1. Creating branch with conflicting changes...");
163 repo.checkout_new("feature/conflict", None)?;
164
165 // Modify the same file differently
166 let readme_path = temp_dir.join("README.md");
167 fs::write(
168 &readme_path,
169 "# Project\n\nFeature branch changes\n\n## Updates\nAdded documentation",
170 )?;
171 repo.add(&["README.md"])?;
172 let feature_commit = repo.commit("Update README from feature branch")?;
173 println!(" Feature commit: {}", feature_commit);
174
175 // Switch back to master and make conflicting change
176 println!("\n2. Making conflicting change on master...");
177 let branches = repo.branches()?;
178 let master_branch = branches.find("master").unwrap();
179 repo.checkout(master_branch)?;
180
181 fs::write(
182 &readme_path,
183 "# Project\n\nMaster branch changes\n\n## Updates\nAdded documentation",
184 )?;
185 repo.add(&["README.md"])?;
186 let master_conflict_commit = repo.commit("Update README from master")?;
187 println!(" Master commit: {}", master_conflict_commit);
188
189 // Attempt merge (will have conflicts)
190 println!("\n3. Attempting merge (will have conflicts)...");
191 let merge_status = repo.merge("feature/conflict")?;
192
193 match merge_status {
194 MergeStatus::Conflicts(files) => {
195 println!(" ⚠️ Merge conflicts detected!");
196 println!(" Conflicted files:");
197 for file in &files {
198 println!(" - {}", file.display());
199 }
200
201 // Check merge in progress
202 if repo.merge_in_progress()? {
203 println!(" ✓ Merge in progress status detected");
204 }
205
206 // Show conflict markers in file
207 println!("\n4. Conflict markers in README.md:");
208 let content = fs::read_to_string(&readme_path)?;
209 for (i, line) in content.lines().enumerate() {
210 if line.starts_with("<<<<<<< ")
211 || line.starts_with("======= ")
212 || line.starts_with(">>>>>>> ")
213 {
214 println!(" {}: {} <-- conflict marker", i + 1, line);
215 } else {
216 println!(" {}: {}", i + 1, line);
217 }
218 }
219
220 // Abort the merge
221 println!("\n5. Aborting merge...");
222 repo.abort_merge()?;
223 println!(" ✓ Merge aborted successfully");
224
225 // Verify merge is no longer in progress
226 if !repo.merge_in_progress()? {
227 println!(" ✓ Repository is back to clean state");
228 }
229 }
230 _ => println!(" Unexpected merge result: {:?}", merge_status),
231 }
232
233 Ok(())
234}
235
236fn demonstrate_merge_status_and_abort(repo: &Repository, temp_dir: &std::path::Path) -> Result<()> {
237 println!("\n--- Demonstrating Merge Status and Options ---\n");
238
239 // Create a simple feature branch
240 println!("1. Creating simple feature branch...");
241 repo.checkout_new("feature/simple", None)?;
242
243 let simple_path = temp_dir.join("simple.txt");
244 fs::write(&simple_path, "Simple feature content")?;
245 repo.add(&["simple.txt"])?;
246 repo.commit("Add simple feature")?;
247
248 // Switch back to master
249 let branches = repo.branches()?;
250 let master_branch = branches.find("master").unwrap();
251 repo.checkout(master_branch)?;
252
253 // Test merge with different options
254 println!("\n2. Testing merge with custom options...");
255 let options = MergeOptions::new()
256 .with_fast_forward(FastForwardMode::Auto)
257 .with_message("Integrate simple feature".to_string());
258
259 let merge_status = repo.merge_with_options("feature/simple", options)?;
260
261 match merge_status {
262 MergeStatus::FastForward(hash) => {
263 println!(" ✓ Fast-forward merge completed: {}", hash);
264 }
265 MergeStatus::Success(hash) => {
266 println!(" ✓ Merge commit created: {}", hash);
267 }
268 MergeStatus::UpToDate => {
269 println!(" ✓ Already up to date");
270 }
271 MergeStatus::Conflicts(_) => {
272 println!(" ⚠️ Unexpected conflicts");
273 }
274 }
275
276 // Show final repository state
277 println!("\n3. Final repository state:");
278 let status = repo.status()?;
279 println!(
280 " Working directory clean: {}",
281 status.staged_files().count() == 0 && status.unstaged_files().count() == 0
282 );
283
284 let commits = repo.recent_commits(5)?;
285 println!(" Recent commits:");
286 for (i, commit) in commits.iter().enumerate() {
287 println!(
288 " {}: {} - {}",
289 i + 1,
290 commit.hash.short(),
291 commit.message.subject
292 );
293 }
294
295 Ok(())
296}
Sourcepub fn with_no_commit(self) -> Self
pub fn with_no_commit(self) -> Self
Perform merge but don’t automatically commit
Trait Implementations§
Source§impl Clone for MergeOptions
impl Clone for MergeOptions
Source§fn clone(&self) -> MergeOptions
fn clone(&self) -> MergeOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for MergeOptions
impl Debug for MergeOptions
Auto Trait Implementations§
impl Freeze for MergeOptions
impl RefUnwindSafe for MergeOptions
impl Send for MergeOptions
impl Sync for MergeOptions
impl Unpin for MergeOptions
impl UnwindSafe for MergeOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more