mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-05-05 20:53:09 +08:00
fix:status显示所有更改,而非仅当前目录
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mit" # mini_git
|
||||
version = "0.2.0"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -31,8 +31,9 @@ impl Changes {
|
||||
}
|
||||
|
||||
/// 使用paths过滤,返回相对路径(to cur_dir)
|
||||
/// <br> 注意,如果paths为空,则返回空
|
||||
pub fn filter_relative(&self, paths: &Vec<PathBuf>) -> Changes {
|
||||
self.filter_abs(paths).to_relative()
|
||||
self.filter_abs(paths).to_relative_from_abs()
|
||||
}
|
||||
|
||||
/// 转换为绝对路径(from workdir相对路径)
|
||||
@@ -51,7 +52,7 @@ impl Changes {
|
||||
}
|
||||
|
||||
/// 转换为相对路径(to cur_dir)注意:要先转换为绝对路径
|
||||
fn to_relative(&self) -> Changes {
|
||||
fn to_relative_from_abs(&self) -> Changes {
|
||||
let mut change = self.clone();
|
||||
let cur_dir = util::cur_dir();
|
||||
[&mut change.new, &mut change.modified, &mut change.deleted]
|
||||
@@ -61,6 +62,11 @@ impl Changes {
|
||||
});
|
||||
change
|
||||
}
|
||||
|
||||
///转换为相对路径(to cur_dir)
|
||||
pub fn to_relative(&self) -> Changes {
|
||||
self.to_absolute().to_relative_from_abs()
|
||||
}
|
||||
}
|
||||
|
||||
/** 比较暂存区与HEAD(最后一次Commit::Tree)的差异
|
||||
@@ -147,8 +153,8 @@ pub fn status() {
|
||||
}
|
||||
|
||||
// 对当前目录进行过滤 & 转换为相对路径
|
||||
let staged = changes_to_be_committed().filter_relative(&vec![util::cur_dir()]);
|
||||
let unstaged = changes_to_be_staged().filter_relative(&vec![util::cur_dir()]);
|
||||
let staged = changes_to_be_committed().to_relative();
|
||||
let unstaged = changes_to_be_staged().to_relative();
|
||||
if staged.is_empty() && unstaged.is_empty() {
|
||||
println!("nothing to commit, working tree clean");
|
||||
return;
|
||||
|
||||
@@ -77,6 +77,7 @@ pub fn is_sub_path(path: &Path, parent: &Path) -> bool {
|
||||
}
|
||||
|
||||
/// 判断文件是否在paths中(包括子目录),不检查存在性
|
||||
/// <br>注意,如果paths为空,则返回false
|
||||
pub fn include_in_paths<T, U>(path: &Path, paths: U) -> bool
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
|
||||
Reference in New Issue
Block a user