Skip to content

Commit 2ec4b39

Browse files
committed
fix:status显示所有更改,而非仅当前目录
1 parent 0da02a5 commit 2ec4b39

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mit" # mini_git
3-
version = "0.2.0"
3+
version = "1.0.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/commands/status.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ impl Changes {
3131
}
3232

3333
/// 使用paths过滤,返回相对路径(to cur_dir)
34+
/// <br> 注意,如果paths为空,则返回空
3435
pub fn filter_relative(&self, paths: &Vec<PathBuf>) -> Changes {
35-
self.filter_abs(paths).to_relative()
36+
self.filter_abs(paths).to_relative_from_abs()
3637
}
3738

3839
/// 转换为绝对路径(from workdir相对路径)
@@ -51,7 +52,7 @@ impl Changes {
5152
}
5253

5354
/// 转换为相对路径(to cur_dir)注意:要先转换为绝对路径
54-
fn to_relative(&self) -> Changes {
55+
fn to_relative_from_abs(&self) -> Changes {
5556
let mut change = self.clone();
5657
let cur_dir = util::cur_dir();
5758
[&mut change.new, &mut change.modified, &mut change.deleted]
@@ -61,6 +62,11 @@ impl Changes {
6162
});
6263
change
6364
}
65+
66+
///转换为相对路径(to cur_dir)
67+
pub fn to_relative(&self) -> Changes {
68+
self.to_absolute().to_relative_from_abs()
69+
}
6470
}
6571

6672
/** 比较暂存区与HEAD(最后一次Commit::Tree)的差异
@@ -147,8 +153,8 @@ pub fn status() {
147153
}
148154

149155
// 对当前目录进行过滤 & 转换为相对路径
150-
let staged = changes_to_be_committed().filter_relative(&vec![util::cur_dir()]);
151-
let unstaged = changes_to_be_staged().filter_relative(&vec![util::cur_dir()]);
156+
let staged = changes_to_be_committed().to_relative();
157+
let unstaged = changes_to_be_staged().to_relative();
152158
if staged.is_empty() && unstaged.is_empty() {
153159
println!("nothing to commit, working tree clean");
154160
return;

src/utils/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub fn is_sub_path(path: &Path, parent: &Path) -> bool {
7777
}
7878

7979
/// 判断文件是否在paths中(包括子目录),不检查存在性
80+
/// <br>注意,如果paths为空,则返回false
8081
pub fn include_in_paths<T, U>(path: &Path, paths: U) -> bool
8182
where
8283
T: AsRef<Path>,

0 commit comments

Comments
 (0)