step sixteen: set parent to HEAD
This commit is contained in:
parent
909320d2fb
commit
6dbfc533a6
|
@ -64,6 +64,11 @@ pub fn read_tree(oid: String) {
|
|||
|
||||
pub fn commit(message: &str) -> String {
|
||||
let mut commit = format!("tree {}\n", write_tree(".".to_owned()));
|
||||
|
||||
if let Ok(head) = data::get_head() {
|
||||
commit += format!("parent {}\n", head).as_str();
|
||||
}
|
||||
|
||||
commit += "\n";
|
||||
commit += format!("{}\n", message).as_str();
|
||||
|
||||
|
|
|
@ -45,3 +45,8 @@ pub fn get_object(hash: String, expected: String) -> String {
|
|||
pub fn set_head(oid: String) {
|
||||
fs::write(format!("{}/HEAD", RGIT_DIR), oid).expect("Failed to updated HEAD");
|
||||
}
|
||||
|
||||
pub fn get_head() -> Result<String, Box<dyn std::error::Error + 'static>> {
|
||||
let oid = fs::read_to_string(format!("{}/HEAD", RGIT_DIR))?;
|
||||
return Ok(oid);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue