From cb2a8eb9d0c104cb551c79ec4b3c054dc89fd727 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Wed, 20 Dec 2023 02:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E6=B5=8B=E8=AF=95=E7=9A=84commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/commit.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/commands/commit.rs diff --git a/src/commands/commit.rs b/src/commands/commit.rs new file mode 100644 index 0000000..106a71c --- /dev/null +++ b/src/commands/commit.rs @@ -0,0 +1,16 @@ +use crate::head; +use crate::models::{commit, index}; +// XXX NOT TESTED +pub fn commit(message: String, allow_enpty: bool) { + let index = index::Index::new(); + // XXX true 需要替换为 index.is_empty() + if true && !allow_enpty { + println!("工作区没有任何改动,不需要提交"); + } + + let current_commit_hash = head::current_head_commit(); + + let mut commit = commit::Commit::new(&index, vec![current_commit_hash], message); + let commit_hash = commit.save(); + head::update_head_commit(&commit_hash); +}