Commit a472fa9d authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'setup-update-merge'

bc725479 prepare: support creating update merges
6b4ec649 prepare: remove inaccurate commit
acc77919 test: ensure that the new tree is correct
c58d80ee test: remove unnecessary variable
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Brad King's avatarBrad King <brad.king@kitware.com>
Merge-request: !50
parents 5bf935ae bc725479
......@@ -191,7 +191,6 @@ fn checkout<I, P>(ctx: &WorkareaGitContext, paths: I) -> Result<()>
where I: IntoIterator<Item = P>,
P: AsRef<OsStr>,
{
// Checkout .gitmodules so that submodules work.
let ls_files = ctx.cmd()
.arg("ls-files")
.arg("--")
......@@ -636,11 +635,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()
......@@ -655,6 +649,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()
......
......@@ -439,8 +439,18 @@ fn test_setup_merge() {
if let MergeStatus::Mergeable(bases) = status {
let merge = workarea.setup_merge(&bases, &base, &topic).unwrap();
if let MergeResult::Ready(_) = merge {
// OK
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(), "254e4e42cb914f935679319389e2af07eebb2157");
} else {
panic!("expected the merge from {} into {} to be fine: {:?}",
topic,
......@@ -455,6 +465,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");
......@@ -554,10 +597,8 @@ fn test_setup_merge_submodule_conflict_resolution() {
.collect::<Vec<_>>(),
&["submodule".to_string()]);
let resolution_commit = CommitId::new(SUBMODULE_RESOLUTION);
if let Conflict::SubmoduleWithFix(_, ref fix) = conflicts[0] {
assert_eq!(fix, &resolution_commit);
assert_eq!(fix, &CommitId::new(SUBMODULE_RESOLUTION));
} else {
panic!("expected the merge from {} into {} have a conflict resolution: {:?}",
topic,
......
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