step fifteen: record hash of last commit to HEAD
This commit is contained in:
parent
17072abf21
commit
909320d2fb
|
@ -67,7 +67,9 @@ pub fn commit(message: &str) -> String {
|
||||||
commit += "\n";
|
commit += "\n";
|
||||||
commit += format!("{}\n", message).as_str();
|
commit += format!("{}\n", message).as_str();
|
||||||
|
|
||||||
return data::hash_object(&commit.into_bytes(), "commit".to_owned());
|
let oid = data::hash_object(&commit.into_bytes(), "commit".to_owned());
|
||||||
|
data::set_head(oid.clone());
|
||||||
|
return oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ignored(path: &String) -> bool {
|
fn is_ignored(path: &String) -> bool {
|
||||||
|
@ -112,7 +114,7 @@ fn get_tree(oid: String, base_path: String) -> HashMap<String, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn empty_current_directory(dir: &str) -> io::Result<()> {
|
fn empty_current_directory(dir: &str) -> io::Result<()> {
|
||||||
// Delete current directory, less the ignored directories
|
// Delete current directory, except the ignored directories and files
|
||||||
for entry in fs::read_dir(dir)? {
|
for entry in fs::read_dir(dir)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
|
@ -41,3 +41,7 @@ pub fn get_object(hash: String, expected: String) -> String {
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_head(oid: String) {
|
||||||
|
fs::write(format!("{}/HEAD", RGIT_DIR), oid).expect("Failed to updated HEAD");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue