mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-05-03 15:55:08 +08:00
完整实现commit
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
use crate::head;
|
use crate::head;
|
||||||
use crate::models::{commit, index};
|
use crate::models::{commit, index};
|
||||||
|
|
||||||
|
use super::status;
|
||||||
|
|
||||||
|
fn no_change() -> bool {
|
||||||
|
let change = status::changes_to_be_committed();
|
||||||
|
change.new.len() == 0 && change.modified.len() == 0 && change.deleted.len() == 0
|
||||||
|
}
|
||||||
pub fn commit(message: String, allow_enpty: bool) {
|
pub fn commit(message: String, allow_enpty: bool) {
|
||||||
let index = index::Index::new();
|
let index = index::Index::new();
|
||||||
// XXX true 需要替换为 status::changes_to_be_committed()
|
if no_change() && !allow_enpty {
|
||||||
if false && !allow_enpty {
|
panic!("工作区没有任何改动,不需要提交");
|
||||||
println!("工作区没有任何改动,不需要提交");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_head = head::current_head();
|
let current_head = head::current_head();
|
||||||
@@ -27,3 +32,16 @@ pub fn commit(message: String, allow_enpty: bool) {
|
|||||||
println!("commit hash: {:?}", commit_hash);
|
println!("commit hash: {:?}", commit_hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::utils::util;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_commit_empty() {
|
||||||
|
util::setup_test_with_clean_mit();
|
||||||
|
|
||||||
|
super::commit("".to_string(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user