Skip to content

Commit

Permalink
Fixed #22
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhexists committed Dec 18, 2023
1 parent aabf4e6 commit 22f2ddd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ fn handle_commit(dir_path: &Path) -> io::Result<Vec<TreeEntry>> {
}
} else {
let file_dir_path: PathBuf = entry.path();

let file_contents: Vec<u8> =
read_bytes(file_dir_path.clone()).unwrap();
let file_blob: Result<Blob, io::Error> =
Blob::new_blob(file_contents);
let file_blob: Result<Blob, io::Error> =
Blob::new_blob(file_contents);
match file_blob {
Ok(file_blob) => {
let string_to_be_hashed: &String =
Expand Down Expand Up @@ -130,7 +130,12 @@ fn handle_commit(dir_path: &Path) -> io::Result<Vec<TreeEntry>> {
}
}
}
Err(e) => panic!("Failed to read YAML: {e}"),
Err(_e) => {
io::Error::new(
io::ErrorKind::InvalidInput,
"Invalid Data found in .vault/init.yaml",
);
}
}
Ok(entries)
}
Expand Down Expand Up @@ -217,6 +222,6 @@ pub fn commit(dir_path: &Path, message: &str) -> io::Result<()> {
Err(e) => panic!("Failed to Commit: {e}"),
}
}
Err(e) => panic!("Some error occurred : {e}"),
Err(e) => panic!("{e}"),
}
}
18 changes: 13 additions & 5 deletions src/utils/get_current_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ use std::io::{self, BufReader};
use super::yaml_layouts::InitLayout;

pub fn get_current_branch() -> io::Result<String> {
let file: File = File::open(".vault/init.yaml").expect("Failed to open the details file");
let reader: BufReader<File> = BufReader::new(file);
let config: InitLayout = serde_yaml::from_reader(reader).expect("Failed to read YAML");
let current_branch: String = config.current_branch;
Ok(current_branch)
let file: Result<File, io::Error> = File::open(".vault/init.yaml");
match file {
Ok(file) => {
let reader: BufReader<File> = BufReader::new(file);
let config: InitLayout = serde_yaml::from_reader(reader).expect("Failed to read YAML");
let current_branch: String = config.current_branch;
Ok(current_branch)
}
Err(_e) => Err(io::Error::new(
io::ErrorKind::NotFound,
"Couldn't detect directory as a vault. Kindly Run `vault init` to make a vault",
)),
}
}

0 comments on commit 22f2ddd

Please sign in to comment.