Commit bc725479 authored by Ben Boeckel's avatar Ben Boeckel

prepare: support creating update merges

Basically, the same as a regular merge except that the `ours` strategy
is used.
parent 6b4ec649
......@@ -632,11 +632,6 @@ impl GitWorkArea {
/// object. That commit object should then be stored in a reference using `git update-ref`.
pub fn setup_merge<'a>(&'a self, bases: &[CommitId], base: &CommitId, topic: &CommitId)
-> Result<MergeResult<'a>> {
debug!(target: "git.workarea",
"merging {} into {}",
topic,
base);
let merge_recursive = self.git()
.arg("merge-recursive")
.args(&bases.iter()
......@@ -651,6 +646,29 @@ impl GitWorkArea {
return Ok(MergeResult::Conflict(self.conflict_information()?));
}
self.setup_merge_impl(base, topic)
}
/// Prepare a command to create a merge commit.
///
/// The merge is performed, but only as a tree object. In order to create the actual commit
/// object, a successful merge returns a command which should be executed to create the commit
/// object. That commit object should then be stored in a reference using `git update-ref`.
pub fn setup_update_merge<'a>(&'a self, base: &CommitId, topic: &CommitId)
-> Result<MergeResult<'a>> {
self.setup_merge_impl(base, topic)
}
/// Prepare a command to create a merge commit.
///
/// This supports choosing the merge strategy.
fn setup_merge_impl<'a>(&'a self, base: &CommitId, topic: &CommitId)
-> Result<MergeResult<'a>> {
debug!(target: "git.workarea",
"merging {} into {}",
topic,
base);
let write_tree = self.git()
.arg("write-tree")
.output()
......
......@@ -464,6 +464,39 @@ fn test_setup_merge() {
}
}
#[test]
fn test_setup_merge_ours() {
let tempdir = test_workspace_dir("test_setup_merge_ours");
let base = CommitId::new(BASE_COMMIT);
let ctx = git_context_submodule(tempdir.path(), &base);
let workarea = ctx.prepare(&base).unwrap();
assert!(!workarea.submodule_config().is_empty());
let topic = CommitId::new(SUBMODULE_UPDATE_COMMIT);
let merge = workarea.setup_update_merge(&base, &topic).unwrap();
if let MergeResult::Ready(command) = merge {
let commit = command.commit("commit message").unwrap();
let rev_parse = ctx.git()
.arg("rev-parse")
.arg("--verify")
.arg(format!("{}^{{tree}}", commit))
.output()
.unwrap();
assert!(rev_parse.status.success());
let merged_tree = String::from_utf8_lossy(&rev_parse.stdout);
assert_eq!(merged_tree.trim(), "d6e9a7ef309d55ab0bc68e978e34bea528d7bb94");
} else {
panic!("expected the merge from {} into {} to be fine: {:?}",
topic,
base,
merge);
}
}
#[test]
fn test_setup_merge_rewind() {
let tempdir = test_workspace_dir("test_setup_merge_rewind");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment