refactor: add get_home_e()
This commit is contained in:
@@ -104,20 +104,26 @@ fn search_git_root_path_e() -> PathBuf {
|
||||
search_git_root_path().unwrap_or_else(|| exit_with_error_message("Git root path not found!"))
|
||||
}
|
||||
|
||||
fn get_home_e() -> PathBuf {
|
||||
PathBuf::from(env::var("HOME").unwrap_or_else(|e| {
|
||||
exit_with_error_message(&format!("Get env HOME failed: {}!", e));
|
||||
}))
|
||||
}
|
||||
|
||||
fn get_commit_msg_file(file: &str, default_content: &str) -> String {
|
||||
let mut settings_regexp = search_git_root_path_e().join("settings").join(file);
|
||||
let settings_regexp = search_git_root_path_e().join("settings").join(file);
|
||||
if settings_regexp.exists() {
|
||||
print_info(&format!("Found file: {:?}", settings_regexp));
|
||||
return fs::read_to_string(settings_regexp).unwrap();
|
||||
}
|
||||
|
||||
let mut path_regexp = search_git_root_path_e().join(".git").join("hooks").join(file);
|
||||
let path_regexp = search_git_root_path_e().join(".git").join("hooks").join(file);
|
||||
if path_regexp.exists() {
|
||||
print_info(&format!("Found file: {:?}", path_regexp));
|
||||
return fs::read_to_string(path_regexp).unwrap();
|
||||
}
|
||||
|
||||
let home_path_regexp = PathBuf::from(env::var("HOME").unwrap()).join(&(".".to_owned() + file));
|
||||
let home_path_regexp = get_home_e().join(&(".".to_owned() + file));
|
||||
if home_path_regexp.exists() {
|
||||
print_info(&format!("Found file: {:?}", home_path_regexp));
|
||||
return fs::read_to_string(home_path_regexp).unwrap();
|
||||
@@ -135,10 +141,7 @@ fn get_commit_msg_usage() -> String {
|
||||
}
|
||||
|
||||
fn install_commit_msg(force: bool) {
|
||||
let home_path = PathBuf::from(env::var("HOME").unwrap_or_else(|e| {
|
||||
exit_with_error_message(&format!("Get env HOME failed: {}!", e));
|
||||
}));
|
||||
let commit_msg_crs = home_path.join("bin").join("commit-msg.crs");
|
||||
let commit_msg_crs = get_home_e().join("bin").join("commit-msg.crs");
|
||||
let commig_msg_exec_file = if !commit_msg_crs.exists() {
|
||||
print_warn(&format!("File {:?} NOT exists!", commit_msg_crs));
|
||||
PathBuf::from(env::args().next().unwrap())
|
||||
|
||||
Reference in New Issue
Block a user