feat(reset): introduce reset and fix ROOT_PATH
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
use std::path::{Path, PathBuf, Component};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use crate::store::structs;
|
||||
|
||||
pub fn to_repo_relative(path: &PathBuf, root: &PathBuf) -> PathBuf {
|
||||
path.strip_prefix(root).unwrap().to_path_buf()
|
||||
pub fn to_repo_relative(path: &PathBuf) -> PathBuf {
|
||||
let root = structs::get_repo_root();
|
||||
path.strip_prefix(&root)
|
||||
.expect(&format!(
|
||||
"Expect '{}' to be in the repo '{}'",
|
||||
path.display(),
|
||||
root.display()
|
||||
))
|
||||
.to_path_buf()
|
||||
}
|
||||
|
||||
pub fn to_string(path: &PathBuf) -> String {
|
||||
@@ -18,9 +26,7 @@ pub fn to_string(path: &PathBuf) -> String {
|
||||
/// This function ensures a given path ending with '/' still
|
||||
/// ends with '/' after normalization.
|
||||
pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
let ends_with_slash = path.as_ref()
|
||||
.to_str()
|
||||
.map_or(false, |s| s.ends_with('/'));
|
||||
let ends_with_slash = path.as_ref().to_str().map_or(false, |s| s.ends_with('/'));
|
||||
let mut normalized = PathBuf::new();
|
||||
for component in path.as_ref().components() {
|
||||
match &component {
|
||||
|
||||
15
src/utils/tests.rs
Normal file
15
src/utils/tests.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use std::env;
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn is_running() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub fn is_running() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn is_var_setup() -> bool {
|
||||
env::var("RUNNING_TESTS").is_ok()
|
||||
}
|
||||
Reference in New Issue
Block a user