@@ -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 ;
0 commit comments