mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-05-02 14:50:52 +08:00
删除Index析构自动保存,时机不可控,改为手动+main结束自动save
This commit is contained in:
@@ -31,12 +31,14 @@ pub fn add(raw_paths: Vec<String>, all: bool, mut update: bool) {
|
||||
println!("{}", "--update 只对已跟踪文件进行操作 不包含new".bright_green());
|
||||
}
|
||||
|
||||
let index = Index::get_instance();
|
||||
for file in &files {
|
||||
add_a_file(file);
|
||||
add_a_file(file, index);
|
||||
}
|
||||
index.save();
|
||||
}
|
||||
|
||||
fn add_a_file(file: &Path) {
|
||||
fn add_a_file(file: &Path, index: &mut Index) {
|
||||
let workdir = util::get_working_dir().unwrap();
|
||||
if !util::is_sub_path(file, &workdir) {
|
||||
//文件不在工作区内
|
||||
@@ -49,7 +51,6 @@ fn add_a_file(file: &Path) {
|
||||
return;
|
||||
}
|
||||
|
||||
let index = Index::get_instance();
|
||||
let rel_path = util::to_cur_relative_path(file);
|
||||
if !file.exists() {
|
||||
//文件被删除
|
||||
|
||||
@@ -31,6 +31,7 @@ pub fn commit(message: String, allow_empty: bool) {
|
||||
}
|
||||
|
||||
println!("commit hash: {:?}", commit_hash);
|
||||
index.save();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -38,5 +38,6 @@ pub fn remove(files: Vec<String>, cached: bool, recursive: bool) -> io::Result<(
|
||||
}
|
||||
println!("removed [{}]", file.bright_green());
|
||||
}
|
||||
index.save();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ pub fn restore_index(filter: Option<&Vec<PathBuf>>, target_blobs: &Vec<(PathBuf,
|
||||
}
|
||||
}
|
||||
}
|
||||
index.save();
|
||||
}
|
||||
/**
|
||||
对于工作区中的新文件,若已跟踪,则删除;若未跟踪,则保留<br>
|
||||
@@ -224,8 +225,7 @@ mod test {
|
||||
util::ensure_no_file(&path);
|
||||
cmd::add(vec![], true, false); //add -A
|
||||
cmd::restore(vec![".".to_string()], Some("HEAD".to_string()), false, true);
|
||||
let index = Index::get_instance();
|
||||
assert!(index.get_tracked_files().is_empty());
|
||||
assert!(Index::get_instance().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user