summaryrefslogtreecommitdiffstats
path: root/libimagstorestdhook
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-09-08 17:09:24 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-09-09 16:34:19 +0200
commit47c3d0e483c94030ddd60c05986e3453bd7b9ce6 (patch)
tree43e601bfbb9b165784669b84fe9bb4839ab543bf /libimagstorestdhook
parent17805a0f1ed63fad8e8d53a58a11986aace624e1 (diff)
Implement commit_message()
Diffstat (limited to 'libimagstorestdhook')
-rw-r--r--libimagstorestdhook/src/vcs/git/config.rs68
1 files changed, 63 insertions, 5 deletions
diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs
index a7e262d6..84362563 100644
--- a/libimagstorestdhook/src/vcs/git/config.rs
+++ b/libimagstorestdhook/src/vcs/git/config.rs
@@ -9,15 +9,73 @@ use vcs::git::result::Result;
use vcs::git::action::StoreAction;
pub fn commit_interactive(config: &Value) -> bool {
- warn!("Interactive committing not yet supported, using dummy commit message");
- false
+ match config.lookup("commit.interactive") {
+ Some(&Value::Boolean(b)) => b,
+ Some(_) => {
+ warn!("Configuration error, 'store.hooks.stdhook_git_update.commit.interactive' must be a Boolean.");
+ warn!("Defaulting to commit.interactive = false");
+ false
+ }
+ None => {
+ warn!("Unavailable configuration for");
+ warn!("\t'store.hooks.stdhook_git_update.commit.interactive'");
+ warn!("Defaulting to false");
+ false
+ }
+ }
}
-pub fn commit_message(config: &Value, action: StoreAction) -> Result<String> {
+fn commit_with_editor(config: &Value) -> bool {
+ match config.lookup("commit.interactive_editor") {
+ Some(&Value::Boolean(b)) => b,
+ Some(_) => {
+ warn!("Configuration error, 'store.hooks.stdhook_git_update.commit.interactive_editor' must be a Boolean.");
+ warn!("Defaulting to commit.interactive_editor = false");
+ false
+ }
+ None => {
+ warn!("Unavailable configuration for");
+ warn!("\t'store.hooks.stdhook_git_update.commit.interactive_editor'");
+ warn!("Defaulting to false");
+ false
+ }
+ }
+}
+
+fn commit_default_msg<'a>(config: &'a Value) -> &'a str {
+ match config.lookup("commit.message") {
+ Some(&Value::String(ref b)) => b,
+ Some(_) => {
+ warn!("Configuration error, 'store.hooks.stdhook_git_update.commit.message' must be a String.");
+ warn!("Defaulting to commit.message = 'Update'");
+ "Update"
+ }
+ None => {
+ warn!("Unavailable configuration for");
+ warn!("\t'store.hooks.stdhook_git_update.commit.message'");
+ warn!("Defaulting to commit.message = 'Update'");
+ "Update"
+ }
+ }
+}
+
+fn commit_template() -> &'static str {
+ "Commit template"
+}
+
+pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction) -> Result<String> {
+ use libimaginteraction::ask::ask_string;
+ use libimagutil::edit::edit_in_tmpfile_with_command;
+ use std::process::Command;
+
if commit_interactive(config) {
- unimplemented!()
+ if commit_with_editor(config) {
+ unimplemented!()
+ } else {
+ unimplemented!()
+ }
} else {
- Ok(String::from("Dummy commit"))
+ Ok(String::from(commit_default_msg(config)))
}
}