将Index改为单例模式,防止状态不一致; 注意:测试为单进程,需要reset防止共享单例

This commit is contained in:
mrbeanc
2023-12-27 16:19:02 +08:00
parent 228e1d681e
commit b568e87925
10 changed files with 67 additions and 37 deletions

View File

@@ -70,7 +70,7 @@ impl Changes {
*/
pub fn changes_to_be_committed() -> Changes {
let mut change = Changes::default();
let index = Index::new();
let index = Index::get_instance();
let head_hash = head::current_head_commit();
let tracked_files = index
.get_tracked_files()
@@ -111,7 +111,7 @@ pub fn changes_to_be_committed() -> Changes {
/// 比较工作区与暂存区的差异,返回相对路径(to workdir),不筛选
pub fn changes_to_be_staged() -> Changes {
let mut change = Changes::default();
let index = Index::new();
let index = Index::get_instance();
for file in index.get_tracked_files() {
if !file.exists() {
change.deleted.push(util::to_workdir_relative_path(&file));