step fifty one: record both parents on commit

This commit is contained in:
Gonçalo Valério 2020-11-28 22:25:06 +00:00
parent 8f60af7aa4
commit 1aac45ac62
2 changed files with 29 additions and 2 deletions

View File

@ -79,6 +79,11 @@ pub fn commit(message: &str) -> String {
if head.value != "" { if head.value != "" {
commit += format!("parent {}\n", head.value).as_str(); 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 += "\n";
commit += format!("{}\n", message).as_str(); commit += format!("{}\n", message).as_str();
@ -110,6 +115,13 @@ pub fn get_commit(oid: String) -> Commit {
if line_items[0] == "parent" { if line_items[0] == "parent" {
parents.push(line_items[1].to_owned()); parents.push(line_items[1].to_owned());
message_start = 3; 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 { } else {
parents.push("".to_owned()); parents.push("".to_owned());
} }
@ -273,10 +285,20 @@ pub fn merge(oid: String) {
assert!(head.value != ""); assert!(head.value != "");
let c_head = get_commit(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); read_tree_merged(c_head.tree, c_other.tree);
println!("Merged in working tree"); println!("Merged in working tree");
println!("Please commit");
} }
fn is_ignored(path: &String) -> bool { fn is_ignored(path: &String) -> bool {

View File

@ -265,6 +265,11 @@ fn status() {
println!("HEAD detached at {}", &head[1..10]) 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"); println!("Changes to be committed:\n");
let head_commit = base::get_commit(head); let head_commit = base::get_commit(head);
for (path, action) in diff::changed_files( for (path, action) in diff::changed_files(
@ -315,7 +320,7 @@ fn difference(matches: ArgMatches) {
} }
fn merge(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()); let oid = base::get_oid(cmd_matches.value_of("commit").unwrap().to_owned());
base::merge(oid); base::merge(oid);
} }