diff --git a/src/base.rs b/src/base.rs index 87a594c..0240042 100644 --- a/src/base.rs +++ b/src/base.rs @@ -79,6 +79,11 @@ pub fn commit(message: &str) -> String { if head.value != "" { commit += format!("parent {}\n", head.value).as_str(); } + let merge_head = data::get_ref("MERGE_HEAD".to_owned(), true); + if merge_head.value != "" { + commit += format!("parent {}\n", merge_head.value).as_str(); + data::delete_ref("MERGE_HEAD".to_owned(), false); + } commit += "\n"; commit += format!("{}\n", message).as_str(); @@ -110,6 +115,13 @@ pub fn get_commit(oid: String) -> Commit { if line_items[0] == "parent" { parents.push(line_items[1].to_owned()); message_start = 3; + + //Need to be refactored later + let other_parents: Vec<&str> = lines[2].splitn(2, " ").collect(); + if other_parents[0] == "parent" { + parents.push(other_parents[1].to_owned()); + message_start = 4; + } } else { parents.push("".to_owned()); } @@ -273,10 +285,20 @@ pub fn merge(oid: String) { assert!(head.value != ""); let c_head = get_commit(head.value); - let c_other = get_commit(oid); + let c_other = get_commit(oid.clone()); + + data::update_ref( + "MERGE_HEAD".to_owned(), + data::RefValue { + symbolic: false, + value: oid, + }, + true, + ); read_tree_merged(c_head.tree, c_other.tree); println!("Merged in working tree"); + println!("Please commit"); } fn is_ignored(path: &String) -> bool { diff --git a/src/main.rs b/src/main.rs index 141202e..e0d09b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -265,6 +265,11 @@ fn status() { println!("HEAD detached at {}", &head[1..10]) } + let merge_head = data::get_ref("MERGE_HEAD".to_owned(), true).value; + if merge_head != "".to_owned() { + println!("Merging with {}", &merge_head[1..10]); + } + println!("Changes to be committed:\n"); let head_commit = base::get_commit(head); for (path, action) in diff::changed_files( @@ -315,7 +320,7 @@ fn difference(matches: ArgMatches) { } fn merge(matches: ArgMatches) { - if let Some(cmd_matches) = matches.subcommand_matches("reset") { + if let Some(cmd_matches) = matches.subcommand_matches("merge") { let oid = base::get_oid(cmd_matches.value_of("commit").unwrap().to_owned()); base::merge(oid); }