MCPcopy Create free account
hub / github.com/MrBeanCpp/MIT / commit

Function commit

src/commands/commit.rs:5–35  ·  view source on GitHub ↗
(message: String, allow_empty: bool)

Source from the content-addressed store, hash-verified

3use super::status;
4
5pub fn commit(message: String, allow_empty: bool) {
6 let index = Index::get_instance();
7 if !allow_empty && status::changes_to_be_committed().is_empty() {
8 panic!("工作区没有任何改动,不需要提交");
9 }
10
11 let current_head = head::current_head();
12 let current_commit_hash = head::current_head_commit();
13
14 let mut commit = {
15 if current_commit_hash.is_empty() {
16 Commit::new(index, vec![], message.clone())
17 } else {
18 Commit::new(index, vec![current_commit_hash.clone()], message.clone())
19 }
20 };
21 let commit_hash = commit.save();
22 head::update_head_commit(&commit_hash);
23
24 match current_head {
25 head::Head::Branch(branch_name) => {
26 println!("commit to [{:?}] message{:?}", branch_name, message)
27 }
28 head::Head::Detached(commit_hash) => {
29 println!("Detached HEAD commit {:?} message{:?}", commit_hash[0..7].to_string(), message)
30 }
31 }
32
33 println!("commit hash: {:?}", commit_hash);
34 index.save();
35}
36
37#[cfg(test)]
38mod test {

Callers 9

handle_commandFunction · 0.85
test_create_branchFunction · 0.85
test_delete_branchFunction · 0.85
test_switchFunction · 0.85
test_logFunction · 0.85
test_check_ffFunction · 0.85
test_commit_emptyFunction · 0.85
test_commitFunction · 0.85

Calls 6

changes_to_be_committedFunction · 0.85
current_headFunction · 0.85
current_head_commitFunction · 0.85
update_head_commitFunction · 0.85
is_emptyMethod · 0.45
saveMethod · 0.45

Tested by 8

test_create_branchFunction · 0.68
test_delete_branchFunction · 0.68
test_switchFunction · 0.68
test_logFunction · 0.68
test_check_ffFunction · 0.68
test_commit_emptyFunction · 0.68
test_commitFunction · 0.68