From 68e1f4f61ce579fa1e496a5d789afbcae171a203 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Sep 2016 15:19:47 +0200 Subject: [PATCH] Provide better commit template message, including action and store id --- libimagstorestdhook/src/vcs/git/config.rs | 18 ++++++++++++++---- libimagstorestdhook/src/vcs/git/delete.rs | 2 +- libimagstorestdhook/src/vcs/git/update.rs | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs index 49d4a3c1..c18b8cb1 100644 --- a/libimagstorestdhook/src/vcs/git/config.rs +++ b/libimagstorestdhook/src/vcs/git/config.rs @@ -1,6 +1,7 @@ use toml::Value; use libimagerror::into::IntoError; +use libimagstore::storeid::StoreId; use vcs::git::error::GitHookErrorKind as GHEK; use vcs::git::error::MapErrInto; @@ -70,8 +71,17 @@ fn commit_default_msg<'a>(config: &'a Value, action: &'a StoreAction) -> &'a str /// Get the commit template /// /// TODO: Implement good template string -fn commit_template() -> &'static str { - "Commit template" +fn commit_template(action: &StoreAction, id: &StoreId) -> String { + format!(r#" +# Please commit your changes and remove these lines. +# +# You're about to commit changes via the {action} Hook +# +# Altered file: {id} +# + "#, + action = action, + id = id.local().display()) } /// Generate a commit message @@ -79,7 +89,7 @@ fn commit_template() -> &'static str { /// Uses the functions `commit_interactive()` and `commit_with_editor()` /// or reads one from the commandline or uses the `commit_default_msg()` string to create a commit /// message. -pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction) -> Result { +pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction, id: &StoreId) -> Result { use libimaginteraction::ask::ask_string; use libimagutil::edit::edit_in_tmpfile_with_command; use std::process::Command; @@ -92,7 +102,7 @@ pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction) -> .map_err_into(GHEK::ConfigError) .map(Command::new) .and_then(|cmd| { - let mut s = String::from(commit_template()); + let mut s = commit_template(&action, id); edit_in_tmpfile_with_command(cmd, &mut s).map(|_| s) .map_err_into(GHEK::EditorError) }) diff --git a/libimagstorestdhook/src/vcs/git/delete.rs b/libimagstorestdhook/src/vcs/git/delete.rs index 8b1c791b..51528067 100644 --- a/libimagstorestdhook/src/vcs/git/delete.rs +++ b/libimagstorestdhook/src/vcs/git/delete.rs @@ -168,7 +168,7 @@ impl StoreIdAccessor for DeleteHook { .map_into_hook_error() ); - let message = try!(commit_message(&repo, cfg, action) + let message = try!(commit_message(&repo, cfg, action, &id) .map_dbg_err_str("Failed to get commit message") .map_dbg_str("[GIT DELETE HOOK]: Got commit message")); diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index a85a61a1..9576d6ec 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -188,7 +188,7 @@ impl StoreIdAccessor for UpdateHook { .map_into_hook_error() ); - let message = try!(commit_message(&repo, cfg, StoreAction::Update) + let message = try!(commit_message(&repo, cfg, StoreAction::Update, &id) .map_dbg_err_str("Failed to get commit message") .map_dbg_str("[GIT UPDATE HOOK]: Fetched commit message"));