优化commit显示

This commit is contained in:
HouXiaoxuan
2023-12-21 18:45:15 +08:00
parent c812957a80
commit 72b6f65c83

View File

@@ -3,7 +3,8 @@ use crate::models::{commit, index};
use super::status;
fn no_change() -> bool { //todo: move to status.rs
fn no_change() -> bool {
//todo: move to status.rs
let change = status::changes_to_be_committed();
change.new.len() == 0 && change.modified.len() == 0 && change.deleted.len() == 0
}
@@ -21,16 +22,18 @@ pub fn commit(message: String, allow_empty: bool) {
let commit_hash = commit.save();
head::update_head_commit(&commit_hash);
{
let commit_target = {
match current_head {
head::Head::Branch(branch_name) => branch_name,
head::Head::Detached(commit_hash) => commit_hash[..6].to_string(),
}
};
println!("commit to [{:?}] message{:?}", commit_target, message);
println!("commit hash: {:?}", commit_hash);
match current_head {
head::Head::Branch(branch_name) => {
println!("commit to [{:?}] message{:?}", branch_name, message)
}
head::Head::Detached(commit_hash) => println!(
"Detached HEAD commit {:?} message{:?}",
commit_hash[0..7].to_string(),
message
),
}
println!("commit hash: {:?}", commit_hash);
}
#[cfg(test)]