Skip to content

Commit cd5b9ac

Browse files
authored
Fixed examples/pull.rs
`Repository::commit` needs to be called, otherwise the index gets goofed up. In my specific case, it resulted in a file created in a fetched commit being staged for deletion. https://libgit2.org/libgit2/ex/HEAD/merge.html was referenced for this fix. I also added a call to `Repository::cleanup_state` that was used in the libgit2 example. They did not call `Repository::checkout_head` so I've removed that.
1 parent abbd64e commit cd5b9ac

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

examples/pull.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ fn normal_merge(
139139
&result_tree,
140140
&[&local_commit, &remote_commit],
141141
)?;
142-
// Set working tree to match head.
143-
repo.checkout_head(None)?;
142+
// SEE https://libgit2.org/libgit2/ex/HEAD/merge.html
143+
repo.cleanup_state()?;
144144
Ok(())
145145
}
146146

@@ -181,6 +181,22 @@ fn do_merge<'a>(
181181
}
182182
};
183183
} else if analysis.0.is_normal() {
184+
// SEE https://libgit2.org/libgit2/ex/HEAD/merge.html
185+
186+
let mut checkout_options = git2::build::CheckoutBuilder::default();
187+
checkout_options.allow_conflicts(true);
188+
checkout_options.conflict_style_merge(true);
189+
checkout_options.force();
190+
191+
let mut merge_options = MergeOptions::new();
192+
merge_options.diff3_style(true);
193+
194+
repo.merge(
195+
&[&fetch_commit],
196+
Some(&mut merge_options),
197+
Some(&mut checkout_options),
198+
)?;
199+
184200
// do a normal merge
185201
let head_commit = repo.reference_to_annotated_commit(&repo.head()?)?;
186202
normal_merge(&repo, &head_commit, &fetch_commit)?;

0 commit comments

Comments
 (0)